Java Swing Simple Adder

Source: Internet
Author: User
Tags gettext

1  Packagetest;2 Importjava.awt.*;3 Importjavax.swing.*;4 Importjava.awt.event.*;5  Public classFrameDemo26 {7 StaticJTextField field1=NewJTextField (5);8 StaticJTextField field2=NewJTextField (5);9 StaticJTextField field3=NewJTextField ("0", 5);Ten  One  PublicFrameDemo2 () { AJFrame f=NewJFrame ("Adder"); - f.setdefaultcloseoperation (jframe.exit_on_close); -F.setsize (220,100); theF.setlocation (500,300); -JLabel jb=NewJLabel ("+"); -F.setvisible (true); -JPanel p1=NewJPanel (); + F.setcontentpane (p1); -P1.setlayout (NewFlowLayout ()); +  A P1.add (field1); at P1.add (JB); - P1.add (field2); - P1.add (field3); -JButton b1=NewJButton ("Calculation"); -Color bg=NewColor (255,255,255); - b1.setbackground (BG); in P1.add (B1); -  toB1.addactionlistener (NewActionListener () +     { -      Public voidactionperformed (ActionEvent e)//overriding the Actionperformed method the     { *     intb; $A=integer.parseint (Field1.gettext ());//get the data in TextField1Panax Notoginsengb=Integer.parseint (Field2.gettext ()); -Field3.settext (string.valueof (A +b)); the     } +     } A     ); the } +  Public Static voidMain (String args[]) - { $FrameDemo2 fd=NewFrameDemo2 (); $ } -}

Operation Result:

Beginner Java Swing, has always felt that swing is useless, so there is no contact, these days Java practice, the teacher asked to write a project with Java Swing, after contact feel Swing is very good, more easy to understand than MFC.

Java Swing Simple Adder

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.