当前位置:首页 » 编程语言 » java用户登录

java用户登录

发布时间: 2022-01-19 18:35:44

java语言实现用户注册和登录

//这个是我写的,里面有连接数据库的部分。你可以拿去参考一下
import java.awt.*;
import javax.swing.*;

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

class LoginFrm extends JFrame implements ActionListener// throws Exception
{
JLabel lbl1 = new JLabel("用户名:");
JLabel lbl2 = new JLabel("密码:");
JTextField txt = new JTextField(5);
JPasswordField pf = new JPasswordField();
JButton btn1 = new JButton("确定");
JButton btn2 = new JButton("取消");

public LoginFrm() {
this.setTitle("登陆");
JPanel jp = (JPanel) this.getContentPane();
jp.setLayout(new GridLayout(3, 2, 5, 5));
jp.add(lbl1);
jp.add(txt);
jp.add(lbl2);
jp.add(pf);
jp.add(btn1);
jp.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
}

public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btn1) {
try {
Class.forName("com.mysql.jdbc.Driver");// mysql数据库
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/Car_zl", "root", "1");// 数据库名为Car_zl,密码为1
System.out.println("com : "+ con);
Statement cmd = con.createStatement();
String sql = "select * from user where User_ID='"
+ txt.getText() + "' and User_ps='"
+ pf.getText() + "'" ;
ResultSet rs = cmd
.executeQuery(sql);// 表名为user,user_ID和User_ps是存放用户名和密码的字段名

if (rs.next()) {
JOptionPane.showMessageDialog(null, "登陆成功!");
} else
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
} catch (Exception ex) {

}

if (ae.getSource() == btn2) {
System.out.println("1111111111111");
//txt.setText("");
//pf.setText("");
System.exit(0);
}
}
}

public static void main(String arg[]) {
JFrame.(true);
LoginFrm frm = new LoginFrm();
frm.setSize(400, 200);
frm.setVisible(true);
}
}

② 登录界面的java代码,分别有教师登录,管理员登录,学生登录,右边是用户名和密码,见图。

分三个包,自己建个包,导进去就ok了,数据库是access的。
package 登录;

import java.awt.EventQueue;

public class Cilent {

private JFrame frame;
private JTextField textField;
private JPasswordField passwordField;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Cilent window = new Cilent();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public Cilent() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("登陆界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);

JLabel lblNewLabel = new JLabel("用户名");
lblNewLabel.setBounds(38, 43, 80, 34);
frame.getContentPane().add(lblNewLabel);

textField = new JTextField();
textField.setBounds(155, 42, 227, 37);
frame.getContentPane().add(textField);
textField.setColumns(10);

JLabel label = new JLabel("密码");
label.setBounds(38, 115, 80, 34);
frame.getContentPane().add(label);

passwordField = new JPasswordField();
passwordField.setBounds(155, 115, 227, 37);
frame.getContentPane().add(passwordField);

JButton btnNewButton = new JButton("登录");
btnNewButton.setBounds(60, 187, 115, 34);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
UserCheck UC=new UserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));
if(UC.getI()!=0) //有此用户
{
frame.setVisible(false);
}
else
{
textField.setText("");
passwordField.setText("");
}
}
});

JButton button = new JButton("取消");
button.setBounds(242, 187, 115, 34);
frame.getContentPane().add(button);
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
textField.setText("");
passwordField.setText("");
}
});
}
}
/*****************************************************************/
package 登录;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import 操作处理.UsersCL;

/**@author 20111024
* 检测登录的用户在数据库中有无,若没有,则提示没有此用户,
* 若有,则判断级别:普通用户还是管理员。
*/
public class UserCheck {

private int i=0; //用户级别:0不是用户、1是管理员、2是普通用户
UserCheck(String name ,String password)
{
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
Statement stmt=null;
ResultSet rs=null;
Connection con=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
String query="select * from users where name='"+name+"' and passwd='"+password+"'";

rs=stmt.executeQuery(query);
if(rs.next())
{
//数据库中有此用户,访问成功
i=Integer.parseInt(rs.getString(3));
UsersCL UL=new UsersCL(i);
}
else
{
i=0; //没有用户是默认是0级
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public int getI() {
return i;
}
}
/********************************************************************************************/
package 操作处理;

import java.awt.EventQueue;

public class UsersCL implements ActionListener{

private JFrame frame;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private int i=0;
private JLabel label_3;
private JTextField textField_4;
public UsersCL(int i) {
this.i=i;
frame = new JFrame();
frame.setTitle("用户处理界面");
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setResizable(false);
frame.setVisible(true);

JLabel lblNewLabel = new JLabel("学号");
lblNewLabel.setBounds(24, 32, 74, 29);
frame.getContentPane().add(lblNewLabel);

JLabel label = new JLabel("姓名");
label.setBounds(24, 71, 74, 29);
frame.getContentPane().add(label);

JLabel label_1 = new JLabel("年龄");
label_1.setBounds(24, 110, 74, 29);
frame.getContentPane().add(label_1);

label_3 = new JLabel("性别");
label_3.setBounds(24, 149, 74, 29);
frame.getContentPane().add(label_3);

JLabel label_2 = new JLabel("状态");
label_2.setBounds(24, 195, 74, 29);
frame.getContentPane().add(label_2);

textField = new JTextField();
textField.setBounds(101, 34, 113, 25);
frame.getContentPane().add(textField);
textField.setColumns(10);

textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(101, 73, 113, 25);
frame.getContentPane().add(textField_1);

textField_2 = new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(101, 112, 113, 25);
frame.getContentPane().add(textField_2);

textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setColumns(10);
textField_3.setBounds(101, 199, 288, 25);
frame.getContentPane().add(textField_3);

textField_4 = new JTextField();
textField_4.setColumns(10);
textField_4.setBounds(101, 149, 113, 25);
frame.getContentPane().add(textField_4);

if(1==i)
{
JButton btnNewButton = new JButton("追加");
btnNewButton.setBounds(276, 41, 113, 29);
frame.getContentPane().add(btnNewButton);
btnNewButton.addActionListener(this);
btnNewButton.setActionCommand("追加");

JButton button_1 = new JButton("删除");
button_1.setBounds(276, 145, 113, 29);
frame.getContentPane().add(button_1);
button_1.addActionListener(this);
button_1.setActionCommand("删除");
}

JButton button = new JButton("查询");
button.setBounds(276, 91, 113, 29);
frame.getContentPane().add(button);
button.addActionListener(this);
button.setActionCommand("查询");
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String name,age,sex,query=null;
int num,age1,count=0;
num=Integer.parseInt(textField.getText());
name=textField_1.getText();
age1=Integer.parseInt(textField_2.getText());
sex=textField_4.getText();

if(e.getActionCommand().equals("追加"))
{
query="insert into students values("+num+","+"'"+name+"',"+age1+",'"+sex+"');";
count=1;
}
else if(e.getActionCommand().equals("查询"))
{
query="select * from students where XSB="+num+";";
count=2;
}
else if(e.getActionCommand().equals("删除"))
{
query="delete from students where XSB="+num+" and name="+"'"+name+"'";
count=3;
}

Statement stmt=null;
ResultSet rs=null;
Connection con=null;
String jdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String connectDB="jdbc:odbc:Students";
String query1=null;
try {
Class.forName(jdriver);
con=DriverManager.getConnection(connectDB);
stmt=con.createStatement();
if(count==1)
{
query1="select * from students where XSB="+num+";";
rs=stmt.executeQuery(query1);
if(rs.next())
textField_3.setText("已经由此记录,不能追加!");
else
{
stmt.executeUpdate(query);
textField_3.setText("已经追加完成!");
}
}
else if(2==count)
{
stmt.executeQuery(query);
rs=stmt.executeQuery(query);
if(rs.next())
{
textField_3.setText("已查找到此记录!");
}
else
{
textField_3.setText("没有此记录,可以追加!");
}
}
else if(3==count)
{
query1="select * from students where XSB="+num+" and name="+"'"+name+"'";
rs=stmt.executeQuery(query1);
if(rs.next())
{
stmt.executeUpdate(query);
textField_3.setText("已删除此记录!");
}
else
textField_3.setText("无此记录!");
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
//关闭资源
if(stmt!=null){
try {
stmt.close();
} catch (Exception e2) {
// TODO: handle exception
}
stmt=null;
}
if(con!=null){
try {
con.close();
} catch (Exception e2) {
// TODO: handle exception
}
con=null;
}
}
}
}

③ JAVA单用户登录怎么实现

我做过的一个项目是使用XML传输来实现的。首先客户端登录请求,服务器判断是否合法,合法就返回一个ticket码,客户端需要记录这个ticket码,服务器也需要将ticket记录到数据库里面,以后客户端的连接就通过ticket来判断识别是哪个用户。其实用XML做数据交换是肯定能实现的,只是麻烦的点,但是好处是对于C做的客户端照样通用。如果你只是需要简单的登录的话,也可以把XML交换换成HTTP请求,将用户名和密码放在请求报文的头里面。

④ JAVA 用户登录怎么写 如何给权限

其实最简单的方法就是使用角色和用户两级管理
首先建立角色:分为管理员和普通用户等,管理员用来管理系统的后台,而普通用户就是注册用户,可以实现浏览商品、管理个人信息等操作!
其次为用户分配角色,实现分配使用系统模块的权限。
角色权限的分配通过一张数据库权限表来实现。把系统的功能模块的使用权限设置为表的字段,然后为每个角色分配权限,1代表有权限,0代表无权限。可以设置一个辅助字段为是否登录,通过该字段判断用户是否可以修改个人信息。

⑤ 用java编程实现用户注册并进行登录操作

String username = "",password = "",passwordagain = ""; // 定义用户名和密码

将该变量等于为全局变量 或局部变量即可

⑥ java编写用户登录

代码发给你,如果什么都不懂的话,估计你也难以运行成功,而且图片也没有,要自己会改就能运行了。这些代码希望能帮到你!

数据库文件:

create database hotel_Flyer
go

use hotel_Flyer

create table userInfo(
id int primary key identity(1,1),
userName varchar(20),
password varchar(10),
realName nvarchar(20),
sex nvarchar(2),
age int,
favorite nvarchar(100),
telNum varchar(12),
email varchar(50),
address nvarchar(200)
)
go
insert into userInfo(userName,password) values('李连杰','123')
insert into userInfo(userName,password) values('成龙','123')
insert into userInfo(userName,password) values('甄子丹','123')
insert into userInfo(userName,password) values('赵文卓','123')
insert into userInfo(userName,password) values('吴京','123')
insert into userInfo(userName,password) values('周星驰','123')
insert into userInfo(userName,password) values('刘德华','123')

加载驱动类:

public class ConToSQL {
Connection con=null;
public Connection getConnection() throws Exception{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databaseName=hotel_Flyer", "sa", "sa");
return con;
}

}

连接数据库类:

public class DengluUC {
Connection con=null;
PreparedStatement stm=null;
ResultSet rs=null;

public boolean checkUser(String user,String pwd){
boolean tof=false;
try {

ConToSQL cts=new ConToSQL();
con=cts.getConnection();
stm=con.prepareStatement("select password from userInfo where userName=?");
stm.setString(1, user);
rs=stm.executeQuery();
if(rs.next()){
if(rs.getString(1).equals(pwd)){
tof= true;
}
}

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} /*finally{
try {
rs.close();
stm.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
return tof;
}*/
return tof;
}
}

登录类代码:

package com.hbsoft.hotel_Flyer.login;
import com.hbsoft.hotel_Flyer.usermanagerForm.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Rectangle;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.text.html.Option;

import com.hbsoft.hotel_Flyer.proc.Process;

import java.awt.Point;
import java.sql.*;

import com.hbsoft.hotel_Flyer.database.*;

public class Denglu {

private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="61,26"
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JComboBox jComboBox = null;
private JLabel jL4 = null;
private JLabel jLabel1 = null;
private JPasswordField jPasswordField = null;
private JButton jB1 = null;
private JButton jB2 = null;
private JComboBox jComboBox1 = null;
private JLabel jLabel = null;
private JLabel jLabel2 = null;
private Connection con=null; // @jve:decl-index=0:
private Statement sts=null;
private ResultSet rs=null;
private DatabaseMetaData dmd=null;
private int rowCount=0;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
public JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame("系统登陆");
jFrame.setSize(new Dimension(854, 539));
jFrame.setLocation(new Point(100, 100));
jFrame.setContentPane(getJContentPane());
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setResizable(false);
}
return jFrame;
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(3, 4, 845, 503));
jLabel2.setIcon(new ImageIcon("E:/java\uff088\uff09\u73ed\u5468\u67ab/\u7b2c\u5341\u7ec4\u5de5\u4f5c\u7ad9/hotel_Flyer/\u767b\u5f55\u80cc\u666f.jpg"));
jLabel2.setText("");
jLabel = new JLabel();
jLabel.setText("");
jLabel.setIcon(new ImageIcon(getClass().getResource("/com/hbsoft/hotel_Flyer/img/\u767b\u5f55\u80cc\u666f.jpg")));
jLabel.setBounds(new Rectangle(-1, 1, 851, 509));
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(438, 141, 363, 231));
jLabel1.setText("");
jL4 = new JLabel();
jL4.setBounds(new Rectangle(484, 341, 289, 28));
jL4.setHorizontalAlignment(SwingConstants.CENTER);
Timer t =new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e) {
Date d=new Date();
SimpleDateFormat df = new SimpleDateFormat("yy-MM-dd hh:mm:ss");
jL4.setText(df.format(d));
}
});
t.start();
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.setBorder(BorderFactory.createLineBorder(Color.cyan, 2));
jContentPane.setFont(new Font("\u96b6\u4e66", Font.PLAIN, 14));
jContentPane.add(getJPanel(), null);
jContentPane.add(jL4, null);
jContentPane.add(jLabel1, null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJB1(), null);
jContentPane.add(getJB2(), null);
jContentPane.add(getJComboBox1(), null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel, null);
}
return jContentPane;
}

/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jPanel.setBounds(new Rectangle(0, 0, 415, 0));
}
return jPanel;
}
/**
* This method initializes jB1
*
* @return javax.swing.JButton
*/
void ThisDispose(){
this.getJFrame().dispose();
}
/**
* This method initializes jPasswordField
*
* @return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(570, 263, 201, 29));
}
return jPasswordField;
}

/**
* This method initializes jB1
*
* @return javax.swing.JButton
*/
/*void ThisdDispose(){
this.getJFrame().dispose();
}*/
private JButton getJB1() {
if (jB1 == null) {
jB1 = new JButton();
jB1.setBounds(new Rectangle(489, 313, 103, 35));
jB1.setText("登陆");
jB1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(new DengluUC().checkUser(jComboBox1.getSelectedItem().toString(), new String(jPasswordField.getPassword()))){
//message.setText("登录成功");
//message.setForeground(new Color(255,0,0));
new Process((String)jComboBox1.getSelectedItem()).setVisible(true);
ThisDispose();

}else{
if(new String(jPasswordField.getPassword()).length()==0){
JOptionPane.showMessageDialog(null, "密码不能为空");
}else{
JOptionPane.showMessageDialog(null, "密码不正确,请重新输入");
}
}

}
});
}
return jB1;
}

/**
* This method initializes jB2
*
* @return javax.swing.JButton
*/
private JButton getJB2() {
if (jB2 == null) {
jB2 = new JButton();
jB2.setBounds(new Rectangle(642, 312, 103, 35));
jB2.setText("退出");
jB2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
}
return jB2;
}

/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
public void getResultSet(){
try{
con=new ConToSQL().getConnection();
sts=con.createStatement();
rs=sts.executeQuery("select * from userInfo");

}catch(Exception e){
e.printStackTrace();
}

}
public int getRowCount(){
try {
rs.last();
if (rs.isLast()) {
rowCount = rs.getRow();
}
} catch (Exception e) {
e.printStackTrace();
}
return rowCount;
}
public void closeData(){
try{
rs.close();
sts.close();
con.close();
}catch(SQLException e){
e.printStackTrace();
}
}
private JComboBox getJComboBox1() {
getResultSet();
String [] arr=new String[7];
int i=0;
try {
while (rs.next()) {
if(i<arr.length){
arr[i] = rs.getString(2);
i++;}
}
} catch (Exception e) {
e.printStackTrace();
}
if (jComboBox1 == null) {
jComboBox1 = new JComboBox(arr);
closeData();
jComboBox1.setBounds(new Rectangle(569, 218, 201, 29));
}
return jComboBox1;
}

public static void main(String [] args) throws Exception{
// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
new Denglu().getJFrame().setVisible(true);
}

}

⑦ java用户登录的时候为什么不用用户名和密码直接点登录就可以登录上去,是哪里的原因

/*
*以下是我曾经做项目时候做的登录,是从数据库提取登录名和密码的.具有广泛意义;如按楼主自己定义密码等,就更容易了。
p.s:因为时间忙,我就不另写程序了希望对你有用。
*/
packagecom.youngmaster.view;

importjava.awt.*;
importjava.awt.event.*;
importjava.sql.*;

importjavax.swing.*;
importjavax.swing.border.*;

importcom.youngmaster.jdbc.*;
importjava.awt.Dimension;
importjava.awt.Rectangle;
importjava.awt.Font;
importjavax.swing.DebugGraphics;
importjavax.swing.text.html.ImageView;
importjavax.swing.BorderFactory;
importjava.awt.Color;

/**
*<p>Title:企业绩效管理系统</p>
*
*<p>Description:</p>
*
*<p>Copyright:Copyright(c)2009</p>
*
*<p>Company:</p>
*
*@authoryoungmaster
*@version1.0
*/
{
JPanelcontentPane;
JLabeljLabel1=newJLabel();
JLabeljLabel2=newJLabel();
JLabeljLabel3=newJLabel();
JButtonjButton1=newJButton();
JButtonjButton2=newJButton();
JTextFieldtxtName=newJTextField();
JLabeljLabel5=newJLabel();
JPasswordFieldtxtPsw=newJPasswordField();
TitledBordertitledBorder1=newTitledBorder("");
JComboBoxjComboBox1=newJComboBox();
JPaneljPanel1=newJPanel();
ImageIconimage=newImageIcon("image/building.gif");
JButtonbtnImage=newJButton();
TitledBordertitledBorder2=newTitledBorder("");
publicFrLogin(){
try{
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}catch(Exceptionexception){
exception.printStackTrace();
}
}

/**
*Componentinitialization.
*
*@throwsjava.lang.Exception
*/
privatevoidjbInit()throwsException{
contentPane=(JPanel)getContentPane();
contentPane.setLayout(null);
setSize(newDimension(443,327));
setTitle("FrameTitle");
jLabel1.setFont(newjava.awt.Font("楷体_GB2312",Font.BOLD,20));
jLabel1.setText("企业绩效管理系统");
jLabel1.setBounds(newRectangle(126,28,168,24));
jLabel2.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,16));
jLabel2.setText("用户名:");
jLabel2.setBounds(newRectangle(75,124,59,24));
jLabel3.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,16));
jLabel3.setText("密码:");
jLabel3.setBounds(newRectangle(75,173,59,24));
jButton1.setBounds(newRectangle(99,218,80,28));
jButton1.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,14));
jButton1.setText("登录");
jButton1.addActionListener(newFrLogin_jButton1_actionAdapter(this));
jButton2.setBounds(newRectangle(221,217,83,29));
jButton2.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,14));
jButton2.setText("取消");
jButton2.addActionListener(newFrLogin_jButton2_actionAdapter(this));
txtName.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,14));
txtName.setBounds(newRectangle(146,120,102,23));
txtName.addActionListener(newFrLogin_txtName_actionAdapter(this));
jLabel5.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,16));
jLabel5.setText("等级:");
jLabel5.setBounds(newRectangle(75,74,59,24));
txtPsw.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,14));
txtPsw.setBounds(newRectangle(146,168,102,23));
txtPsw.addActionListener(newFrLogin_txtPsw_actionAdapter(this));
contentPane.setBorder(titledBorder1);
contentPane.setDebugGraphicsOptions(0);
contentPane.setNextFocusableComponent(jComboBox1);
contentPane.setToolTipText("企业绩效管理系统");
jPanel1.setNextFocusableComponent(jComboBox1);
jPanel1.setToolTipText("企业绩效管理系统");
jPanel1.setBounds(newRectangle(1,0,441,330));
jPanel1.setLayout(null);
jComboBox1.setFont(newjava.awt.Font("楷体_GB2312",Font.PLAIN,14));
jComboBox1.setBounds(newRectangle(146,72,102,23));
jComboBox1.addActionListener(newFrLogin_jComboBox1_actionAdapter(this));
btnImage.setBounds(newRectangle(271,55,120,160));
btnImage.setBorder(titledBorder2);
jPanel1.add(jLabel1);
jPanel1.add(jLabel5);
jPanel1.add(jLabel2);
jPanel1.add(jLabel3);
jPanel1.add(txtName);
jPanel1.add(jComboBox1);
jPanel1.add(txtPsw);
jPanel1.add(jButton2);
jPanel1.add(jButton1);
jPanel1.add(btnImage);
contentPane.add(jPanel1);
jComboBox1.addItem(1);
jComboBox1.addItem(2);
btnImage.setIcon(image);

this.setTitle("登录");
}

publicvoidjButton2_actionPerformed(ActionEvente){
System.exit(0);
}

publicvoidjButton1_actionPerformed(ActionEvente){
//栏位判断
if(txtName.getText().equals("")||txtPsw.getText().equals("")){

javax.swing.JOptionPane.showMessageDialog(this,"登录信息错误!请重新输入。");
txtName.setText("");
txtPsw.setText("");
}else{
booleansuccess=false;
intgrade;
Stringname="";
Stringpsw="";
JdbcUtilsdbc=JdbcUtils.getInstance();
ResultSetrs=dbc.executeQuery("SELECT*FROMuser");
//查询帐号和密码是否匹配
try{
while(rs.next()){
grade=rs.getInt("grade");
name=rs.getString("name");
psw=rs.getString("password");
if(txtName.getText().equals(name)&&
txtPsw.getText().equals(psw)&&
((jComboBox1.getSelectedIndex()+1)==grade)){
//当时出现问题地方
//Integer.parseInt(jComboBox1.getSelectedItem()
success=true;
break;
}
}
//若匹配则登陆成功并进入主界面
if(success){
FrMainufram=newFrMain();
this.setVisible(false);
DimensionscreenSize=Toolkit.getDefaultToolkit().
getScreenSize();
DimensionframeSize=ufram.getSize();
if(frameSize.height>screenSize.height){
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
ufram.setLocation((screenSize.width-frameSize.width)/
2,
(screenSize.height-frameSize.height)/
2);
ufram.setVisible(true);
}else{
javax.swing.JOptionPane.showMessageDialog(this,
"管理员名或密码错误!请重新输入。");
txtName.setText("");
txtPsw.setText("");
txtName.setFocusable(true);
}

}catch(SQLExceptionex){
javax.swing.JOptionPane.showMessageDialog(this,
ex.getMessage().toString());
return;
}
}

}

publicvoidtxtName_actionPerformed(ActionEvente){

}

publicvoidjComboBox1_actionPerformed(ActionEvente){

}

publicvoidtxtPsw_actionPerformed(ActionEvente){

}
}

classFrLogin_txtPsw_{
privateFrLoginadaptee;
FrLogin_txtPsw_actionAdapter(FrLoginadaptee){
this.adaptee=adaptee;
}

publicvoidactionPerformed(ActionEvente){
adaptee.txtPsw_actionPerformed(e);
}
}

classFrLogin_jComboBox1_{
privateFrLoginadaptee;
FrLogin_jComboBox1_actionAdapter(FrLoginadaptee){
this.adaptee=adaptee;
}

publicvoidactionPerformed(ActionEvente){
adaptee.jComboBox1_actionPerformed(e);
}
}

classFrLogin_txtName_{
privateFrLoginadaptee;
FrLogin_txtName_actionAdapter(FrLoginadaptee){
this.adaptee=adaptee;
}

publicvoidactionPerformed(ActionEvente){
adaptee.txtName_actionPerformed(e);
}
}

classFrLogin_jButton1_{
privateFrLoginadaptee;
FrLogin_jButton1_actionAdapter(FrLoginadaptee){
this.adaptee=adaptee;
}

publicvoidactionPerformed(ActionEvente){
adaptee.jButton1_actionPerformed(e);
}
}

classFrLogin_jButton2_{
privateFrLoginadaptee;
FrLogin_jButton2_actionAdapter(FrLoginadaptee){
this.adaptee=adaptee;
}

publicvoidactionPerformed(ActionEvente){
adaptee.jButton2_actionPerformed(e);
}
}

热点内容
小说缓存网 发布:2024-12-31 02:55:29 浏览:921
安卓手机上的短信放在哪个文件 发布:2024-12-31 02:55:19 浏览:541
乐视1s什么配置 发布:2024-12-31 02:48:55 浏览:225
python等待线程结束 发布:2024-12-31 02:41:58 浏览:401
沈阳php网站 发布:2024-12-31 02:41:58 浏览:958
烤冷面存储 发布:2024-12-31 02:39:56 浏览:494
android引用资源文件 发布:2024-12-31 02:27:37 浏览:36
html删除缓存 发布:2024-12-31 02:11:32 浏览:835
全球现有存储空间价值 发布:2024-12-31 02:01:12 浏览:982
服务器内存4drx4是什么意思 发布:2024-12-31 01:56:44 浏览:837