-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gui12.java
59 lines (55 loc) · 1.51 KB
/
Gui12.java
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
51
52
53
54
55
56
57
58
59
//GUI.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUI extends WindowAdapter{
JFrame jf;
public GUI(){
jf=new JFrame("Window 1");
jp.setLayout(new GridBagLayout());
JPanel jp=new JPanel();
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
jp.add(new JButton("B1"),gbc);
gbc.gridx=1;
gbc.gridy=0;
jp.add(new JButton("B2"),gbc);
gbc.gridx=0;
gbc.ipady=20;
gbc.gridy=1;
jp.add(new JButton("B3"),gbc);
gbc.gridx=1;
gbc.gridy=1;
jp.add(new JButton("B4"),gbc);
gbc.gridx=0;
gbc.gridy=2;
gbc.gridwidth=2;
gbc.fill=GridBagConstraints.VERTICAL;
jp.add(new JButton("B5"),gbc);
jf.add(jp);
jf.addWindowListener(this);
// jf.setSize(600,600);
jf.pack();
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();
}
}