package graph;
/*
*
* JSplitPane
*/
import java.awt.*;
import javax.swing.*;
public class demo9 extends JFrame{
JSplitPane jsp;
JList jlist;
JLabel jl1;
public static void main(String[] args) {
// TODO Auto-generated method stub
demo9 demo = new demo9();
}
public demo9() {
//chuangjianzujian
String[] words = {"boys","girls","birds"};
jlist = new JList<>(words);
jl1 = new JLabel(new ImageIcon("1.jpg"));
//caifenchuangge
jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jlist,jl1);
//shezhi keyibianhua
jsp.setOneTouchExpandable(true);
//tianjiazujian
this.add(jsp);
this.setTitle("123");
this.setSize(300, 300);
this.setLocation(500, 200);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
package graph;
/*
* qq聊天界面
* 使用多行文本框
*
* */
import java.awt.*;
import javax.swing.*;
public class demo10 extends JFrame {
JTextArea jta1;
JComboBox jcb;
JTextField jtf;
JButton button;
JPanel jp1;
public static void main(String[] args) {
// TODO Auto-generated method stub
demo10 demo = new demo10();
}
public demo10() {
jp1 = new JPanel();
jta1 = new JTextArea();
String[] ss = {"布什","奥巴马","特朗普","泷泽萝拉"};
jcb = new JComboBox(ss);
jtf = new JTextField(10);
button = new JButton("发送");
//设置布局
//添加组件
jp1.add(jcb);
jp1.add(jtf);
jp1.add(button);
this.add(jta1);
this.add(jp1,BorderLayout.NORTH);
this.setTitle("聊天窗口");
this.setSize(300, 300);
this.setLocation(500, 200);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
多行文本可滚动:
package graph;
/*
* qq聊天界面
* 使用多行文本框
* 多行文本可滚动;
* */
import java.awt.*;
import javax.swing.*;
public class demo10 extends JFrame {
JTextArea jta1;
JComboBox jcb;
JScrollPane jsp;
JTextField jtf;
JButton button;
JPanel jp1;
public static void main(String[] args) {
// TODO Auto-generated method stub
demo10 demo = new demo10();
}
public demo10() {
jp1 = new JPanel();
jta1 = new JTextArea();
jsp = new JScrollPane(jta1);
String[] ss = {"布什","奥巴马","特朗普","泷泽萝拉"};
jcb = new JComboBox(ss);
jtf = new JTextField(10);
button = new JButton("发送");
//设置布局
//添加组件
jp1.add(jcb);
jp1.add(jtf);
jp1.add(button);
this.add(jsp);
this.add(jp1,BorderLayout.NORTH);
this.setTitle("QQ聊天窗口");
//在title前面设置图片;
this。setIconImage((new ImageIcon("1.jpg")).getImage());
this.setSize(300, 300);
this.setLocation(500, 200);
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setVisible(true);
}
}