Home > Back-end >  Just learning Java swing, code compilation is no problem, but can't run, have bosses can help h
Just learning Java swing, code compilation is no problem, but can't run, have bosses can help h

Time:09-24

Package homework;
The import javax.mail. Swing. *;
Import the Java. The awt. *;
Import the Java. The awt. Event. MouseEvent;
Import the Java. The awt. Event. MouseListener;
Public class homework {
Public static void main (String [] args) {
CAL cal1=new CAL ();
}
}
The class CAL extends JFrame {
MousePolice police;
JButton jia;
JButton cha.
JButton chu;
JButton ji;
JTextField text1.
JTextField text2.
JTextField answer;
Public CAL () {
The init ();
SetVisible (true);
SetDefaultCloseOperation (JFrame. DISPOSE_ON_CLOSE);
}
Void init () {
JFrame window1=new JFrame ();
The Container con=window1. GetContentPane ();
Con. SetBackground (Color. Blue);
Window1. SetBounds (150150100, 0100);
Window1. SetLayout (null);
JPanel jp=new JPanel ();
Window1. Add (jp);
Police=new MousePolice ();
Police. SetView (this);
Jia=new JButton (" add ");
Jia. SetBounds (150150100100);
Cha=new JButton (" bad ");
Cha. SetBounds (500150100100);
Chu=new JButton (" addition ");
Jia. SetBounds (650,50,100,100);
Ji=new JButton (" product ");
Ji. SetBounds (150500100100);
Text1=new JTextField (10);
Text1. SetBounds (850650,10,10);
Text2=new JTextField (10);
Text1. SetBounds (950650,10,10);
Answer=new JTextField (10);
Text1. SetBounds (850950,10,10);
Window1. Add (jia);
Window1. Add (cha);
Window1. Add (chu);
Window1. Add (ji);
Window1. Add (text1);
Window1. Add (text2);
Window1. Add (answer);
Jia. AddMouseListener (police);
Cha. AddMouseListener (police);
Chu. AddMouseListener (police);
Ji. AddMouseListener (police);
AddMouseListener (police);
}
}
The class MousePolice implements MouseListener {
CAL view;

Public void setView (CAL view) {
Enclosing the view=view;
}

Public void mousePressed (MouseEvent e) {
Double the result=1;
String value1=view. Text1. GetText ();
String=value2 view. Text2. GetText ();
Double number1=double. ParseDouble (value1);
Double number2=double. ParseDouble (value2);
If (um participant etSource ()==the jia & amp; & Um participant etButton ()==MouseEvent. For the) {
Result=number1 + number2;
} else if (um participant etSource ()==the cha & amp; & Um participant etButton ()==MouseEvent. For the) {
Result=number1 - number2;
} else if (um participant etSource ()==the chu & amp; & Um participant etButton ()==MouseEvent. For the) {
Result=number1/number2;
} else if (um participant etSource ()==the ji & amp; & Um participant etButton ()==MouseEvent. For the) {
Result=number1 * number2;
}
View. The answer. The setText (String. The valueOf (result);
}
Public void mouseReleased (MouseEvent e) {
}

Public void mouseEntered (MouseEvent e) {
}

Public void mouseExited (MouseEvent e) {
}

Public void mouseClicked (MouseEvent e) {
}
}

CodePudding user response:


Please first learn to code,

CodePudding user response:

Don't run is a performance?

CodePudding user response:

The
refer to the original poster is there any name can be up response:


You compile the program is no problem, but there is a big problem, is that you have set up two jframe, inherited the jframe class itself, you initialize a jframe,
Visualization is the jframe class itself, but you put all the containers in your initialization window1, change!
  • Related