📄 10db6388cdd4001914a2835148eb641d
字号:
/*
* Created on 2005-6-4
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package server;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ServerGUI extends JFrame{
int tcpPort = 1234,
udpPort = 1235;
JPanel panel = null;
JTextArea displayArea = null;
JScrollPane displayPane = null;
JButton startButton = null,
stopButton = null;
JMenuBar serverMenu = null;
TCPThread tcpThread = null;
public ServerGUI()
{
initFrame();
initPanel();
initMenu();
this.setJMenuBar(serverMenu);
this.setContentPane(panel);
}
void initFrame()
{
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent frameEvent)
{
// tcpThread.finalized();
System.exit(0);
}
});
this.setSize(500, 550);
this.setTitle("\"别问我是谁,请与我面对\"服务器");
}
void initMenu()
{
serverMenu = new JMenuBar();
JMenu fileMenu = new JMenu("文件");
JMenuItem exitItem = new JMenuItem("退出");
fileMenu.add(exitItem);
JMenu settingMenu = new JMenu("选项");
JMenuItem tcpItem = new JMenuItem("TCP端口..");
JMenuItem udpItem = new JMenuItem("UDP端口..");
tcpItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ServerGUI.this.tcpPort = Integer.parseInt(JOptionPane.showInputDialog("Please input tcp port number"));
}
});
udpItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
ServerGUI.this.udpPort = Integer.parseInt(JOptionPane.showInputDialog("Please input udp port number"));
}
});
settingMenu.add(tcpItem);
settingMenu.add(udpItem);
serverMenu.add(fileMenu);
serverMenu.add(settingMenu);
}
void initPanel()
{
panel = new JPanel(new BorderLayout());
if (startButton == null)
startButton = new JButton("启动!");
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
tcpThread = new TCPThread(ServerGUI.this, ServerGUI.this.tcpPort);
}
});
if (stopButton == null)
stopButton = new JButton("停止!");
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//..
}
});
Box buttons = Box.createHorizontalBox();
buttons.add(Box.createHorizontalGlue());
buttons.add(startButton);
buttons.add(Box.createHorizontalGlue());
buttons.add(stopButton);
buttons.add(Box.createHorizontalGlue());
if (displayPane == null)
{
displayArea = new JTextArea();
displayArea.setLineWrap(true);
displayPane = new JScrollPane(displayArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
}
panel.add(BorderLayout.NORTH, buttons);
panel.add(BorderLayout.CENTER, displayPane);
}
public void setDisplayArea(String text)
{
displayArea.setText(text);
}
public void appendDisplayArea(String text)
{
displayArea.append(text);
}
public static void main(String[] args)
{
ServerGUI serverGUI = new ServerGUI();
serverGUI.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -