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 | // $Id: AwtDialogPromptStream.java 12732 2010-05-25 13:00:59Z mevenson $ |
---|
2 | |
---|
3 | package awt; |
---|
4 | |
---|
5 | import java.awt.BorderLayout; |
---|
6 | import java.awt.Dialog; |
---|
7 | import java.awt.FlowLayout; |
---|
8 | import java.awt.Frame; |
---|
9 | import java.awt.Label; |
---|
10 | import java.awt.Panel; |
---|
11 | import java.awt.TextField; |
---|
12 | import java.awt.event.ActionEvent; |
---|
13 | import java.awt.event.ActionListener; |
---|
14 | |
---|
15 | import abcl.DialogPromptStream; |
---|
16 | |
---|
17 | import javax.swing.JButton; |
---|
18 | |
---|
19 | public class AwtDialogPromptStream extends DialogPromptStream { |
---|
20 | |
---|
21 | Dialog dialog = new Dialog((Frame)null, true); |
---|
22 | private Label prompt = new Label(); |
---|
23 | private TextField input = new TextField(32); |
---|
24 | |
---|
25 | public AwtDialogPromptStream() { |
---|
26 | this("Prompt"); |
---|
27 | } |
---|
28 | |
---|
29 | public AwtDialogPromptStream(String title) { |
---|
30 | super(); |
---|
31 | dialog.setTitle(title); |
---|
32 | Panel tmpPanel = new Panel(); |
---|
33 | tmpPanel.add(prompt); |
---|
34 | tmpPanel.add(input); |
---|
35 | dialog.add(tmpPanel); |
---|
36 | JButton okBtn = new JButton("Ok"); |
---|
37 | okBtn.addActionListener(new ActionListener() { |
---|
38 | |
---|
39 | public void actionPerformed(ActionEvent e) { |
---|
40 | synchronized(dialog) { |
---|
41 | dialog.dispose(); |
---|
42 | } |
---|
43 | } |
---|
44 | }); |
---|
45 | tmpPanel = new Panel(new FlowLayout()); |
---|
46 | tmpPanel.add(okBtn); |
---|
47 | dialog.add(tmpPanel, BorderLayout.SOUTH); |
---|
48 | } |
---|
49 | |
---|
50 | @Override |
---|
51 | protected void closeDialog() { |
---|
52 | dialog.dispose(); |
---|
53 | } |
---|
54 | |
---|
55 | @Override |
---|
56 | protected String readInputFromModalDialog(String promptText) { |
---|
57 | prompt.setText(promptText); |
---|
58 | dialog.pack(); |
---|
59 | dialog.setVisible(true); |
---|
60 | return input.getText(); |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.