KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > example > chat > client > ConnectDialog


1 /*
2  * @(#) $Id: ConnectDialog.java 555855 2007-07-13 03:19:00Z trustin $
3  *
4  * Copyright 2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */

19 package org.apache.mina.example.chat.client;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Frame JavaDoc;
23 import java.awt.HeadlessException JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25
26 import javax.swing.AbstractAction JavaDoc;
27 import javax.swing.BoxLayout JavaDoc;
28 import javax.swing.JButton JavaDoc;
29 import javax.swing.JCheckBox JavaDoc;
30 import javax.swing.JDialog JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JTextField JavaDoc;
34
35 /**
36  *
37  * @author The Apache Directory Project (mina-dev@directory.apache.org)
38  * @version $Rev$, $Date$
39  *
40  */

41 public class ConnectDialog extends JDialog JavaDoc {
42     private static final long serialVersionUID = 2009384520250666216L;
43
44     private String JavaDoc serverAddress;
45
46     private String JavaDoc username;
47
48     private boolean useSsl;
49
50     private boolean cancelled = false;
51
52     public ConnectDialog(Frame JavaDoc owner) throws HeadlessException JavaDoc {
53         super(owner, "Connect", true);
54
55         serverAddress = "localhost:1234";
56         username = "user" + Math.round(Math.random() * 10);
57
58         final JTextField JavaDoc serverAddressField = new JTextField JavaDoc(serverAddress);
59         final JTextField JavaDoc usernameField = new JTextField JavaDoc(username);
60         final JCheckBox JavaDoc useSslCheckBox = new JCheckBox JavaDoc("Use SSL", false);
61
62         JPanel JavaDoc content = new JPanel JavaDoc();
63         content.setLayout(new BoxLayout JavaDoc(content, BoxLayout.PAGE_AXIS));
64         content.add(new JLabel JavaDoc("Server address"));
65         content.add(serverAddressField);
66         content.add(new JLabel JavaDoc("Username"));
67         content.add(usernameField);
68         content.add(useSslCheckBox);
69
70         JButton JavaDoc okButton = new JButton JavaDoc();
71         okButton.setAction(new AbstractAction JavaDoc("OK") {
72             private static final long serialVersionUID = -2292183622613960604L;
73
74             public void actionPerformed(ActionEvent JavaDoc e) {
75                 serverAddress = serverAddressField.getText();
76                 username = usernameField.getText();
77                 useSsl = useSslCheckBox.isSelected();
78                 ConnectDialog.this.dispose();
79             }
80         });
81
82         JButton JavaDoc cancelButton = new JButton JavaDoc();
83         cancelButton.setAction(new AbstractAction JavaDoc("Cancel") {
84             private static final long serialVersionUID = 6122393546173723305L;
85
86             public void actionPerformed(ActionEvent JavaDoc e) {
87                 cancelled = true;
88                 ConnectDialog.this.dispose();
89             }
90         });
91
92         JPanel JavaDoc buttons = new JPanel JavaDoc();
93         buttons.add(okButton);
94         buttons.add(cancelButton);
95
96         getContentPane().add(content, BorderLayout.CENTER);
97         getContentPane().add(buttons, BorderLayout.SOUTH);
98     }
99
100     public boolean isCancelled() {
101         return cancelled;
102     }
103
104     public String JavaDoc getServerAddress() {
105         return serverAddress;
106     }
107
108     public String JavaDoc getUsername() {
109         return username;
110     }
111
112     public boolean isUseSsl() {
113         return useSsl;
114     }
115 }
116
Popular Tags