|
Tips & Tricks |
|
If you click on the third button from the main
window or frame then a confirm message dialog
box will open with three button i.e. the “Yes”,
“No” and “Cancel” like the following image:
|
|
enter name” on the frame. Clicking the button
opens an input dialog box. If you click on the
“Ok” button then a message dialog box appears
containing message “Welcome: entered_text”
otherwise it displays a message dialog box
containing message “You pressed cancel
button.”.
Code of Program: ShowInputDialog.java
import javax.swing.*;
import java.awt.event.*;
public class ShowInputDialog{
public static void main(String[] args){
JFrame frame = new JFrame(“Input Dialog
Box Frame”);
JButton button = new JButton(“Show
Input Dialog Box to enter name”);
button.addActionListener(new
ActionListener(){
public void actionPerformed(ActionEvent
ae){
String str =
JOptionPane.showInputDialog(null, “Enter
your name: “,
“JavaJazzUp”, 1);
if(str != null)
JOptionPane.showMessageDialog(null,
“Welcome: “ + str,
“JavaJazzUp”, 1);
else
JOptionPane.showMessageDialog(null,
“You pressed cancel button.”,
“JavaJazzUp”, 1);
}
});
JPanel panel = new JPanel();
panel.add(button);
frame.add(panel);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
|
|
Jan
2008 | Java Jazz Up | 102 |
|
|
View All Topics |
All Pages of this Issue |
Pages:
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 ,
85 ,
86,
87 ,
88,
89 ,
90 ,
91 ,
92 ,
93 ,
94 ,
95 ,
96 ,
97 ,
98 ,
99 ,
100 ,
101 ,
102 ,
103,
104 ,
105 ,
106,
107,
Download PDF |
|
|
|
|
|
|
|
|
|