📄 37.txt
字号:
// package
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.awt.geom.*;
import java.util.*;
// 1
/**
定义了一个空 Frame 宽度 WIDTH 高度 HEIGHT
*/
class BlankFrame extends JFrame
{
public BlankFrame()
{
counter++;
setTitle("Frame "+counter);
setSize (WIDTH, HEIGHT);
setLocation(SPACE*counter,SPACE*counter);
// create a panel
EventPanel panel = new EventPanel();
// add panel to frame
Container contentPane = getContentPane();
contentPane.add(panel);
}
public static final int WIDTH = 300;
public static final int HEIGHT = 300;
public static final int SPACE = 30;
private static int counter = 0;
}
//
聊天界面
// 显示框架
public class ChatTest
{
public static void main(String[] args)
{
ChatFrame frame = new ChatFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocation(250,100);
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("about.gif"));
frame.setVisible(true);
frame.setResizable(false);
frame.addWindowListener(new
WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
class ChatFrame extends JFrame
{
Container contentPane;
public ChatFrame() // initialization Emailframe
{
this.setSize(WIDTH, HEIGHT);
this.setTitle("...局域网聊天 ... ");
contentPane = getContentPane();
show = new JTextArea(8,24);
show.setFont(new Font("宋体",Font.PLAIN,20));
scroll = new JScrollPane(show);
contentPane.add(scroll,BorderLayout.CENTER);
show.setLineWrap(true);
msgPanel panel = new msgPanel();
Border border = BorderFactory.createEtchedBorder();
panel.setBorder(border);
contentPane.add(panel,BorderLayout.SOUTH);
}
public static final int WIDTH = 365;
public static final int HEIGHT = 400;
private JTextField message;
private JTextArea show;
private JComboBox box;
private JButton send;
private JScrollPane scroll;
private BufferedReader in ;
private PrintWriter out;
public void sendMsg() // send Email
{
show.append(box.getSelectedItem()+message.getText()+"\n");
scroll.validate();
}
class msgPanel extends JPanel
{
public msgPanel()
{
box = new JComboBox();
box.addItem("妹妹:");
box.addItem("哥哥:");
this.add(box);
message = new JTextField(22);
message.setFont(new Font("宋体",Font.PLAIN,20));
this.add(message);
send = new JButton("发送");
send.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
new Thread()
{
public void run()
{
sendMsg();
}
}.start();
}
});
this.add(send);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -