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

来源:互联网 发布:采购流程优化四手法 编辑:程序博客网 时间:2024/06/05 04:53
  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. }  
阅读全文
0 0
原创粉丝点击