/Users/lyon/j4p/src/ip/gui/dialog/BooLog.java

1    package ip.gui.dialog; 
2     
3    import java.awt.*; 
4    import java.awt.event.ActionEvent; 
5    import java.awt.event.ActionListener; 
6     
7    /** 
8     BooLog - the boolean dialog 
9     */ 
10   public class BooLog extends Dialog 
11           implements ActionListener { 
12    
13       private Label label; 
14       public Button yesButton; 
15       public Button noButton; 
16    
17    
18       private boolean ok = false; 
19       private boolean done = false; 
20       private Panel buttonPanel = new Panel(); 
21    
22    
23       public static void main(String args[]) { 
24           BooLog bl = new BooLog( 
25                   new Frame(), 
26                   "Boo!", 
27                   "Scared ya??", 
28                   "ok", "cancel"); 
29       } 
30    
31       public BooLog( 
32               Frame frame, 
33               String title, 
34               String prompt, 
35               String yes, String no) { 
36           super(frame, title, true); 
37           label = new Label(prompt); 
38           yesButton = new Button(yes); 
39           noButton = new Button(no); 
40           setButtonPanel(); 
41       } 
42    
43       private void setButtonPanel() { 
44           buttonPanel.setLayout( 
45                   new FlowLayout(FlowLayout.RIGHT)); 
46           buttonPanel.add(label); 
47           buttonPanel.add(noButton); 
48           buttonPanel.add(yesButton); 
49           noButton.addActionListener(this); 
50           yesButton.addActionListener(this); 
51           add("South", buttonPanel); 
52           pack(); 
53           show(); 
54       } 
55    
56       public boolean getUserInput() { 
57           return ok; 
58       } 
59    
60       public void actionPerformed(ActionEvent e) { 
61           Object arg = e.getSource(); 
62           if (arg == yesButton) ok = true; 
63           System.out.println("Input=" + ok); 
64    
65           done = true; 
66           setVisible(false); 
67       } 
68   } 
69