📄 servergui.java
字号:
package server.pool;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class ServerGUI extends JFrame {
JButton start = new JButton();
JButton stop = new JButton();
ServerPool server=new ServerPool();
public ServerGUI() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
this.getContentPane().setBackground(SystemColor.inactiveCaption);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setForeground(Color.orange);
this.setTitle("习题管理系统服务器");
start.setBounds(new Rectangle(98, 31, 101, 23));
start.setActionCommand("start");
start.setText("启动服务器");
start.addActionListener(new ServerGUI_start_actionAdapter(this));
stop.setBounds(new Rectangle(99, 63, 101, 23));
stop.setActionCommand("stop");
stop.setText("关闭服务器");
stop.setEnabled(false);
stop.addActionListener(new ServerGUI_stop_actionAdapter(this));
this.getContentPane().add(start);
this.getContentPane().add(stop);
this.setVisible(true);
this.setBounds(400,400,300,150);
}
public void stop_actionPerformed(ActionEvent e) {
try {
server.closeServer();
start.setEnabled(true);
stop.setEnabled(false);
} catch (IOException ex) {
JOptionPane.showMessageDialog(this,"服务器关闭失败!");
}
}
public void start_actionPerformed(ActionEvent e) {
try {
server.startServer();
start.setEnabled(false);
stop.setEnabled(true);
} catch (IOException ex) {
JOptionPane.showMessageDialog(this,"服务器启动失败!");
}
}
public static void main(String[] arg){
new ServerGUI().validate();
}
}
class ServerGUI_start_actionAdapter implements ActionListener {
private ServerGUI adaptee;
ServerGUI_start_actionAdapter(ServerGUI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.start_actionPerformed(e);
}
}
class ServerGUI_stop_actionAdapter implements ActionListener {
private ServerGUI adaptee;
ServerGUI_stop_actionAdapter(ServerGUI adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.stop_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -