-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui7.java
More file actions
50 lines (46 loc) · 1.22 KB
/
Gui7.java
File metadata and controls
50 lines (46 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//GUI.java
import javax.swing.*;
import java.awt.event.*;
public class GUI extends WindowAdapter{
JFrame jf;
JCheckBox jcb1;
// JComboBox jcb2;
ButtonGroup bg;
GUI(){
jf=new JFrame("My Frame");
jcb1 =new JCheckBox("Hello!",false);
//jcb2 =new JRadioButton("Female");
jcb1.setBounds(75,50,100,30);
//jrb2.setBounds(75,100,100,30);
bg=new ButtonGroup();
bg.add(jcb1);
//bg.add(jrb2);
jf.add(jcb1);
//jf.add(jrb2);
// jcb1=new JCheckBox();
// jcb2=new JComboBox();
jf.addWindowListener(this);
jf.setSize(300,300);
jf.setLayout(null);
jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
jf.setVisible(true);
}
public void windowClosing(WindowEvent we){
int a=JOptionPane.showConfirmDialog(jf,"Are u Sure?");
if(a==JOptionPane.YES_OPTION){
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
else if(a==JOptionPane.NO_OPTION){
jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
else if(a==JOptionPane.CANCEL_OPTION){
jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
}
//Main.java
public class Main {
public static void main(String[] args) {
new GUI();
}
}