-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_alert_optionpane.java
More file actions
72 lines (57 loc) · 2.31 KB
/
05_alert_optionpane.java
File metadata and controls
72 lines (57 loc) · 2.31 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
import javax.swing.*;
import java.awt.event.*;
public class GUIApp {
public static void main(String[] args) {
JFrame frame = new JFrame("Cupertinii Swing GUI");
frame.setSize(400,500);
frame.setLayout(null);
JButton btn_1 = new JButton("Button - Simple Message");
btn_1.setBounds(10, 50, 380, 50);
// Show Message Dialog
btn_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// This will create a alert dialog box
JOptionPane.showMessageDialog(
frame, // Parent
"Button Clicked!", // Message String
"Title of this dialog", // Dialog Title (Optional)
JOptionPane.WARNING_MESSAGE); // Message Type (Optional)
}
});
JButton btn_2 = new JButton("Button - Show Confirmation with Yes/No");
btn_2.setBounds(10, 100, 380, 50);
// Show Yes/No Message Box
btn_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// This will create a alert dialog box with Yes/No buttons
int response = JOptionPane.showConfirmDialog(
frame, // Parent
"Button Clicked!", // Message String
"Do you agree?", // Dialog Title (Optional)
JOptionPane.YES_NO_OPTION); // Message Type (Optional)
if(response == JOptionPane.NO_OPTION) {
System.out.println("Clicked => No");
}
else if(response == JOptionPane.YES_OPTION) {
System.out.println("Clicked => Yes");
}
}
});
JButton btn_3 = new JButton("Button - Show Input Box");
btn_3.setBounds(10, 150, 380, 50);
// Show Input dialog box
btn_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// This will create a Input dialog box
String input = JOptionPane.showInputDialog(
frame, // Parent
"Enter your age."); // Message String
System.out.println("Age = " + input);
}
});
frame.add(btn_1);
frame.add(btn_2);
frame.add(btn_3);
frame.setVisible(true);
}
}