在这里插入代码片
public class ChatServer extends JFrame implements ActionListener{
JButton jb1;
JButton jb2;
JPanel jp;
public ChatServer() {
jb1=new JButton("启动服务器");
jb1.addActionListener(this);
jb2=new JButton("停止服务器");
jp=new JPanel();
jp.add(jb1);
jp.add(jb2);
this.add(jp);
this.setSize(240,240);
this.setTitle("YYChat服务器");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
ChatServer chatServer=new ChatServer();
}
@Override
public void actionPerformed(ActionEvent e) {
new StartServer();
}
}
本文介绍了一个使用Java Swing创建的简易聊天服务器GUI界面实现。该界面包含启动和停止服务器的按钮,通过ActionListener监听事件,实现了服务器的基本控制功能。

6538

被折叠的 条评论
为什么被折叠?



