public class Main extends JFrame implements ChatServerListener {
ChatServerImpl server = ChatServerImpl.getInstance();
JTextArea textArea;
JMenuBar menuBar;
JToolBar toolBar;
StartServerActon startAction = new StartServerActon();
StopServerAction stopAction = new StopServerAction();
@SuppressWarnings("deprecation")
public static void main(String[] args) {
// TODO Auto-generated method stub
Main main = new Main(); //这一句有错误,不知道错哪了
//main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//main.setVisible(true);
main.show();
}
public Main(){
super("聊天-服务器");
setSize(300,500);
layoutComponents();
}
ChatServerListener,layoutComponents(),StartServerActon,StopServerAction这些类或接口都没给,去掉这些东西的话是不会有异常的,所以你要去检查这些类或接口的问题了
class StartServerActon extends AbstractAction{
public StartServerActon(){
super("启动");
putValue(
Action.SMALL_ICON,
new ImageIcon(getClass().getResource("E:/1.jpg"))); ///这一行也提示,找不到资源。
putValue(Action.SHORT_DESCRIPTION,"启动聊天服务器");
putValue(Action.ACCELERATOR_KEY,
KeyStroke.getKeyStroke("Control A"));
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try{
server.addListener(Main.this);
textArea.setText("");
server.start();
stopAction.setEnabled(true);
this.setEnabled(false);
}catch(Exception e){
textArea.append("服务器启动错误");
server.removeListener(Main.this);
}
}
}
new ImageIcon("这里写成绝对路径那"); ///这一行也提示,找不到资源。
我用JTextArea这个类实例化好了还在类里面用成功了,但是在调用setText和另一增加文字的函数的时候居然报空指针