⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatroom.java

📁 JAVA做的QQ软件,感兴趣的可以看看,收藏依旧
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;

public class ChatRoom extends JFrame implements Runnable
{
	JTextArea msgTA,noticeTA;
	JList inline;
	JTextField msg;
	JButton send,exit;
	JLabel welcome,to;
	BorderLayout bl1,bl2;
	GridBagLayout gbl;
	GridBagConstraints gbc;
	FlowLayout fl;
	JPanel p1,p2,p3;
	JScrollPane jsp;
	JComboBox jcb;
	
	public ChatRoom()
	{
		super("Welcome !!");
		Container c=this.getContentPane();
		c.setBackground(Color.pink);
		bl1=new BorderLayout(10,10);
		bl2=new BorderLayout(10,10);
		c.setLayout(bl1);
		
		Image img = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/pictures/leave.gif"));
		welcome=new JLabel("欢迎进入聊天室!!",new ImageIcon(img),0);
		msgTA=new JTextArea(16,33);
		//msgTA.setEditable(false);
		msgTA.setLineWrap(true);
		jsp=new JScrollPane(msgTA);
		noticeTA=new JTextArea("-------   Notice   -------",3,10);
		noticeTA.setEditable(false);
		String[] users={"dog","cat","rain"};
		inline=new JList(users);
		msg=new JTextField(33);
		send=new JButton("Send Message");
		exit=new JButton("Exit ChatRoom");
		to=new JLabel("To:");	
		jcb=new JComboBox(users);
		
		
		p1=new JPanel();
		p1.setLayout(bl2);
		p1.setBackground(Color.pink);
		p1.add(noticeTA,BorderLayout.NORTH);
		p1.add(inline,BorderLayout.CENTER);	
		
		p2=new JPanel();
		p2.setBackground(Color.pink);
		gbl=new GridBagLayout();
		gbc=new GridBagConstraints();
		
		p2.setLayout(gbl);
		
		gbc.insets.left=50;
		gbc.gridx=1;
		gbl.setConstraints(to,gbc);
		p2.add(to);
		
		gbc.gridx=2;
		gbl.setConstraints(jcb,gbc);
		p2.add(jcb);
		
		gbc.gridx=3;
		gbl.setConstraints(send,gbc);
		p2.add(send);
		
		gbc.gridx=4;
		gbl.setConstraints(exit,gbc);
		p2.add(exit);
		
		p3=new JPanel();
		p3.setBackground(Color.pink);
		fl=new FlowLayout(5);
		p3.setLayout(fl);
		p3.add(jsp);
		p3.add(msg);
		
		c.add(welcome,BorderLayout.NORTH);
		c.add(p3,BorderLayout.CENTER);
		c.add(p1,BorderLayout.EAST);
		c.add(p2,BorderLayout.SOUTH);
		
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setSize(500,425);
		this.setVisible(true);
		
		// 启动循环接受来自服务器的对象流
		
	}
	public static void main(String[] a)
	{
		new ChatRoom();
	}
	public void run()
	{
		
	}
}

⌨️ 快捷键说明

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