package javazuoye;
import javax.swing.*;
import java.awt.;
import java.awt.event.;
public class denglujiemian {
public static void main(String[] args) {
// TODO Auto-generated method stub
LoginDialog lo = new LoginDialog();
lo.setVisible(true);
}
}
public class MainWindow extends JFrame{
JLabel but1;
MainWindow(){
setTitle("系统登录");
setBounds(400,200,300,180);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// setLayout(null);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
but1 = new JLabel("登录成功!");
this.add(but1);
}
}
public class LoginDialog extends JDialog {
JLabel name;
JLabel a2;
JComboBox a3;
JPasswordField password;
JButton shi;
JButton fou;
LoginDialog(){
method1();
}
private void method1() {
// TODO Auto-generated method stub
setTitle("登录系统");
setBounds(500,250,220,140);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setLayout(null);
setModal(true);
// this.setResizable(false);
name = new JLabel("用户名:");
name.setBounds(20,10,50,20);
this.add(name);
a2 = new JLabel("密码:");
a2.setBounds(20,32,50,20);
this.add(a2);
a3 = new JComboBox();
a3.addItem("huakaihualuo");
a3.addItem("hellow");
a3.setBounds(75,10,105,20);
this.add(a3);
password = new JPasswordField("666666");
password.setBounds(75,33,105,20);
password.setEchoChar('*');
this.add(password);
shi = new JButton("登录");
shi.setBounds(25,60,60,20);
add(shi);
shi.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
login();
}
});
fou =new JButton("退出");
fou.setBounds(110,60,60,20);
add(fou);
fou.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
logout();
}
});
}
void login(){
String accout = a3.getSelectedItem().toString();
String pwd = new String(password.getPassword());
if(accout.equals("huakaihualuo")&&pwd.equals("666666")){
setVisible(false);
showMainWindow();
}else{
JOptionPane.showMessageDialog(this, "用户名是"+accout + ",密码是" + pwd);
}
}
void logout(){
int ret = JOptionPane.showConfirmDialog(this,"退出登录?","取消登录",JOptionPane.YES_NO_OPTION);
if(ret ==JOptionPane.YES_NO_OPTION){
dispose();
}
}
void showMainWindow(){
MainWindow frm = new MainWindow();
frm.setVisible(true);
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· .NET Core GC压缩(compact_phase)底层原理浅谈
· Winform-耗时操作导致界面渲染滞后
· Phi小模型开发教程:C#使用本地模型Phi视觉模型分析图像,实现图片分类、搜索等功能
· 语音处理 开源项目 EchoSharp