首页 > 其他 > 详细

GUI编程实战

时间:2019-04-18 15:18:31      阅读:120      评论:0      收藏:0      [点我收藏+]

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);
    }

}
View Code

 

 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);
    }

}
View Code

 

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);
    }
}
View Code

 4.记事本界面

 

前端知识留到后面干吧!!!

 

GUI编程实战

原文:https://www.cnblogs.com/helloworld2019/p/10722966.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!