本文目錄一覽:
java使用面向對象寫一個登錄註冊查詢的功能
import java.util.Scanner;/**
* 採用面向對象的方式 寫一個登錄系統
* @author Administrator
*
*///用戶信息class UserInfo{ public static String[] user = new String[10]; public static String[] passwd = new String[10];
public UserInfo() { this.user[0] = “test”; this.passwd[0] =”123456″;
}
}//找回密碼class ZhaoHui extends UserInfo{ public static void zhaohui() {
Scanner s = new Scanner(System.in);
System.out.println(“請輸入你要找回的用戶名:”);
String zname = s.nextLine(); for(int i=0;i2;i++) { if(user[i].equals(zname)) {
Scanner ss = new Scanner(System.in);
System.out.println(“恭喜你!成功找回密碼,請輸入:”+”‘張哥最帥'”+” 查看密碼”);
String zgzs = ss.nextLine();
if(“張哥最帥”.equals(zgzs)) {
System.out.println(passwd[i]);
}else {
System.out.println(“請輸正確!”);
}
}else if(user[i]!=zname){
System.out.println(“用戶名不存在!”); return;
}
break;
}
}
}//修改密碼 class XiuGai extends UserInfo{ public static void xiugai() {
Scanner s =new Scanner(System.in);
System.out.println(“請輸入您要修改的密碼:”);
String xpasswd = s.nextLine(); for(int i=0;i2;i++) {
passwd[i] = xpasswd; if(xpasswd.equals(passwd[i])) {
System.out.println(“恭喜你,修改成功!”); break;
}else {
System.out.println(“修改密碼失敗”); break;
}
}
}
}//查詢用戶class ChaXun extends UserInfo{
public static void select() { for(int i=0;i2;i++) {
System.out.println(“當前用戶:”+user[i] +”\n”+ “當前密碼:”+passwd[i] );
i++; break;
}
}
}//註冊class ZhuCe extends UserInfo{
public static void regist() {
Scanner ss = new Scanner(System.in);
System.out.println(“請輸入用戶名:”);
String suser = ss.nextLine();
System.out.println(“請輸入密碼:”);
String spasswd = ss.nextLine();
for(int i=0;iuser.length;i++) {
user[i] = suser;
passwd[i] = spasswd;
System.out.println(“註冊成功!”); break;
}
}
}//登錄class Loginc extends UserInfo{
public static void login() { int flag = 1;
Scanner scanner = new Scanner(System.in);
System.out.println(“請輸入用戶名:”);
String users = scanner.nextLine();
System.out.println(“請輸入密碼:”);
String passwds = scanner.nextLine();
for(int i=0;iUserInfo.user.length;i++) { if(user[i].equals(users) passwd[i].equals(passwds)) {
System.out.println(“登陸成功!”); break;
}
System.out.println(“登陸失敗!”); break;
}
}
}//主界面class ZhuJieMian{ public static void Start() {
Loginc Loginc = new Loginc();
ZhuCe ZhuCe = new ZhuCe();
ChaXun ChaXun = new ChaXun();
XiuGai XiuGai = new XiuGai();
ZhaoHui ZhaoHui = new ZhaoHui();
Scanner s = new Scanner(System.in); while(true) {
System.out.println(“|”+ “\t”+ “\t”+ “\t”+ “\t”+ “\t”+ “\t”+ “\t”+”\t”+”|”);
System.out.println(“|”+”\t” + “測試用戶名:test 測試密碼:123456” + “\t”+ “\t”+ “\t”+ “\t”+”|”);
System.out.println(“|” + “\t”+ “請輸入[1-5]進行操作 1.登錄|2.註冊|3.查詢當前用戶|4.修改密碼|5.找回密碼 ” + “\t”+”|”);
System.out.print(“請輸入:”); int temp = s.nextInt();
switch(temp) { case 1:Loginc.login(); break; case 2:ZhuCe.regist();; break; case 3:ChaXun.select();; break; case 4:XiuGai.xiugai();; break; case 5:ZhaoHui.zhaohui();; break; default:System.out.println(“錯誤!請重寫輸入正確的數字進行操作!”);
}
}
}
}public class LoginTest { public static void main(String[] args) {
ZhuJieMian zjm = new ZhuJieMian();
zjm.Start();
}
}
性能測試中如何使用java批量註冊登錄賬戶
性能測試中示例代碼使用java批量註冊登錄賬戶。
性能測試過程中所需的測試數據,以登錄為例,為了更真實的模 批量讀取註冊。
Java登錄註冊功能實現代碼解析,文中通示例代碼,每個用戶信息都是唯一的,所以可以藉助Set的特性來操作用戶信息的存放。
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.setDefaultLookAndFeelDecorated(true);
LoginFrm frm = new LoginFrm();
frm.setSize(400, 200);
frm.setVisible(true);
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/310161.html