Elementary school student Arithmetic in Java

Source: Internet
Author: User

Importjava.awt.*;Importjava.awt.event.*;Importjava.io.FileNotFoundException;Importjava.io.IOException;Importjavax.swing.*; Public classLoginextendsJFrame {PrivateTextField F1; PrivateTextField F2; PrivateJButton B1; PrivateJButton B2; PrivateJButton B3; Yunsuan SCS=NewYunsuan (); //Login Interface     PublicLogin () {Container CP=getcontentpane ();//ContainerCp.setlayout (NewGridLayout (3,1));//three row one column layoutLabel l1=NewLabel ("User name"); Label L2=NewLabel ("Password"); Panel P1=NewPanel (); Panel P2=NewPanel (); Panel P3=NewPanel (); F1=NewTextField (10); F2=NewTextField (10); F2.setechochar (‘*‘);//Echo character is *b1=NewJButton ("Login"); B2=NewJButton ("Reset"); B3=NewJButton ("Exit"); P1.add (L1);//The first line adds a label 1P1.add (F1);        P2.add (L2);        P2.add (F2);        P3.add (B1);        P3.add (B2);        P3.add (B3);        Cp.add (p1);        Cp.add (p2);        Cp.add (p3); B1.addactionlistener (NewEnter ()); B2.addactionlistener (NewReWrite ()); B3.addactionlistener (NewClose ()); }    classEnterImplementsactionlistener{ Public voidactionperformed (ActionEvent e) {if((F1.gettext ()). Equals ("Czp") && (F2.gettext ()). Equals ("123456") {Yunsuan frame1=NewYunsuan (); Frame1.setbounds (200, 200, 300, 300); Frame1.setvisible (true); }                 ElseJoptionpane.showmessagedialog (NULL, "The user name or password is wrong, please login again!" "); }    }    classReWriteImplementsactionlistener{ Public voidactionperformed (ActionEvent e) {F1.settext (""); F2.settext ("");        F1.requestfocus (); }    }    classCloseImplementsactionlistener{ Public voidactionperformed (ActionEvent e) {JButton BT=(JButton) E.getsource (); if(bt==B3) {System.exit (0); }        }}//Main Function Program start     Public Static voidMain (string[] args) {Login log=NewLogin (); Log.settitle ("System Login"); Log.setbounds (200, 200, 300, 300);        Log.setbackground (Color.Blue); Log.setvisible (true); NewYunsuan (); }}ImportJava.awt.Color;ImportJava.awt.Container;Importjava.awt.GridLayout;ImportJava.awt.Label;ImportJava.awt.Panel;ImportJava.awt.TextField;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException;ImportJava.io.ObjectInputStream;Importjava.util.ArrayList;ImportJavax.swing.JButton;ImportJavax.swing.JComboBox;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JOptionPane;ImportJavax.swing.JPanel;ImportJavax.swing.JTextField; Public classYunsuanextendsJFrame {PrivateJTextField TextNum1; PrivateJTextField textNum2; PrivateJTextField result; PrivateJTextField RESULT1; PrivateJComboBox opers;  PublicYunsuan () {init (); SetSize (300,100); Setlocationrelativeto (NULL); Settitle ("Elementary School Math"); Setdefaultcloseoperation (3); SetVisible (false); }         Private voidinit () {string[] operators= "+,-, *,/". Split (","); TextNum1=NewJTextField (); Textnum1.setcolumns (10); TextNum2=NewJTextField (); Textnum2.setcolumns (10); Result=NewJTextField (); Result.setcolumns (10); RESULT1=NewJTextField (); Result1.setcolumns (10); Opers=NewJComboBox (operators); Opers.addactionlistener (NewActionListener () {@Override Public voidactionperformed (ActionEvent e) {intoperator =Opers.getselectedindex (); DoubleNUM1 =double.parsedouble (Textnum1.gettext ()); Doublenum2 =double.parsedouble (Textnum2.gettext ()); Switch(operator) { Case0:result1.settext (NUM1 + num2+ ""); Break;  Case1:result1.settext (num1-num2+ ""); Break;  Case2:result1.settext (NUM1 * num2+ ""); Break;  Case3:result1.settext (num1/num2+ ""); Break;                          }                             }                   }); JPanel P=NewJPanel ();        P.add (TEXTNUM1);        P.add (TEXTNUM2);        P.add (opers);        P.add (result);        P.add (RESULT1);  This. Add (P); }}

Elementary school student Arithmetic in Java

Related Article

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.