Permalink
Browse files

Added field for nickname in the connect-window.

  • Loading branch information...
1 parent 5af0f75 commit 20ee0dbdadeb49856b6b49d8b8ee37676b5969a2 @kd35a committed May 10, 2012
Showing with 26 additions and 2 deletions.
  1. +4 −0 ChatServer/src/clientgui/ChatWindow.java
  2. +22 −2 ChatServer/src/clientgui/ConnectForm.java
@@ -166,5 +166,9 @@ public static void main(String[] args) {
new ChatWindow(host, port);
}
}
+
+ protected void sendMessage(Message msg) {
+ outbox.put(msg);
+ }
}
@@ -10,10 +10,13 @@
import javax.swing.JOptionPane;
import javax.swing.JTextField;
+import message.NickMessage;
+
public class ConnectForm extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
private JTextField hostField;
private JTextField portField;
+ private JTextField nickField;
public ConnectForm() {
}
@@ -24,15 +27,18 @@ public void initGUI() {
JLabel hostLabel = new JLabel("Host:");
JLabel portLabel = new JLabel("Port:");
+ JLabel nickLabel = new JLabel("Nickname:");
hostField = new JTextField("", 15);
portField = new JTextField("1234", 15);
+ nickField = new JTextField("", 15);
JButton connectButton = new JButton("Connect");
ConnectListener cl = new ConnectListener(this);
hostField.addActionListener(cl);
portField.addActionListener(cl);
+ nickField.addActionListener(cl);
connectButton.addActionListener(cl);
GroupLayout layout = new GroupLayout(getContentPane());
@@ -43,10 +49,12 @@ public void initGUI() {
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(hostLabel)
- .addComponent(portLabel))
+ .addComponent(portLabel)
+ .addComponent(nickLabel))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
.addComponent(hostField)
.addComponent(portField)
+ .addComponent(nickField)
.addComponent(connectButton))
);
@@ -57,6 +65,9 @@ public void initGUI() {
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(portLabel)
.addComponent(portField))
+ .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+ .addComponent(nickLabel)
+ .addComponent(nickField))
.addComponent(connectButton)
);
@@ -80,15 +91,24 @@ public ConnectListener(ConnectForm parent) {
this.parent = parent;
}
- @SuppressWarnings("unused")
@Override
public void actionPerformed(ActionEvent event) {
try {
String host = hostField.getText();
int port = Integer.parseInt(portField.getText());
+ String nick = nickField.getText().trim();
+
if (port < 0 || port > 65535)
throw new NumberFormatException();
+
ChatWindow cw = new ChatWindow(host, port);
+
+ if (!nick.equals("")) {
+ NickMessage nm = new NickMessage();
+ nm.setNick(nick);
+ cw.sendMessage(nm);
+ }
+
parent.setVisible(false);
} catch (NumberFormatException exception) {
JOptionPane.showMessageDialog(parent,

0 comments on commit 20ee0db

Please sign in to comment.