206a5ceec5d4001914a2835148eb641d

来自「使用TCP和UDP协议」· 代码 · 共 75 行

TXT
75
字号
/*
 * 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;
    
    public ServerGUI()
    {
        initPanel();
        this.setContentPane(panel);
        this.setSize(400,600);
    }
    
    void initPanel()
    {
        panel = new JPanel(new BorderLayout());
        if (startButton == null)
            startButton = new JButton("Start!");
        startButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                //..
            }
        });
        if (stopButton == null)
            stopButton = new JButton("Stop!");
        stopButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                //..
            }
        });
        Box buttons = Box.createHorizontalBox();
        buttons.add(startButton);
        buttons.add(Box.createHorizontalStrut(40));
        buttons.add(stopButton);
        
        if (displayPane == null)
        {
            displayArea = new JTextArea();
            displayPane = new JScrollPane(displayArea, 
        			JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
        			JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        }
        
        panel.add(BorderLayout.NORTH, buttons);
        panel.add(BorderLayout.CENTER, displayPane);
    }
    public static void main(String[] args)
    {
        ServerGUI serverGUI = new ServerGUI();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?