Java登录界面简单设计
package cn.com.view; import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent; import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JTextField; import sun.awt.HorizBagLayout; import cn.com.beans.UserInfoBean;
import cn.com.beans.UserInfoViewBean;
import cn.com.daos.UserInfoDAO;
import cn.com.listeners.LoginFrame_btnLogin_ActionListener;
import cn.com.listeners.LoginFrame_btnReset_ActionListener;
import cn.com.listeners.LoginFrame_lblRegist_MouseListener; public class LoginFrame extends JFrame {
JPanel pnlMain;
JButton btnLogin;
JButton btnReset;
JLabel lblUserName;
JLabel lblUserPwd;
JLabel lblTitle;
JLabel lblRegist;
JTextField txtUserName;
JPasswordField pwdUserPwd;
JProgressBar progressBar;
JLabel lblLoginStat; public LoginFrame() {
pnlMain = new JPanel(null);
btnLogin = new JButton("登录");
btnReset = new JButton("重置");
lblUserName = new JLabel("用户名:");
lblUserPwd = new JLabel("密 码:");
lblTitle = new JLabel("用户登录");
lblRegist = new JLabel("注册");
txtUserName = new JTextField();
pwdUserPwd = new JPasswordField();
progressBar = new JProgressBar();
progressBar.setIndeterminate(false);
progressBar.setOrientation(JProgressBar.HORIZONTAL);
progressBar.setForeground(new Color(0, 255, 0));
progressBar.setBounds(286, 348, 146, 14);
init();
} private void init() {
// TODO Auto-generated method stub
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setIconImage(Toolkit.getDefaultToolkit().getImage("image\\e.jpg"));
this.setBounds(100, 100, 559, 351);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.getContentPane().setLayout(null);
getContentPane().setBackground(new Color(255, 255, 255)); JLabel label = new JLabel("人事管理系统用户登录");
label.setFont(new Font("楷体", Font.PLAIN, 40));
label.setBackground(Color.WHITE);
label.setBounds(79, 10, 400, 43);
this.getContentPane().add(label); JLabel lblNewLabel = new JLabel("图片");
lblNewLabel.setBounds(10, 63, 250, 250);
this.getContentPane().add(lblNewLabel);
lblNewLabel.setIcon(new ImageIcon("D:\\Workspaces\\PMSys\\image\\login.jpg")); JLabel lblUserName = new JLabel("用户名:");
lblUserName.setFont(new Font("华文楷体", Font.BOLD, 15));
lblUserName.setBounds(270, 100, 65, 28);
this.getContentPane().add(lblUserName); JLabel lblUserPwd = new JLabel("密 码:");
lblUserPwd.setFont(new Font("华文楷体", Font.BOLD, 15));
lblUserPwd.setBounds(270, 163, 65, 25);
this.getContentPane().add(lblUserPwd); txtUserName = new JTextField();
txtUserName.setText("请输入用户名");
txtUserName.setBounds(345, 97, 173, 31);
txtUserName.setBackground(new Color(255, 255, 204));
this.getContentPane().add(txtUserName);
txtUserName.setColumns(10); pwdUserPwd = new JPasswordField();
pwdUserPwd.setFont(new Font("宋体", Font.BOLD, 20));
pwdUserPwd.setBounds(345, 160, 173, 28);
pwdUserPwd.setBackground(new Color(255, 255, 204));
this.getContentPane().add(pwdUserPwd); JButton btnLogin = new JButton("登录"); btnLogin.setBounds(272, 217, 93, 43);
this.getContentPane().add(btnLogin); JButton btnReset = new JButton("重置"); btnReset.setBounds(427, 217, 93, 43);
this.getContentPane().add(btnReset); lblLoginStat = new JLabel("登录中>>>>");
lblLoginStat.setForeground(Color.RED);
lblLoginStat.setFont(new Font("华文楷体", Font.BOLD, 15));
lblLoginStat.setBounds(270,270,246,14);
this.getContentPane().add(lblLoginStat);
lblLoginStat.setVisible(false); progressBar.setBounds(272,284,246,14);
progressBar.setIndeterminate(true);
progressBar.setVisible(false);
this.getContentPane().add(progressBar);
this.setVisible(true); //添加监听事件
btnLogin.addActionListener(new LoginFrame_btnLogin_ActionListener(this));
btnReset.addActionListener(new LoginFrame_btnReset_ActionListener(this));
lblRegist.addMouseListener(new LoginFrame_lblRegist_MouseListener(this));
} public void btnLogin_actionPerformed(ActionEvent e){
// TODO Auto-generated method stub progressBar.setVisible(true);
lblLoginStat.setVisible(true);
UserInfoDAO dao = new UserInfoDAO();
String userName = this.txtUserName.getText();
String userPwd = new String(this.pwdUserPwd.getPassword());
if(dao.validateByNameAndPwd(userName, userPwd)) {
UserInfoViewBean ab = dao.getUserListInfoByUserName(userName);
new MainFrame(ab);
this.dispose();
}else {
// JOptionPane.showMessageDialog(null, "用户名或密码错误","错误",JOptionPane.ERROR_MESSAGE);
int n = JOptionPane.showConfirmDialog(null, "密码错误,是否重新登录?", "提示",JOptionPane.YES_NO_OPTION);
if(n == 0){
//progressBar.setIndeterminate(false);
progressBar.setVisible(false);
lblLoginStat.setVisible(false);
}else{
System.exit(0);
} }
}
//重置监听事件
public void btnReset_actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.txtUserName.setText("");
this.pwdUserPwd.setText("");
} public void lblRegist_mouseClicked(MouseEvent e) {
} }
Java登录界面简单设计的更多相关文章
- Java消息系统简单设计与实现
前言:由于导师在我的毕设项目里加了消息系统(本来想水水就过的..),没办法...来稍微研究研究吧..简单简单... 需求分析 我的毕设是一个博客系统,类似于简书这样的,所以消息系统也类似,在用户的消息 ...
- Java登录界面的实现(注册、登录、背景图片)
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.java * 作者:常轩 * 微信公众号:Worldh ...
- java联系人管理系统简单设计
本文实例为大家分享了java联系人管理系统毕业设计,供大家参考,具体内容如下 要求: 请使用XML保存数据,完成一个联系人管理系统. 用户必须经过认证登录后方可以使用系统. 注册 ...
- winform基本控件的使用2(用户登录界面的设计)
首先还是通过例子来讲解,这次的实验主要是使用messageBox的使用方法,关于messageBox的使用方法在我的博客里面有相关的转载,请自己查看,下面说一下实验要求. 功能要求:模拟一个用户登陆的 ...
- 关于java登录界面
import java.awt.*; 包含用于创建用户界面和绘制图形图像的所有类. import javax.swing.*; 提供一组“轻量级”(全部是 Java 语言)组件,尽量让这些组件在所 ...
- Java图形界面开发—简易登录注册小程序
登录注册小代码,将学过的一些小知识融合在一起进行了使用,加深印象.本例中如果有注释不详细的地方,详见其它博客. Java程序操作数据库SQLserver详解 功能介绍:简单的登录注册系统,使用了数据库 ...
- Qt常用的登录界面设计
记录一下Qt常用的登录界面的设计 方便以后使用! 1.QpushButton改变一个按钮的颜色,当鼠标放上去和移开时显示不同的颜色.QPushButton { background-color: rg ...
- 以java实现的一个简单登录界面(带验证码)
本文参考于:https://blog.csdn.net/wyf2017/article/details/78831744 https://blog.csdn.net/MengKun822/articl ...
- JAVA web简单的登录界面jsp实现
此次试验所用到的软件是myeclipse10,tomcat7,Dreamweaver,sqlserver2008数据库.可以实现用户使用用户名和密码登录.如果登录成功,页面会显示登录成功,如果密码错误 ...
随机推荐
- Deutsch lernen (15)
1. unterscheiden - unterschied - unterschieden 区别,区分:(能够)分清 Die beiden Begriffe sind nur schwer ...
- pyqt5 做的小程序,可以用来UI做个小demo
#!/usr/bin/python3# -*- coding: utf-8 -*- """ZetCode PyQt5 tutorial This program crea ...
- Java 8 函数接口详细教程
ay = new byte[array.length]; for (int i = 0; i < array.length; i++) { transformedArray[i] = funct ...
- 【转载】Jmeter分布式部署测试-----远程连接多台电脑做压力性能测试
在使用Jmeter进行接口的性能测试时,由于Jmeter 是JAVA应用,对于CPU和内存的消耗比较大,所以,当需要模拟数以万计的并发用户时,使用单台机器模拟所有的并发用户就有些力不从心,甚至会引起J ...
- 连接mysql时遇到的问题
1.报错:The server time zone value '???ú±ê×??±??' is unrecognized or represents 解决方法:在jdbc连接的url后面加上ser ...
- PAT_A1122#Hamiltonian Cycle
Source: PAT A1122 Hamiltonian Cycle (25 分) Description: The "Hamilton cycle problem" is to ...
- Selenium3+python自动化 -JS处理滚动条
selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 常见场景: 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的. 这时候需要借 ...
- http://www.phplo.com/special/2013/0616/467.html
http://www.phplo.com/special/2013/0616/467.html
- 编码的由来,ASCII编码,和字节的形成
一.编码的由来 计算机只能计算和识别二进制,必须让计算机识别文字,才能和计算机进行交互,彼此也才能通过计算机通信. 由此,有了ASCII编码的诞生,它起始于50年代后期,在1967年定案,是最初美国国 ...
- firebird的日期型字段
fb一大特色,日期型字段.dialect3时,对date time datetime是分的很清楚的.它们之间,你必须手把格式设定好,否则会报错.而不是你想象的会自动化:表xxx的date字段yyy,i ...