1
package org.jboss.remoting.samples.chat.client;
3
import java.awt.Dimension;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.awt.Insets;
7
import java.awt.event.ActionEvent;
9
import javax.swing.JButton;
10
import javax.swing.JFrame;
11
import javax.swing.JLabel;
12
import javax.swing.JTextField;
14
import org.jboss.remoting.samples.chat.exceptions.CreateConnectionException;
18
* <p>Description: </p>
19
* <p>Copyright: Copyright (c) 2003</p>
21
* @author not attributable
25
interface CreateConnectionStrategy
27
void createChat(String description, ChatMember owner)
28
throws CreateConnectionException;
31
public class CreateFrame extends CloseableFrame {
32
JLabel jDescriptionLabel = new JLabel();
33
JLabel IDLabel = new JLabel();
34
JTextField descriptionField = new JTextField();
35
JTextField idField = new JTextField();
36
JButton OKButton = new JButton();
37
JButton CancelButton = new JButton();
38
GridBagLayout gridBagLayout1 = new GridBagLayout();
40
private CreateConnectionStrategy ccs;
43
CreateConnectionStrategy ccs,
57
private void jbInit() throws Exception {
58
jDescriptionLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
59
jDescriptionLabel.setText("Description:");
60
this.getContentPane().setLayout(gridBagLayout1);
61
IDLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
62
IDLabel.setText("Your ID:");
63
descriptionField.setText("");
65
OKButton.setFont(new java.awt.Font("SansSerif", 1, 14));
66
OKButton.setText("OK");
67
OKButton.addActionListener(new CreateFrame_OKButton_actionAdapter(this));
68
CancelButton.setFont(new java.awt.Font("SansSerif", 1, 14));
69
CancelButton.setText("Cancel");
70
CancelButton.addActionListener(new CreateFrame_CancelButton_actionAdapter(this));
71
this.setLocale(java.util.Locale.getDefault());
72
this.setResizable(false);
73
this.setTitle("Create a chat room");
74
this.setSize(new Dimension(00, 300));
75
this.getContentPane().add(jDescriptionLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
76
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(25, 21, 0, 0), 11, 4));
77
this.getContentPane().add(IDLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
78
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11, 21, 0, 0), 27, 0));
79
this.getContentPane().add(descriptionField, new GridBagConstraints(2, 0, 2, 1, 1.0, 0.0
80
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(25, 0, 0, 16), 270, 1));
81
this.getContentPane().add(OKButton, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0
82
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(81, 0, 115, 0), 30, -5));
83
this.getContentPane().add(CancelButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
84
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(81, 27, 115, 103), 11, -2));
85
this.getContentPane().add(idField, new GridBagConstraints(2, 1, 2, 1, 1.0, 0.0
86
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(9, 0, 0, 22), 272, 2));
92
void OKButton_actionPerformed(ActionEvent e) {
96
ChatMember chatMember = new ChatMember();
97
chatMember.set_name(idField.getText());
98
ccs.createChat(descriptionField.getText(),chatMember);
100
catch (CreateConnectionException cce)
102
System.out.println("OK button catches exception:");
103
System.out.println(cce);
107
void CancelButton_actionPerformed(ActionEvent e) {
111
public static void main(String[] args) {
112
CreateFrame createFrame;
115
createFrame = new CreateFrame(
116
new DummyCreateConnectionStrategy(),
119
createFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
122
catch (CreateConnectionException ce)
124
System.out.println("unable to create create frame");
130
class CreateFrame_OKButton_actionAdapter implements java.awt.event.ActionListener {
133
CreateFrame_OKButton_actionAdapter(CreateFrame adaptee) {
134
this.adaptee = adaptee;
136
public void actionPerformed(ActionEvent e) {
137
adaptee.OKButton_actionPerformed(e);
141
class CreateFrame_CancelButton_actionAdapter implements java.awt.event.ActionListener {
144
CreateFrame_CancelButton_actionAdapter(CreateFrame adaptee) {
145
this.adaptee = adaptee;
147
public void actionPerformed(ActionEvent e) {
148
adaptee.CancelButton_actionPerformed(e);
152
class DummyCreateConnectionStrategy implements CreateConnectionStrategy
154
public DummyCreateConnectionStrategy() throws CreateConnectionException
156
System.out.println("DummyCreateConnectionStrategy()");
159
public void createChat(String description, ChatMember owner)
160
throws CreateConnectionException
162
System.out.println("description: " + description);
163
System.out.println("nickName: " + owner.get_name());