Java聊天--聊天界面

import java.awt.*;
import javax.swing.*;

public class myMain extends JFrame {
	
	JTextField tsend;//在外部声明文本框,用来写留言
	Choice clist;//声明下拉框,用来罗列在线用户
	JTextArea ta;//声明大型文本区,用来显示聊天记录
	
	myMain(String title){
		super(title);
		this.setSize(400,300);
		this.setLocation(150,250);
		Container con = this.getContentPane();
		con.setLayout(new BorderLayout());//设置窗体布局为BorderLayout
		
		JPanel pp = new JPanel();
		JPanel p1 = new JPanel();
		JPanel p2 = new JPanel();
		
		ta = new JTextArea();//实例化大型文本区
		ta.disable();//设置成只读属性
		
		pp.setLayout(new GridLayout(2,1));//把pp设成(2,1)网格布局
		pp.add(p1);
		pp.add(p2);
		
		con.add(pp, BorderLayout.SOUTH);//Container把pp放在窗体北边
		con.add(ta, BorderLayout.CENTER);//Container把文本区放在中间
		
		JLabel l1 = new JLabel("留言");
		JLabel l2 = new JLabel("to");
		
		tsend = new JTextField(30);//实例化文本框
		clist = new Choice();//实例化下拉列表框
		clist.add("王");
		clist.add("盖");
		clist.add("邱");
		clist.add("杜");
		JButton bSend = new JButton("发送");
		
		p1.add(l1);
		p1.add(tsend);
		p2.add(l2);
		p2.add(bSend);
		p2.add(clist);
		clist.addItem("所有联系人");//下拉列表框添加一项内容
	}
	public static void main(String args[]){
		myMain wm = new myMain("Java聊天窗口");
		wm.show();
	}
}

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值