/**
* 功能:Swing编程实战(qq聊天)JTextArea(多行文本框组件)
* 作者:小孟鱼
* 日期:2018.8.18
*
*/
package com.gui;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Test_gui_10 extends JFrame{
//创建组件
JTextArea jta=null;
JScrollPane jsp=null;//可以再面板输入多行数据让其滚动
JPanel jp1=null;
JComboBox jcb=null;//下拉框组件
JTextField jtf=null;//文本框
JButton jb=null;
public static void main(String[] args) {
Test_gui_10 test_gui_10=new Test_gui_10();
}
//构造函数
public Test_gui_10()
{
jta=new JTextArea();
jsp=new JScrollPane(jta);
jp1=new JPanel();
String []chatter= {"布什","拉登","王校长"};
jcb=new JComboBox(chatter);
jtf=new JTextField(10);
jb=new JButton("发送");
//设置布局管理
//添加组件
jp1.add(jcb);
jp1.add(jtf);
jp1.add(jb);
//加入到JFrame
this.add(jsp);
this.add(jp1,BorderLayout.SOUTH);
//给窗口设置一个标题
this.setTitle("QQ聊天");
//给窗口设置一个大小
this.setSize(300, 150);
//属性
//this.setIconImage(new ImageIcon("images/timg1.jpg"));错误的 下面是正确写法
this.setIconImage(new ImageIcon("images/timg1.jpg").getImage());
//禁止用户改变窗口的大小
this.setResizable(false);
//设置窗口的初始位置
this.setLocationRelativeTo(null);
//this.setLocation(300, 300);
//设置当关闭窗口时,保证JVM也关闭
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//显示
this.setVisible(true);
}
}