GUI学习

通过运用复选框(JCheckBox)与组合框(JComboBox)来做出一个登录界面,实现了一部分简单的功能。

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;

public class GUI {

	public static void main(String[] args) {
		final JFrame frm = new JFrame();
		frm.setBounds(630, 250, 450, 500);
		JLabel lb1 = new JLabel("用户名:");
		lb1.setBounds(72, 105, 63, 26);
		JComboBox name = new JComboBox();
		name.setBounds(187, 107, 177, 23);
		name.addItem("1");
		name.addItem("2");
		JLabel lb2 = new JLabel("密码:"); 
		lb2.setBounds(72, 141, 63, 26);
		JPasswordField pwd = new JPasswordField();
		pwd.setBounds(187, 144, 177, 23);
		JCheckBox ch1 = new JCheckBox("记住密码");
		ch1.setBounds(180, 180,80, 25);
		ch1.setSelected(true);
		frm.add(ch1);
		JCheckBox ch2 = new JCheckBox("自动登录");
		ch2.setBounds(290, 180, 80, 25);
		frm.add(ch2);
		JButton btn1 = new JButton("登录");
		btn1.setBounds(100, 230, 80, 25);
		frm.add(btn1);
		JButton btn2 = new JButton("退出");
		frm.add(btn2);
		btn2.setBounds(250, 230, 80, 25);
		btn2.addActionListener(new ActionListener(){
		

			
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				frm.setVisible(false);
			}
		});
		frm.add(lb1);
		frm.add(lb2);
		frm.add(name);
		frm.add(pwd);
		frm.setLayout(null);
		frm.setVisible(true);
		
	}

}

  

posted @ 2016-03-18 20:06  大橙子桑  阅读(269)  评论(1编辑  收藏  举报