KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > client > util > ConfirmDialog


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.client.util;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import java.util.*;
19
20
21 public class ConfirmDialog extends Dialog implements ActionListener
22 {
23   private Label m_label;
24   private Button m_yes;
25   private Button m_no;
26   private Vector m_listeners = new Vector();
27   private String JavaDoc m_actionCommand;
28
29
30   public ConfirmDialog(Frame f, String JavaDoc message)
31   {
32     super(f, "Confirm", true);
33
34     createContents();
35
36     addWindowListener(
37       new WindowAdapter()
38       {
39         public void windowClosing(WindowEvent e)
40         {
41           no();
42         }
43       }
44     );
45
46     Point parentLoc = getParent().getLocation();
47     setLocation(parentLoc.x + 30, parentLoc.y + 30);
48
49     m_label.setText(message);
50     pack();
51   }
52
53
54   protected void createContents()
55   {
56     Panel panel = new Panel();
57     panel.setLayout(new GridBagLayout());
58
59     m_label = new Label("", Label.CENTER);
60     Constrain.constrain(panel, m_label,
61       0, 0, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER,
62       1.0, 0.0, 5, 10, 5, 10, 20, 0);
63
64     m_yes = new Button("Yes");
65     m_yes.setActionCommand("yes");
66     m_yes.addActionListener(this);
67     Constrain.constrain(panel, m_yes, 0, 1, 1, 1,
68       GridBagConstraints.NONE, GridBagConstraints.NORTHWEST, 0.0, 0.0,
69       10, 10, 10, 10, 20, 3);
70
71     m_no = new Button("No");
72     m_no.setActionCommand("no");
73     m_no.addActionListener(this);
74     Constrain.constrain(panel, m_no, 1, 1, 1, 1,
75       GridBagConstraints.NONE, GridBagConstraints.NORTHEAST, 0.0, 0.0,
76       10, 0, 10, 10, 20, 3);
77
78     add(panel);
79   }
80
81
82   public void addActionListener(ActionListener l)
83   {
84     m_listeners.addElement(l);
85   }
86
87
88   public void removeActionListener(ActionListener l)
89   {
90     m_listeners.removeElement(l);
91   }
92
93
94   public void setActionCommand(String JavaDoc command)
95   {
96     m_actionCommand = command;
97   }
98
99
100   public void actionPerformed(ActionEvent e)
101   {
102     if (e.getActionCommand().equals("yes"))
103       yes();
104     else if (e.getActionCommand().equals("no"))
105       no();
106   }
107
108
109   protected void yes()
110   {
111     setVisible(false);
112     dispose();
113     notifyListeners();
114   }
115
116
117   protected void no()
118   {
119     setVisible(false);
120     dispose();
121   }
122
123
124   protected void notifyListeners()
125   {
126     ActionEvent evt =
127       new ActionEvent(this, ActionEvent.ACTION_PERFORMED, m_actionCommand);
128
129     Enumeration e = m_listeners.elements();
130     while (e.hasMoreElements()) {
131       ActionListener l = (ActionListener)e.nextElement();
132       l.actionPerformed(evt);
133     }
134   }
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Popular Tags