- /*
- * 聊天框
- */
- package com.test.swing;
- import java.awt.*;
- import javax.swing.*;
- public class Test3 extends JFrame {
- //定义组件
- JTextArea jta = null; //文本域
- JPanel jp = null; //面板
- JScrollPane jsp =null;
- JComboBox jc = null; //组合框
- JTextField jtf = null; //文本框
- JButton jb = null; //按钮
- public static void main(String[] args) {
- Test3 test3 = new Test3();
- }
- //构造函数
- public Test3(){
- //创建组件
- jta = new JTextArea();
- jsp = new JScrollPane(jta); //文本域加入滚动条功能
- jp = new JPanel();
- String chatter[] = {"英 拉","普 京","奥巴马"};
- jc = new JComboBox(chatter);
- jtf = new JTextField(10);
- jb = new JButton("发送");
- //添加组件
- this.add(jsp);
- jp.add(jc);
- jp.add(jtf);
- jp.add(jb);
- this.add(jsp); //加入实现滚动功能文本域
- this.add(jp, BorderLayout.SOUTH);
- this.setSize(300, 200);
- this.setResizable(false);
- this.setVisible(true);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Java图形界面——文本域、边界布局
最新推荐文章于 2023-12-09 15:35:49 发布