Repository navigation
Expand file tree
/
Copy pathXYLayout.java
More file actions
84 lines (70 loc) · 2.42 KB
/
Copy pathXYLayout.java
File metadata and controls
84 lines (70 loc) · 2.42 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
/**
* Created by IntelliJ IDEA.
* User: plamen
* Date: 28-Jun-2010
* Time: 16:07:51
* To change this template use File | Settings | File Templates.
*/
public class XYLayout extends JFrame implements ActionListener {
public static void main(String[] args) {
new XYLayout();
}
public XYLayout() {
addWindowListener(new WindowAdapter() {
void windowClosing() {
System.exit(0);
}
});
buildFrame();
setLocation(250, 150);
setVisible(true);
}
private void buildFrame() {
JButton button;
Dimension size;
Container pane = getContentPane();
pane.setLayout(null);
Insets insets = pane.getInsets();
button = new JButton("first");
size = button.getPreferredSize();
button.setBounds(25 + insets.left, 15 + insets.top, size.width, size.height);
button.addActionListener(this);
pane.add(button);
button = new JButton("second");
size = button.getPreferredSize();
button.setBounds(55 + insets.left, 120 + insets.top, size.width, size.height);
pane.add(button);
button = new JButton("Exit");
size = button.getPreferredSize();
button.setBounds(150 + insets.left, 45 + insets.top, size.width + 50, size.height + 20);
button.addActionListener(this);
pane.add(button);
int width = 300 + insets.left + insets.right;
int height = 220 + insets.top + insets.bottom;
setSize(width, height);
}
@Override
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (s.equals("Exit")) {
System.exit(0);
} else if (s.equals("first")) {
String[] possibleFlavor = {"Vanilla", "Chocolate", "Rocky Road"};
String favorite = (String) JOptionPane.showInputDialog(this, "Chose your favorite",
"Ice Cream Flavor",
JOptionPane.QUESTION_MESSAGE,
null,
possibleFlavor,
possibleFlavor[0]);
if (favorite == null)
System.out.println("No choice made");
else
System.out.println("Favorite: " + favorite);
}
}
}