第13章 Swing

Swing学习

package password;

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

/*class mj extends JDialog{
	public mj(Dengru h){
		super (h,"提示",true);
		Container c=getContentPane();
		c.add(new JLabel("登入成功"));
		setBounds(100,100, 200, 200);
	}
}弹出对话框*/
public class Dengru extends JFrame {
	public  Dengru(){
		Container cc=getContentPane();
		cc.setLayout(null);
		setTitle("登入界面");
		setSize(500, 400);
		setVisible(true);
		setDefaultCloseOperation(HIDE_ON_CLOSE);
		final JTextField jt1=new JTextField();
		final JTextField jt2=new JTextField();
		JButton jb1=new JButton("登入");
		JButton jb2=new JButton("重置");
		JLabel jl1=new JLabel("账号:");
		JLabel jl2=new JLabel("密码:");
		final JLabel jl3=new JLabel("账号或密码错误,请重新输入");
		cc.add(jt1);
		cc.add(jt2);
		cc.add(jb1);
		cc.add(jb2);
		cc.add(jl1);
		cc.add(jl2);
		cc.add(jl3);
		jl3.setVisible(false);
		jt1.setBounds(150, 70, 300, 50);
		jt2.setBounds(150, 170, 300, 50);
		jb1.setBounds(200, 280, 60, 40);
		jb2.setBounds(280, 280, 60, 40);
		jl1.setBounds(100, 80, 40, 50);
		jl2.setBounds(100, 180, 40, 50);
		jl3.setBounds(150, 240, 300, 30);
		final String nn="hhh";
		final String pp="123";
		jb1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (nn.equals(jt1.getText())&&pp.equals(jt2.getText())){
					
					JOptionPane.showMessageDialog(null, "登入成功");
				}
				else {
					jl3.setVisible(true);
				}
			}	
		});
		jb2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				jt1.setText("");
				jt2.setText("");	
				jl3.setVisible(false);
			}	
		});
		
		/*GridBagConstraints g1=new GridBagConstraints();
		g1.gridx=2;
		g1.gridy=1;
		g1.anchor=GridBagConstraints.SOUTH;
		cc.add(p1,g1);
		GridBagConstraints g2=new GridBagConstraints();
		g2.gridx=0;
		g2.gridy=1;
		g2.anchor=GridBagConstraints.SOUTH;
		cc.add(jt1,g2);
		GridBagConstraints g3=new GridBagConstraints();
		g3.gridx=1;
		g3.gridy=1;
		g3.anchor=GridBagConstraints.SOUTH;
		cc.add(jt2,g3);布局管理器不能精确控制 */
	}

	public  static void main(String[] args) {
		new Dengru();

	}
}

运行结果:
界面:
界面
登入错误提示
成功提示

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值