javax.swing组件的使用

package day5_0314;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class QQ extends JFrame{
    
    public QQ(){
        this.setLayout(null);//设置窗体为绝对布局
        
        //添加标签
        JLabel j = new JLabel("注册账号");
        j.setForeground(Color.blue);
        j.setFont(new Font("黑体",Font.ITALIC,20));
        j.setBounds(320,105,150,20);
        this.add(j);
        
        //添加标签
        JLabel jl = new JLabel("找回密码");
        jl.setForeground(Color.blue);//设置标签颜色
        jl.setFont(new Font("黑体",Font.ITALIC,20));//设置字体
        jl.setBounds(320,130,150,20);
        this.add(jl);
        
        //复选框
        JCheckBox check1 = new JCheckBox("记住密码");
        check1.setBounds(110, 150, 80, 20);
        this.add(check1);
        JCheckBox check2 = new JCheckBox("自动登录");
        check2.setBounds(210, 150, 80, 20);
        this.add(check2);
        
        //创建按钮
        JButton button = new JButton("多账号");
        button.setBounds(5,210,80,20);
        this.add(button);
        
        JButton button1 = new JButton("设置");
        button1.setBounds(100,210,80,20);
        this.add(button1);
        
        JButton button2 = new JButton("登录");
        button2.setBounds(400,210,80,20);
        this.add(button2);
        
        //创建文本框
        JTextField j1 = new JTextField("");
        j1.setBounds(110,130,200,20);
        this.add(j1);
        
        //创建下拉框
        JComboBox box = new JComboBox();
        box.addItem("1198470366");
        box.addItem("1234567890");
        box.addItem("300000000$");
        box.setBounds(110,105,200,20);
        this.add(box);
        

   //压缩图片,并设置图片边框       
        Image img = new ImageIcon("img/qq1.jpg").getImage();
        img = img.getScaledInstance(500,100, 1);
        JLabel j1Imag = new JLabel(new ImageIcon(img));
        j1Imag.setBounds(0,0,500,100);
        this.add(j1Imag);
        
        Image img1 = new ImageIcon("img/qq2.jpg").getImage();
        img1 = img1.getScaledInstance(100,100, 1);
        JLabel j1Imag1 = new JLabel(new ImageIcon(img1));
        j1Imag1.setBounds(5,105,100,100);
        this.add(j1Imag1);
        
        this.setSize(500,300);//设置窗体布局大小
        this.setVisible(true);//设置窗体可见
        this.setTitle("QQ2017");//设置窗体标题
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗体退出,程序运行结束
        this.setLocationRelativeTo(null);//设置窗体位置居中
        this.setResizable(true);//设置窗体大小国定
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        QQ q = new QQ();
    }
}


 

posted @ 2017-03-14 22:45  沉迷学习,日渐消瘦  阅读(791)  评论(0)    收藏  举报