source: branches/streams/abcl/examples/gui/awt/AwtDialogPromptStream.java

Last change on this file was 12732, checked in by Mark Evenson, 15 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
3package awt;
4
5import java.awt.BorderLayout;
6import java.awt.Dialog;
7import java.awt.FlowLayout;
8import java.awt.Frame;
9import java.awt.Label;
10import java.awt.Panel;
11import java.awt.TextField;
12import java.awt.event.ActionEvent;
13import java.awt.event.ActionListener;
14
15import abcl.DialogPromptStream;
16
17import javax.swing.JButton;
18
19public 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.