1.拆分窗格:JSplistPane
package swing; /** * swing 实战 */ import java.awt.*; import javax.swing.*; public class Myframe extends JFrame { // 创建组件 JSplitPane jsp; JList jlist; JLabel jl1; public static void main(String[] args) { Myframe myframe = new Myframe(); } public Myframe() { String[] words = { "boy", "girl", "bird" }; jlist = new JList(words); jl1 = new JLabel(new ImageIcon("images/下载.jpg")); // 拆分窗格 jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jlist, jl1); // 水平拆分 // this.add(jsp); this.setSize(300, 300); this.setLocation(100, 100); this.setSize(300, 250); this.setLocation(200, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }
2.QQ聊天界面:
package swing; /** * QQ聊天界面 优化加上滑框 * @author Administrator * */ import java.awt.*; import javax.swing.*; public class Demo1 extends JFrame { // 创建组件 JTextArea jta = null;// 多行文本框组件 JPanel jp1; JComboBox jcb; JTextField jtf; JButton jb; JScrollPane jsp; public static void main(String[] args) { Demo1 demo = new Demo1(); } public Demo1() { 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);// 按钮 // 加组件 this.setTitle("QQ腾讯"); this.setIconImage((new ImageIcon("images/QQ.png")).getImage()); this.add(jsp); this.add(jp1, BorderLayout.SOUTH); this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }
3.QQ用户登录界面(他日再来吧,,,完善慢慢扣)
import java.awt.*; import javax.swing.*; public class Demo2 extends JFrame { // 北部区域 JLabel jl1; // 南部区域 JButton jb1, jb2, jb3; JPanel jp1; // 中部区域 JTabbedPane jtp;// 选项卡窗格 JPanel jp2, jp3, jp4; JLabel jl2, jl3, jl4, jl5; JTextField jtf; JPasswordField jpf; JButton jb4; JCheckBox jcb1, jcb2; public static void main(String[] args) { Demo2 demo = new Demo2(); } public Demo2() { // 创建组件 jl2 = new JLabel("QQ号码", JLabel.CENTER); jl3 = new JLabel("手机号码", JLabel.CENTER); jl4 = new JLabel("电子邮箱", JLabel.CENTER); jtf = new JTextField(); jb4 = new JButton(new ImageIcon("")); jcb1 = new JCheckBox("隐身登录"); jcb2 = new JCheckBox("记住密码"); // 北部区域 jl1 = new JLabel(new ImageIcon("src/images/qq1.jpg")); // 南郊 jp1 = new JPanel(); jb1 = new JButton((new ImageIcon("src/images/qq.3.jpg"))); jb2 = new JButton((new ImageIcon("src/images/qq.3.jpg"))); jb3 = new JButton((new ImageIcon("src/images/qq.3.jpg"))); // 中部区域 jtp = new JTabbedPane(); jp2 = new JPanel(); jp3 = new JPanel(); jp3.setBackground(Color.RED); // 将面板添加到选项卡窗口 jtp.add("QQ号码", jp2); jtp.add("手机号码", jp3); jtp.add("电子邮箱", jp4); // 设置布局 jp2.setLayout(new GridLayout(3, 3)); // 添加组件 jp1.add(jb1); jp1.add(jb2); jp1.add(jb3); jp2.add(jl2); jp2.add(jtf); jp2.add(jb4); jp2.add(jl3); // jp2.add(jpf); jp2.add(jl4); jp2.add(jcb1); jp2.add(jcb2); // jp2.add(jl5); this.add(jp1, BorderLayout.SOUTH); this.add(jl1, BorderLayout.NORTH); this.add(jtp, BorderLayout.CENTER); this.setSize(350, 400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }
4.记事本界面
前端知识留到后面干吧!!!