-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.app2
58 lines (46 loc) · 1.85 KB
/
.app2
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
package frameApp;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main {
public static void main(String [] args){
SimpleGUI app = new SimpleGUI();
app.setVisible(true);
}
}
public class SimpleGUI extends JFrame {
private JButton button = new JButton("Press");
private JTextField input = new JTextField("", 5);
private JLabel label = new JLabel("Input: ");
private JRadioButton radio1 = new JRadioButton("Select this");
private JRadioButton radio2 = new JRadioButton("Select that");
private JCheckBox check = new JCheckBox("Check", false);
public SimpleGUI (){
super("Simple Instance");
this.setBounds(200,200,300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container container = this.getContentPane();
container.setLayout(new GridLayout(3,2,2,2));
container.add(label);
container.add(input);
ButtonGroup group = new ButtonGroup();
group.add(radio1);
group.add(radio2);
container.add(radio1);
radio1.setSelected(true);
container.add(radio2);
container.add(check);
button.addActionListener(new ButtonEventListener ());
container.add(button);
}
class ButtonEventListener implements ActionListener {
public void actionPerformed (ActionEvent e){
String message = "";
message += "Button was pressed \n";
message += "Text is " + input.getText() + "\n";
message += (radio1.isSelected() ? "Radio #1" : "Radio #2") + "is selected \n";
message += "CheckBox is " + ((check.isSelected()) ? "checked" : "unchecked");
JOptionPane.showMessageDialog(null, message, "Output", JOptionPane.PLAIN_MESSAGE);
}
}
}