// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: Client.java
package test;
import component.QiZi;
import inter.QiZiInter;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.StringTokenizer;
import javax.swing.*;
import javax.swing.border.TitledBorder;
public class Client
{
class ClientFrame extends JFrame
{
private static final long serialVersionUID = 1L;
private JToolBar toolbar;
private JPanel centerPanel;
private JButton btnLink;
private JButton btnClose;
private JButton btnReady;
private JButton btnEnterRoom;
private JButton btnExitRoom;
private JTextField txtName;
private JTextField txtIp;
private JTextField txtPort;
private JList roomList;
private DefaultListModel roomData;
final Client this$0;
public DefaultListModel getRoomData()
{
return roomData;
}
public JList getRoomList()
{
return roomList;
}
public JButton getBtnReady()
{
return btnReady;
}
public JButton getBtnEnterRoom()
{
return btnEnterRoom;
}
public JButton getBtnExitRoom()
{
return btnExitRoom;
}
public ClientFrame(String title, String msgs[])
{
this$0 = Client.this;
super(title);
setDefaultCloseOperation(0);
roomData = new DefaultListModel();
roomList = new JList(roomData);
roomList.setBorder(new TitledBorder("房间列表"));
btnLink = new JButton("连接");
btnClose = new JButton("断开");
btnReady = new JButton("就绪");
btnReady.setEnabled(false);
btnEnterRoom = new JButton("进入房间");
btnExitRoom = new JButton("离开房间");
btnExitRoom.setEnabled(false);
txtName = new JTextField("doudou");
txtIp = new JTextField("127.0.0.1");
txtPort = new JTextField("6969");
toolbar = new JToolBar();
toolbar.add(btnEnterRoom);
toolbar.add(btnExitRoom);
toolbar.add(new JLabel("用户名:"));
toolbar.add(txtName);
toolbar.add(new JLabel("服务器IP:"));
toolbar.add(txtIp);
toolbar.add(new JLabel("端口:"));
toolbar.add(txtPort);
toolbar.add(btnLink);
toolbar.add(btnClose);
toolbar.add(btnReady);
qipan = new QiPan(30);
centerPanel = new JPanel(new BorderLayout());
centerPanel.add(toolbar, "North");
centerPanel.add(qipan, "Center");
talkPanel = new TalkPanel(msgs);
add(roomList, "West");
add(centerPanel, "Center");
add(talkPanel, "East");
setSize(920, 550);
validate();
setVisible(true);
btnEnterRoom.addActionListener(new ActionListener() {
final ClientFrame this$1;
public void actionPerformed(ActionEvent e)
{
if (stop)
{
JOptionPane.showMessageDialog(clientFrame, "还没有连接服务器!", "错误操作", 0);
return;
}
if (roomList.getSelectedIndex() == -1)
{
JOptionPane.showMessageDialog(clientFrame, "还没有选择房间!", "错误操作", 0);
return;
} else
{
String str = roomList.getSelectedValue().toString();
StringTokenizer st = new StringTokenizer(str, "$");
st.nextToken();
clientFrame.setCursor(QiZiInter.WAITING_CURSOR);
msgThread.sendMessage((new StringBuilder("into_room$")).append(name).append("$").append(st.nextToken()).toString());
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
return;
}
}
{
this$1 = ClientFrame.this;
super();
}
});
btnExitRoom.addActionListener(new ActionListener() {
final ClientFrame this$1;
public void actionPerformed(ActionEvent e)
{
if (stop)
{
JOptionPane.showMessageDialog(clientFrame, "还没有连接服务器!", "错误操作", 0);
return;
} else
{
clientFrame.setCursor(QiZiInter.WAITING_CURSOR);
msgThread.sendMessage((new StringBuilder("exit_room$")).append(name).append("$").append("请求离开房间").toString());
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
return;
}
}
{
this$1 = ClientFrame.this;
super();
}
});
btnLink.addActionListener(new ActionListener() {
final ClientFrame this$1;
public void actionPerformed(ActionEvent e)
{
if (!stop)
break MISSING_BLOCK_LABEL_356;
String str;
String str1;
String str2;
Exception e1;
try
{
str = txtName.getText().trim();
if (str == null || str.equals(""))
{
JOptionPane.showMessageDialog(ClientFrame.this, "连接用户名必须填写!", "错误", 0);
return;
}
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(ClientFrame.this, e1.getMessage(), "异常", 0);
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
return;
}
name = str;
str1 = txtIp.getText().trim();
if (str1 == null || str1.equals(""))
{
JOptionPane.showMessageDialog(ClientFrame.this, "服务器IP必须填写!", "错误", 0);
return;
}
if (!str1.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"))
{
JOptionPane.showMessageDialog(ClientFrame.this, "IP地址格式错误!", "错误", 0);
return;
}
ip = str1;
str2 = txtPort.getText().trim();
if (str2 == null || str2.equals(""))
{
JOptionPane.showMessageDialog(ClientFrame.this, "端口必须填写!", "错误", 0);
return;
}
try
{
port = Integer.parseInt(str2);
}
// Misplaced declaration of an exception variable
catch (Exception e1)
{
JOptionPane.showMessageDialog(ClientFrame.this, "端口是正整数!", "错误", 0);
return;
}
setTitle((new StringBuilder("五子棋")).append(name).toString());
clientFrame.setCursor(QiZiInter.WAITING_CURSOR);
openConnection();
btnEnterRoom.setEnabled(true);
btnExitRoom.setEnabled(false);
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
JOptionPane.showMessageDialog(ClientFrame.this, "连接服务器成功!", "成功", 1);
break MISSING_BLOCK_LABEL_368;
JOptionPane.showMessageDialog(ClientFrame.this, "已经与服务器建立了,无须再连接!", "警告", 0);
}
{
this$1 = ClientFrame.this;
super();
}
});
btnClose.addActionListener(new ActionListener() {
final ClientFrame this$1;
public void actionPerformed(ActionEvent e)
{
if (!stop)
{
clientFrame.setCursor(QiZiInter.WAITING_CURSOR);
btnReady.setEnabled(true);
stop = true;
talkPanel.setMyEnabled(false);
qipan.resetGame();
qipan.setWaiting(true);
msgThread.sendMessage((new StringBuilder("client_close$")).append(name).append("$").append("bye").toString());
try
{
msgThread.closeConnection();
btnEnterRoom.setEnabled(true);
btnExitRoom.setEnabled(false);
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
JOptionPane.showMessageDialog(ClientFrame.this, "断开服务器成功!", "成功", 1);
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(ClientFrame.this, e1.getMessage(), "异常", 0);
clientFrame.setCursor(QiZiInter.NORMAL_CURSOR);
return;
}
} else
{
JOptionPane.showMessageDialog(ClientFrame.this, "已经处于断开状态!", "警告", 0);
}
}
{
this$1 = ClientFrame.this;
super();
}
});
btnReady.addActionListener(new ActionListener() {
final ClientFrame this$1;
public void actionPerformed(ActionEvent e)
{
if (stop)
{
JOptionPane.showMessageDialog(ClientFrame.this, "还没有连接服务器!", "错误", 0);
return;
} else
{
clientFrame.setCursor(Qi