In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use Java graphical interface programming to achieve a simple calculator", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Java graphical interface programming to achieve a simple calculator" this article.
1. Simple calculator
Using AWT programming, the FrameNORTH area places the TextField component, and the Panel designated as a four-row and five-column GridLayout layout manager is placed in the middle area of the Frame with fill operators and Operand buttons.
The button triggers the event source and adds ActionListener registration listeners to the button. Custom NumListener (Operand listener class), OperatListener (operator listener class), EqualListener (= "=" listener class) and anonymous internal classes (such as b [11]'- 'listener class) listen to and respond to button events.
Note: integer, floating-point, negative, and continuous operations are fine.
Interface effect:
Simply calculate-12 + 3 =-9
Code:
Import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import static java.awt.Color.blue;public class Calculation {/ / Operand double XJI y; String op; boolean flag; Frame frame = new Frame ("Tomoko's calculator!") ; TextField tf = new TextField (30); Button [] b = new Button [20]; public void init () {/ / Northern region to place text boxes frame.add (tf,BorderLayout.NORTH); Panel panel = new Panel (); panel.setLayout (new GridLayout); / / set button String s = "+-* /%"; for (int item0
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.