Home > Back-end >  How to make the original window hide or close
How to make the original window hide or close

Time:04-13

Package com;
The import javax.mail. Swing. *;
Import the Java. The awt. *;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;
import java.util.Random;
Public class YanZhengMa {
Public static void main (String [] args) {
The new Windows ();
}
}
The class Windows extends JFrame {
Windows () {
Pan1 p1=new pan1 ();
This. The add (p1);
Enclosing setBounds (500500250200);
Enclosing setVisible (true);
Enclosing setDefaultCloseOperation (JFrame. DISPOSE_ON_CLOSE);
}
}
The class pan1 extends JPanel implements ActionListener {
JButton jb1, jb2;
JLabel jumpers jl1, jl2 jl3;
JTextField jt1;
The Random r=new Random ();
Int a=r.n extInt (10);
Int b=r.n extInt (10);
Int c=r.n extInt (10);
Int d=r.n extInt (10);
String aa=a + ""
String bb=b + ";"
String cc=c + ""
String dd=d + ";"
String f=aa + bb + cc + dd.
Pan1 () {
SetLayout (null);
Jb1=new JButton ();
Jb2=new JButton ();
Jumpers jl1=new JLabel ();
Jl2=new JLabel ();
Jl3=new JLabel ();
Jt1=new JTextField ();
Jb1. SetText (" ok ");
Jb2. SetText (" cancel ");
Jumpers jl1. SetText (" please enter the verification code: ");
Jl2. SetText (f);
Jl3. SetText (" verification code: ");
Jl3. SetBounds (10,10,100,30);
Jl3. SetFont (new Font (" ", the Font BOLD, 20));
Jl2. SetBounds (100,0,120,50);
Jl2. SetFont (new Font (" ", the Font HANGING_BASELINE, 50));
Jumpers jl1. SetBounds (10,70,100,30);
Jb1. SetBounds (20120,70,30);
Jb2. SetBounds (130120,70,30);
Jt1. SetBounds (110,70,100,30);
Jb1. AddActionListener (this);
Jb2. AddActionListener (this);
This. The add (jb1);
This. The add (jb2);
This. The add (jt1);
This. The add (jumpers jl1);
This. The add (jl3);
This. The add (jl2);
}
@ Override
Public void actionPerformed (an ActionEvent e) {
String s=um participant etActionCommand ();
The switch (s) {
Case "sure" :
Way1 ();
break;
Case "cancel" :
Way2 ();
break;
}
}
Void way1 () {
String g=jt1. GetText ();
If (g.e quals (f)) {
Way3 ();
} else {
JOptionPane. ShowMessageDialog (null, "this is not the correct verification code,"
"Error", JOptionPane. ERROR_MESSAGE);
}
}
Void way2 () {
System.exit(0);
}
Void way3 () {
}
}
  • Related