Java_Swing程序设计_尝试开发一个登陆窗体,包括用户名、密码以及提交按钮和重置按钮,当用户输入用户名my,密码love时,弹出登陆成功提示对话框。...

package com.lzw;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class UseCase3 extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;

public UseCase3(){
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setTitle("登录窗体");
setBounds(300, 200, 300, 150);
Container cp=getContentPane();
cp.setLayout(null);
JLabel jl=new JLabel("用户名:");
jl.setBounds(10, 10, 200, 18);
final JTextField name=new JTextField();
name.setBounds(80, 10, 150, 18);
JLabel jl2=new JLabel("密码:");
jl2.setBounds(10, 50, 200, 18);
final JPasswordField password=new JPasswordField();
password.setBounds(80, 50, 150, 18);
cp.add(jl);
cp.add(name);
cp.add(jl2);
cp.add(password);
JButton jb=new JButton("确定");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(name.getText().trim().length()==0||new String(password.getPassword()).trim().length()==0){
JOptionPane.showMessageDialog(null, "用户名密码不允许为空");
return;
}
if(name.getText().trim().equals("my")&&new String(password.getPassword()).trim().equals("love")){
JOptionPane.showMessageDialog(null, "登录成功");
}
else{
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
}
});
jb.setBounds(80, 80, 60, 18);
cp.add(jb);

final JButton button = new JButton();
button.setText("重置");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
name.setText("");
password.setText("");
}
});
button.setBounds(150, 80, 60, 18);
getContentPane().add(button);
}

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

}

}

 

转载于:https://www.cnblogs.com/bby2014210552/p/5942745.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值