大家看看这个服务器程序错在哪里
import java.awt.*;import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import *;
import *;
import javax.swing.*;
public class MyServer extends JFrame implements ActionListener {
JTextArea jta;
JButton jb1, jb2;
JPanel jp;
int port = 888;
ServerSocket ss;
BufferedReader br;
PrintWriter pw;
public MyServer() {
super("服务器");
jta = new JTextArea();
jb1 = new JButton("中断");
jb2 = new JButton("启动");
jp = new JPanel();
jp.add(jb2);
jp.add(jb1);
this.add(jp, "North");
this.add(jta);
jb1.addActionListener(this);
jb2.addActionListener(this);
this.setBounds(300, 300, 250, 350);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == "启动") {
jb2.setEnabled(false);
jb1.setEnabled(true);
try {
ss = new ServerSocket(port);
jta.append("服务器启动成功" + "\n");
//new ServerListen(ss, jta, br, pw).start();
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
Socket server;
try {
server = ss.accept();
br = new BufferedReader(new InputStreamReader(server.getInputStream()));
pw=new PrintWriter(new OutputStreamWriter(server.getOutputStream()));
new Thread(new Runnable() {
String message;
@Override
public void run() {
try {
while ((message = br.readLine()) != null) {
pw.println("**"+message);
pw.flush();
jta.append("客户说:"+message + "\n");
jta.append("说:"+"**"+message+"\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if (e.getActionCommand() == "中断") {
jb1.setEnabled(false);
jb2.setEnabled(true);
jta.setText("");
pw.close();
try {
br.close();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
ss.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
public static void main(String[] args) {
new MyServer();
}
}
做的是一个socket服务器程序
点击中断按钮后有异常,求大神指点