Last change
on this file was
12732,
checked in by Mark Evenson, 14 years ago
|
Make GUI examples buildable; putative attempt at a README.
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Id
|
File size:
1.3 KB
|
Line | |
---|
1 | package swing; |
---|
2 | |
---|
3 | import java.awt.BorderLayout; |
---|
4 | import java.awt.FlowLayout; |
---|
5 | import java.awt.Frame; |
---|
6 | import java.awt.event.ActionEvent; |
---|
7 | import java.awt.event.ActionListener; |
---|
8 | |
---|
9 | import javax.swing.JButton; |
---|
10 | import javax.swing.JDialog; |
---|
11 | import javax.swing.JLabel; |
---|
12 | import javax.swing.JPanel; |
---|
13 | import javax.swing.JTextField; |
---|
14 | |
---|
15 | import abcl.DialogPromptStream; |
---|
16 | |
---|
17 | public class SwingDialogPromptStream extends DialogPromptStream { |
---|
18 | |
---|
19 | JDialog dialog = new JDialog((Frame)null, true); |
---|
20 | private JLabel prompt = new JLabel(); |
---|
21 | private JTextField input = new JTextField(32); |
---|
22 | |
---|
23 | public SwingDialogPromptStream() { |
---|
24 | this("Prompt"); |
---|
25 | } |
---|
26 | |
---|
27 | public SwingDialogPromptStream(String title) { |
---|
28 | super(); |
---|
29 | dialog.setTitle(title); |
---|
30 | JPanel tmpPanel = new JPanel(); |
---|
31 | tmpPanel.add(prompt); |
---|
32 | tmpPanel.add(input); |
---|
33 | dialog.add(tmpPanel); |
---|
34 | JButton okBtn = new JButton("Ok"); |
---|
35 | okBtn.addActionListener(new ActionListener() { |
---|
36 | |
---|
37 | public void actionPerformed(ActionEvent e) { |
---|
38 | synchronized(dialog) { |
---|
39 | dialog.dispose(); |
---|
40 | } |
---|
41 | } |
---|
42 | }); |
---|
43 | tmpPanel = new JPanel(new FlowLayout()); |
---|
44 | tmpPanel.add(okBtn); |
---|
45 | dialog.add(tmpPanel, BorderLayout.SOUTH); |
---|
46 | } |
---|
47 | |
---|
48 | @Override |
---|
49 | protected void closeDialog() { |
---|
50 | dialog.dispose(); |
---|
51 | } |
---|
52 | |
---|
53 | @Override |
---|
54 | protected String readInputFromModalDialog(String promptText) { |
---|
55 | prompt.setText(promptText); |
---|
56 | dialog.pack(); |
---|
57 | dialog.setVisible(true); |
---|
58 | return input.getText(); |
---|
59 | } |
---|
60 | |
---|
61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.