📄 chatframe.java
字号:
package PC;
import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.*;
class ChatFrame extends JFrame{
JTextField sip;
JTextField cip;
JTextField sport;
JTextField cport;
JTextArea input=new JTextArea();
JLabel server;
JLabel client;
JLabel server1;
JLabel client1;
JLabel server2;
JLabel client2;
JLabel serverinf;
JLabel clientinf;
JButton request;
JButton accept;
JButton open;
JButton audio;
JScrollPane jsp=new JScrollPane();
JTextArea chatroom=new JTextArea();
Font ft=new Font("Serif",Font.BOLD,12);
Thread ower;
ChatFrame(){}
ChatFrame(JTextField sip,JTextField cip,JTextField sport,JTextField cport,JTextArea input,JTextArea chatroom,JButton accept,JButton open,JButton audio,Thread owner){
this.sip=sip;
this.cip=cip;
this.sport=sport;
this.cport=cport;
this.input=input;
this.chatroom=chatroom;
this.accept=accept;
this.open=open;
this.audio=audio;
this.ower=owner;
setLayout(null);
setBackground(Color.white);
ImageIcon icon1 = new ImageIcon("lang1.jpg");
ImageIcon icon2 = new ImageIcon("lang2.jpg");
server=new JLabel("SERVER",JLabel.CENTER);
client=new JLabel("CLIENT",JLabel.CENTER);
server1=new JLabel(icon1,JLabel.CENTER);
client1=new JLabel(icon2,JLabel.CENTER);
server2=new JLabel("PORT:",JLabel.CENTER);
client2=new JLabel("PORT:",JLabel.CENTER);
serverinf=new JLabel("IP:",JLabel.CENTER);
clientinf=new JLabel("IP:",JLabel.CENTER);
request=new JButton("ASK");
request.setBackground(Color.white);
accept.setBackground(Color.white);
server.setSize(150, 20);
server.setLocation(0, 0);
server1.setSize(150, 100);
server1.setLocation(0, 20);
serverinf.setSize(50, 20);
serverinf.setLocation(0, 120);
sip.setSize(100, 20);
sip.setLocation(50, 120);
server2.setSize(50, 20);
server2.setLocation(0, 140);
sport.setSize(100, 20);
sport.setLocation(50, 140);
client.setSize(150, 20);
client.setLocation(0, 160);
client1.setSize(150, 100);
client1.setLocation(0, 180);
clientinf.setSize(50, 20);
clientinf.setLocation(0, 280);
cip.setSize(100, 20);
cip.setLocation(50, 280);
client2.setSize(50, 20);
client2.setLocation(0, 300);
cport.setSize(100, 20);
cport.setLocation(50, 300);
request.setSize(80, 30);
request.setLocation(0, 320);
accept.setSize(80, 30);
accept.setLocation(80, 320);
add(server);
add(sip);
add(cip);
add(sport);
add(cport);
add(serverinf);
add(server1);
add(server2);
add(client2);
add(client);
add(clientinf);
add(client1);
add(request);
add(accept);
open.setSize(100, 20);
open.setLocation(170, 0);
audio.setSize(100, 20);
audio.setLocation(270, 0);
jsp.setSize(300, 230);
jsp.setLocation(170, 20);
jsp.setBorder(new TitledBorder("CHAT-RECORDS"));
input.setSize(300, 100);
input.setLocation(170, 250);
input.setBorder(new TitledBorder("INPUT-PLACE"));
add(open);
add(audio);
add(jsp);
jsp.getViewport().add(chatroom);
add(input);
server.setFont(ft);
chatroom.setFont(ft);
client.setFont(ft);
input.setFont(ft);
serverinf.setFont(ft);
clientinf.setFont(ft);
chatroom.setFont(ft);
chatroom.setEditable(false);
request.setEnabled(true);
accept.setEnabled(true);
input.setEditable(true);
setVisible(true);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
ower.stop();
}
}
);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -