1
package org.jboss.remoting.samples.chat.client;
3
import java.awt.GridBagConstraints;
4
import java.awt.GridBagLayout;
5
import java.awt.Insets;
6
import java.awt.event.ActionEvent;
9
import javax.swing.JButton;
10
import javax.swing.JLabel;
11
import javax.swing.JTextField;
13
import org.jboss.remoting.samples.chat.exceptions.JoinConnectionException;
17
* <p>Description: </p>
18
* <p>Copyright: Copyright (c) 2003</p>
20
* @author not attributable
24
interface JoinConnectionStrategy
26
void join(ChatInfo chatInfo, ChatMember newMember)
27
throws JoinConnectionException;
31
public class JoinFrame extends CloseableFrame {
32
JLabel jLabel1 = new JLabel();
33
JTextField IDField = new JTextField();
34
JButton OKButton = new JButton();
35
JButton CancelButton = new JButton();
37
private ChatInfo chatInfo;
38
private JoinConnectionStrategy jcs;
39
GridBagLayout gridBagLayout1 = new GridBagLayout();
44
JoinConnectionStrategy jcs,
48
this.chatInfo = chatInfo;
60
private void jbInit() throws Exception {
61
jLabel1.setFont(new java.awt.Font("SansSerif", 1, 12));
62
jLabel1.setText("Your ID:");
63
this.getContentPane().setLayout(gridBagLayout1);
65
OKButton.setFont(new java.awt.Font("SansSerif", 1, 12));
66
OKButton.setText("OK");
67
OKButton.addActionListener(new JoinFrame_OKButton_actionAdapter(this));
68
CancelButton.setFont(new java.awt.Font("SansSerif", 1, 12));
69
CancelButton.setText("Cancel");
70
CancelButton.addActionListener(new JoinFrame_CancelButton_actionAdapter(this));
71
this.setTitle("Join a Chat Room");
72
this.getContentPane().add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
73
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(96, 82, 0, 0), 22, 5));
74
this.getContentPane().add(IDField, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0
75
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(96, 0, 0, 39), 215, 0));
76
this.getContentPane().add(CancelButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
77
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(47, 16, 43, 139), 0, 0));
78
this.getContentPane().add(OKButton, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
79
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(49, 108, 43, 0), 22, 0));
86
public static void main(String[] args)
90
ChatMember chatMember = new ChatMember();
91
chatMember.set_name("xyz");
92
ChatInfo chatInfo = new ChatInfo();
93
chatInfo.set_currentMembers(3);
94
chatInfo.set_description("abc");
95
chatInfo.set_origin(new Date());
96
JoinFrame joinFrame = new JoinFrame(
98
new DummyJoinConnectionStrategy(),
102
catch (JoinConnectionException ce)
104
System.out.println("unable to create chat frame");
108
void OKButton_actionPerformed(ActionEvent e) {
112
ChatMember chatMember = new ChatMember();
113
chatMember.set_name(IDField.getText());
114
jcs.join(chatInfo, chatMember);
116
catch (JoinConnectionException jce)
118
System.out.println("OK button catches exception:");
119
System.out.println(jce);
123
void CancelButton_actionPerformed(ActionEvent e) {
130
class DummyJoinConnectionStrategy implements JoinConnectionStrategy
132
public DummyJoinConnectionStrategy() throws JoinConnectionException
134
System.out.println("DummyJoinConnectionStrategy()");
137
public void join(ChatInfo chatInfo, ChatMember newMember) throws JoinConnectionException
139
System.out.println("DummyJoinConnectionStrategy.getId(" + chatInfo.get_key() + ", " + newMember.get_name() + ")");
143
class JoinFrame_OKButton_actionAdapter implements java.awt.event.ActionListener {
146
JoinFrame_OKButton_actionAdapter(JoinFrame adaptee) {
147
this.adaptee = adaptee;
149
public void actionPerformed(ActionEvent e) {
150
adaptee.OKButton_actionPerformed(e);
154
class JoinFrame_CancelButton_actionAdapter implements java.awt.event.ActionListener {
157
JoinFrame_CancelButton_actionAdapter(JoinFrame adaptee) {
158
this.adaptee = adaptee;
160
public void actionPerformed(ActionEvent e) {
161
adaptee.CancelButton_actionPerformed(e);