當前位置:首頁 » 編程語言 » 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);
}
}

熱點內容
管理java版本 發布:2024-11-15 11:44:03 瀏覽:629
ndk編譯的程序如何執行 發布:2024-11-15 11:43:18 瀏覽:626
輕應用伺服器適合搭建網站嗎 發布:2024-11-15 11:36:08 瀏覽:246
c語言的百分號 發布:2024-11-15 11:34:24 瀏覽:31
一加五安卓8什麼時候推送 發布:2024-11-15 11:19:40 瀏覽:854
暗影騎士擎有哪些配置 發布:2024-11-15 11:13:46 瀏覽:598
方舟主機專用伺服器是什麼意思 發布:2024-11-15 11:12:23 瀏覽:8
創維最早的伺服器是什麼 發布:2024-11-15 11:11:35 瀏覽:864
手機配置太低怎麼下載原聲 發布:2024-11-15 11:03:31 瀏覽:905
21款奧迪a6配置有哪些 發布:2024-11-15 11:03:20 瀏覽:120