Java图形界面——文本域、边界布局

  1. /* 
  2.  * 聊天框 
  3.  */  
  4. package com.test.swing;  
  5. import java.awt.*;  
  6. import javax.swing.*;  
  7. public class Test3 extends JFrame {  
  8.         //定义组件  
  9.     JTextArea jta = null;   //文本域  
  10.     JPanel jp = null;       //面板  
  11.     JScrollPane jsp =null;  
  12.     JComboBox jc = null;    //组合框  
  13.     JTextField jtf = null;  //文本框     
  14.     JButton jb = null;      //按钮  
  15.       
  16.     public static void main(String[] args) {  
  17.         Test3 test3 = new Test3();  
  18.     }  
  19.         //构造函数  
  20.     public Test3(){  
  21.         //创建组件  
  22.         jta = new JTextArea();  
  23.         jsp = new JScrollPane(jta); //文本域加入滚动条功能  
  24.           
  25.         jp = new JPanel();  
  26.           
  27.         String chatter[] = {"英    拉","普    京","奥巴马"};  
  28.         jc = new JComboBox(chatter);  
  29.           
  30.         jtf = new JTextField(10);  
  31.         jb = new JButton("发送");  
  32.           
  33.         //添加组件  
  34.         this.add(jsp);  
  35.         jp.add(jc);  
  36.         jp.add(jtf);  
  37.         jp.add(jb);  
  38.           
  39.         this.add(jsp); //加入实现滚动功能文本域  
  40.         this.add(jp, BorderLayout.SOUTH);  
  41.           
  42.         this.setSize(300200);  
  43.         this.setResizable(false);  
  44.         this.setVisible(true);  
  45.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  46.     }  
  47.   
  48. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值