KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > wizard > MessageDialog


1 package org.enhydra.dods.wizard;
2
3 import java.awt.Button JavaDoc;
4 import java.awt.Dialog JavaDoc;
5 import java.awt.Dimension JavaDoc;
6 import java.awt.Font JavaDoc;
7 import java.awt.Frame JavaDoc;
8 import java.awt.GridBagConstraints JavaDoc;
9 import java.awt.GridBagLayout JavaDoc;
10 import java.awt.Insets JavaDoc;
11 import java.awt.Label JavaDoc;
12 import java.awt.Panel JavaDoc;
13 import java.awt.SystemColor JavaDoc;
14 import java.awt.event.ActionEvent JavaDoc;
15 import java.awt.event.ActionListener JavaDoc;
16 import java.awt.event.KeyAdapter JavaDoc;
17 import java.awt.event.KeyEvent JavaDoc;
18 import java.awt.event.WindowEvent JavaDoc;
19
20 /**
21  * This class is used for showing different dialog messages.
22  *
23  * @author Nenad Vico
24  * @version 1.0
25  */

26 public class MessageDialog extends Dialog JavaDoc {
27     Panel JavaDoc mainPanel;
28     GridBagLayout JavaDoc gridBagLayout;
29     Label JavaDoc lMessage;
30     Button JavaDoc bOK;
31     Label JavaDoc lEmpty2;
32     Label JavaDoc lEmpty3;
33     Label JavaDoc lEmpty4;
34
35     /**
36      * Constructor (String, Frame, String, boolean).
37      *
38      * @param message Message that will be shown in the dialog.
39      * @param frame Frame that calls dialog with the massage.
40      * @param title Title of the dialog.
41      * @param modal True if Dialog needs to be modal, otherwise false.
42      */

43     public MessageDialog(String JavaDoc message, Frame JavaDoc frame, String JavaDoc title, boolean modal) {
44         super(frame, title, modal);
45         mainPanel = new Panel JavaDoc();
46         gridBagLayout = new GridBagLayout JavaDoc();
47         lMessage = new Label JavaDoc();
48         bOK = new Button JavaDoc();
49         lEmpty2 = new Label JavaDoc();
50         lEmpty3 = new Label JavaDoc();
51         lEmpty4 = new Label JavaDoc();
52         enableEvents(64L);
53         try {
54             jbInit();
55             lMessage.setText(message);
56             add(mainPanel);
57             pack();
58         } catch (Exception JavaDoc exception) {
59             exception.printStackTrace();
60         }
61     }
62
63     /**
64      * Constructor (String, Frame).
65      * Created Dialog is modal.
66      *
67      * @param message Message that will be shown in the dialog.
68      * @param frame Frame that calls dialog with the massage.
69      */

70     public MessageDialog(String JavaDoc message, Frame JavaDoc frame) {
71         this(message, frame, "", true);
72     }
73
74     /**
75      * Constructor (String, Frame, boolean).
76      *
77      * @param message Message that will be shown in the dialog.
78      * @param frame Frame that calls dialog with the massage.
79      * @param modal True if Dialog needs to be modal, otherwise false.
80      */

81     public MessageDialog(String JavaDoc message, Frame JavaDoc frame, boolean modal) {
82         this(message, frame, "", modal);
83     }
84
85     /**
86      * Constructor (String, Frame, String).
87      * Created dialog is modal.
88      *
89      * @param message Message that will be shown in the dialog.
90      * @param frame Frame that calls dialog with the massage.
91      * @param title Title of the dialog.
92      */

93     public MessageDialog(String JavaDoc message, Frame JavaDoc frame, String JavaDoc title) {
94         this(message, frame, title, true);
95     }
96
97     private void jbInit() throws Exception JavaDoc {
98         mainPanel.setLayout(gridBagLayout);
99         mainPanel.setBackground(SystemColor.control);
100         mainPanel.setSize(new Dimension JavaDoc(500, 400));
101         lMessage.setFont(new Font JavaDoc("Dialog", 1, 12));
102         lMessage.setAlignment(1);
103         lMessage.setText("Message");
104         bOK.setLabel("OK");
105         lEmpty4.setAlignment(1);
106         bOK.addActionListener(new ActionListener JavaDoc() {
107             public void actionPerformed(ActionEvent JavaDoc actionevent) {
108                 bOK_actionPerformed(actionevent);
109             }
110         });
111         bOK.addKeyListener(new KeyAdapter JavaDoc() {
112             public void keyPressed(KeyEvent JavaDoc keyevent) {
113                 bOKKeyPressed(keyevent);
114             }
115         });
116         mainPanel.add(lMessage,
117                 new GridBagConstraints JavaDoc(0, 0, 3, 1, 0.0D, 0.0D, 10, 1,
118                 new Insets JavaDoc(0, 0, 0, 4), 10, 30));
119         mainPanel.add(bOK,
120                 new GridBagConstraints JavaDoc(0, 2, 3, 1, 0.0D, 0.0D, 10, 3,
121                 new Insets JavaDoc(0, 0, 0, 1), 29, 0));
122         mainPanel.add(lEmpty2,
123                 new GridBagConstraints JavaDoc(0, 0, 1, 3, 0.0D, 0.0D, 10, 1,
124                 new Insets JavaDoc(0, 0, 0, 18), 0, 0));
125         mainPanel.add(lEmpty3,
126                 new GridBagConstraints JavaDoc(2, 0, 1, 3, 0.0D, 0.0D, 10, 1,
127                 new Insets JavaDoc(0, 0, 0, 22), 0, 0));
128         mainPanel.add(lEmpty4,
129                 new GridBagConstraints JavaDoc(0, 3, 3, 1, 0.0D, 0.0D, 10, 1,
130                 new Insets JavaDoc(0, 0, 0, 0), 0, 0));
131     }
132
133     protected void processWindowEvent(WindowEvent JavaDoc windowevent) {
134         if (windowevent.getID() == 201) {
135             cancel();
136         }
137         super.processWindowEvent(windowevent);
138     }
139
140     void cancel() {
141         dispose();
142     }
143
144     void bOK_actionPerformed(ActionEvent JavaDoc actionevent) {
145         cancel();
146     }
147
148     void bOKKeyPressed(KeyEvent JavaDoc keyevent) {
149         int i = keyevent.getKeyCode();
150
151         if (i == 27 || i == 10) {
152             cancel();
153         }
154     }
155 }
156
Popular Tags