In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.