JAVA图形化界面设计,登录框

eclipse软件编写

package swing;

import javax.swing.;
import java.awt.
;
import java.awt.event.*;

public class Login {
JFrame f=new JFrame(“login”);
JTextField t1=new JTextField(15);
JPasswordField p=new JPasswordField(15);
JButton b1=new JButton(“submit”);
JButton b2=new JButton(“cancel”);

public static void main(String[] args) {
	new Login().launch();
	
}
public void launch() {
	f.setSize(350,200);
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	f.setLocationRelativeTo(null);
	
	f.setLayout(new GridLayout(0,2));
	JPanel p1=new JPanel();
	p1.add(new JLabel("username"));
	JPanel p2=new JPanel();
	p2.add(t1);
	
	JPanel p3=new JPanel();
	p3.add(new JLabel("password"));
	JPanel p4=new JPanel();
	p4.add(p);
	
	JPanel p5=new JPanel();
	p5.add(b1);
	JPanel p6=new JPanel();
	p6.add(b2);
	
	
	b1.addActionListener(submit);
	b2.addActionListener(cancel);
	
	
	
	f.add(p1);
	f.add(p2);
	f.add(p3);
	f.add(p4);
	f.add(p5);
	f.add(p6);
	f.setVisible(true);;
}
ActionListener submit=new ActionListener() {
	@Override
	public void actionPerformed(ActionEvent e) {
		String sname=t1.getText();
		String pword=new String(p.getPassword());
		sname=sname.trim();
		pword=pword.trim();
		if(sname.equals("")||pword.equals("")) {
			JOptionPane.showMessageDialog(f,"please enter your message");	
		}else if(sname.equals("liuna")&&pword.equals("928")) {
		
			f.dispose();
		}else {
			JOptionPane.showMessageDialog(f,"your message is wrong");	
		}
	}	
};
ActionListener cancel=new ActionListener() {
	@Override
	public void actionPerformed(ActionEvent e) {
		t1.setText("");
	    p.setText("");
	}
};

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值