導航:首頁 > 編程語言 > java登錄

java登錄

發布時間:2022-02-01 00:14:27

A. 用java實現一個登錄頁面 可以用什麼方法

那應該用jsp頁面里寫一個表單,主要包括用戶名、密碼等欄位,然後再寫一個提交和重置按鈕,採用post或者get方式把表單數據提交到後台進行處理,比如說通過java的jdbc訪問資料庫,判斷輸入表單的數據是否是已經存在的合法用戶,如果是就跳轉到系統主頁面,如果不是就顯示提示錯誤信息。

B. 用Java編寫注冊登錄程序

什麼都不說了 直接給你代碼吧
package com.moliying.ui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
private JFrame frame = new JFrame("登錄");
private Container c = frame.getContentPane();
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JButton ok = new JButton("確定");
private JButton cancel = new JButton("取消");
public Login() {
frame.setSize(300, 200);
frame.setBounds(450, 300, 300, 200);
c.setLayout(new BorderLayout());
initFrame();
frame.setVisible(true);
}
private void initFrame() {
// 頂部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("系統管理員登錄"));
c.add(titlePanel, "North");
// 中部表單
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel a1 = new JLabel("用戶名:");
a1.setBounds(50, 20, 50, 20);
JLabel a2 = new JLabel("密 碼:");
a2.setBounds(50, 60, 50, 20);
fieldPanel.add(a1);
fieldPanel.add(a2);
username.setBounds(110, 20, 120, 20);
password.setBounds(110, 60, 120, 20);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel, "Center");
// 底部按鈕
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(ok);
buttonPanel.add(cancel);
c.add(buttonPanel, "South");

ok.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
System.out.println(username.getText().toString());
}
});

cancel.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
}
});
}
public static void main(String[] args) {
// new Login();

String ss = "abbabbbaabbbccba";

System.out.println(ss.split("b").length);

}
}

C. 用java編程實現用戶注冊並進行登錄操作

String username = "",password = "",passwordagain = ""; // 定義用戶名和密碼

將該變數等於為全局變數 或局部變數即可

D. java注冊登錄

不清楚LZ的意思,不連接資料庫么?

E. Java中登陸時如何實現的

如果時java web開發的話,那就是跟資料庫掛鉤了。用戶輸入用戶名和密碼,然後後台程序和資料庫保存的用戶名和密碼進行比較,如果成功,就進入允許的界面,如果不成功,重新回到登錄界面,或者返回網站首頁。
希望能幫到你!!!

F. java怎樣實現登錄驗證

G. 用JAVA編寫一個登陸系統。

第一個java文件LogoingDemo.java

importjava.util.Scanner;

publicclassLogoingDemo{
publicstaticvoidmain(String[]args){
System.out.println("請輸入用戶名");
Scannersc=newScanner(System.in);
Stringname=sc.nextLine();
System.out.println("請輸入密碼");
Stringpsw=sc.nextLine();
sc.close();
CheckDemocd=newCheckDemo(name,psw);//用戶名和密碼傳入驗證類
booleanbo=cd.check();//調用方法進行驗證
if(bo){
System.out.println("登錄成功");
}else{
System.out.println("登錄失敗:提示用戶名admin密碼123");
}
}
}

第二個java文件CheckDemo.java

publicclassCheckDemo{
publicStringname;
publicStringpsw;
publicCheckDemo(Stringname,Stringpsw){//構造器
this.name=name;
this.psw=psw;
}
publicbooleancheck(){
//用戶名密碼不能為空.用戶名=admin密碼=123
if(name!=null&&psw!=null&&name.equals("admin")&&psw.equals("123")){
returntrue;
}
returnfalse;
}
}

效果


請輸入用戶名
admin
請輸入密碼
123
登錄成功
------------------------------------
請輸入用戶名
add
請輸入密碼
123
登錄失敗:提示用戶名admin密碼123

H. java實現簡單登錄界面

自己寫的比較規范的代碼,都有注釋:

import javax.swing.JFrame;//框架
import javax.swing.JPanel;//面板
import javax.swing.JButton;//按鈕
import javax.swing.JLabel;//標簽
import javax.swing.JTextField;//文本框
import java.awt.Font;//字體
import java.awt.Color;//顏色
import javax.swing.JPasswordField;//密碼框
import java.awt.event.ActionListener;//事件監聽
import java.awt.event.ActionEvent;//事件處理
import javax.swing.JOptionPane;//消息窗口

public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;

public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}

public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置關閉框架的同時結束程序
this.setSize(300,200);//設置框架大小為長300,寬200
this.setResizable(false);//設置框架不可以改變大小
this.setTitle("用戶登錄");//設置框架標題
this.pnluser.setLayout(null);//設置面板布局管理
this.pnluser.setBackground(Color.cyan);//設置面板背景顏色
this.lbluserLogIn.setText("用戶登錄");//設置標簽標題
this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,14));//設置標簽字體
this.lbluserLogIn.setForeground(Color.RED);//設置標簽字體顏色
this.lbluserName.setText("用戶名:");
this.lbluserPWD.setText("密 碼:");
this.btnSub.setText("登錄");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(120,15,60,20);//設置標簽x坐標120,y坐標15,長60,寬20
this.lbluserName.setBounds(50,55,60,20);
this.lbluserPWD.setBounds(50,85,60,25);
this.txtName.setBounds(110,55,120,20);
this.pwdPwd.setBounds(110,85,120,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);//載入標簽到面板
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);//載入面板到框架
this.setVisible(true);//設置框架可顯
}

public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"賬號不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"密碼不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,"賬號或密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}
}

public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}

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

I. 如何用java做登錄界面

import javax.swing.JFrame;//框架
import javax.swing.JPanel;//面板
import javax.swing.JButton;//按鈕
import javax.swing.JLabel;//標簽
import javax.swing.JTextField;//文本框
import java.awt.Font;//字體
import java.awt.Color;//顏色
import javax.swing.JPasswordField;//密碼框
import java.awt.event.ActionListener;//事件監聽
import java.awt.event.ActionEvent;//事件處理
import javax.swing.JOptionPane;//消息窗口public class UserLogIn extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;

public UserLogIn(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}

public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設置關閉框架的同時結束程序
this.setSize(300,200);//設置框架大小為長300,寬200
this.setResizable(false);//設置框架不可以改變大小
this.setTitle("用戶登錄");//設置框架標題
this.pnluser.setLayout(null);//設置面板布局管理
this.pnluser.setBackground(Color.cyan);//設置面板背景顏色
this.lbluserLogIn.setText("用戶登錄");//設置標簽標題
this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,14));//設置標簽字體
this.lbluserLogIn.setForeground(Color.RED);//設置標簽字體顏色
this.lbluserName.setText("用戶名:");
this.lbluserPWD.setText("密 碼:");
this.btnSub.setText("登錄");
this.btnReset.setText("重置");
this.lbluserLogIn.setBounds(120,15,60,20);//設置標簽x坐標120,y坐標15,長60,寬20
this.lbluserName.setBounds(50,55,60,20);
this.lbluserPWD.setBounds(50,85,60,25);
this.txtName.setBounds(110,55,120,20);
this.pwdPwd.setBounds(110,85,120,20);
this.btnSub.setBounds(85,120,60,20);
this.btnSub.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(155,120,60,20);
this.btnReset.addActionListener(new ActionListener()//匿名類實現ActionListener介面
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);//載入標簽到面板
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);//載入面板到框架
this.setVisible(true);//設置框架可顯
}

public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"賬號不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"密碼不能為空","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}else{
JOptionPane.showMessageDialog(null,"賬號或密碼錯誤","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}
}

public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}

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

J. 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登錄相關的資料

熱點內容
pdf光子 瀏覽:832
自拍軟體文件夾名稱大全 瀏覽:325
程序員留學移民 瀏覽:49
梁中間部位箍筋加密區 瀏覽:117
頻譜分析pdf 瀏覽:750
樂2怎麼升級安卓70 瀏覽:172
java中獲取日期 瀏覽:506
單片機74hc245 瀏覽:272
美國歷史上的總統pdf 瀏覽:751
程序員脫單實驗室靠不靠譜 瀏覽:458
php中間四位手機號 瀏覽:869
永旺app怎麼樣了 瀏覽:516
壓縮空氣流量計算軟體 瀏覽:649
智慧聊天app怎麼激活 瀏覽:924
一加換機備份到哪個文件夾 瀏覽:736
支撐pdf 瀏覽:417
java空文件夾刪除 瀏覽:587
安卓9跟81有什麼區別 瀏覽:912
n1藍寶書pdf 瀏覽:244
為什麼安卓機拍照那麼丑 瀏覽:696