這個(gè)需要你會(huì)file的操作,將接收的username和password寫(xiě)入user.Txt文件中即可。
成都創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的平橋網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
import java.util.Scanner;
public class Logon {
private static final char username = '青';
private static final int password = 123;
private static final Scanner san = new Scanner(System.in);
public static void main(String[] args) {
char iname;
int ipass;
System.out.print("請(qǐng)輸入用戶名: ");
iname = san.next().charAt(0);
System.out.print("請(qǐng)輸入密碼: ");
ipass = san.nextInt();
if(Logon.username == iname Logon.password == ipass) {
System.out.println("歡迎你, " + Logon.username);
} else {
System.out.println("對(duì)不起, 你不是" + Logon.username);
}
}
}
1.寫(xiě)一個(gè)操作數(shù)據(jù)庫(kù)的通用DAO(假設(shè)為Dao.java),提供
·加載數(shù)據(jù)庫(kù)驅(qū)動(dòng)和獲取數(shù)據(jù)庫(kù)連接的方法:void getConnection();
·執(zhí)行查詢的方法:ResultSet executeQuery(String sql);
·執(zhí)行更新的方法:Integer executeUpdate(String sql);
·關(guān)閉資源的方法:void releaseResource(Connection con);
2.在你的界面中把用戶名和密碼取出來(lái)
·username = yourTextField.getText();
·password = yourPasswordField.getText();
3.匹配
·驗(yàn)證username、password是否是有效輸入值(例如:不能包含特殊字符,不能有注入嫌疑等)
·String sql = "select * from yourTable where username='"+username+"' and password='"+password+"'" ;
·Dao.executeQuery(sql):如果有結(jié)果說(shuō)明合法,否則不合法。
不懂Connect 我
cmd的話需要用scanner接受鍵盤(pán)輸入
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入用戶名:");
String username = input.next();
System.out.println("請(qǐng)輸入密碼:");
String password = input.next();
try {
FileWriter fw = new FileWriter("d:/text.txt", false);
BufferedWriter writer = new BufferedWriter(fw);
StringBuffer sb = new StringBuffer();
sb.append("用戶名:").append(username).append(" ").append("密碼:")
.append(password);
writer.write(sb.toString());
writer.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
你要先學(xué)會(huì)截圖哦,你發(fā)的看不清楚,重新寫(xiě)了一個(gè)你參考參考!
import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Day30A extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel labelName,labelId,labelPass,labelMoney,labelSelect,labelCar;
private JComboBoxString jcb;
private JPanel jp1,jp2,jp3,jp4,jp5,jp6,jp7;
private ButtonGroup btg;
private JRadioButton jr1,jr2;
Day30A(){
this.setTitle("注冊(cè)賬戶");
this.setLayout(new GridLayout(7,1));
this.setSize(300,280);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
init();
this.setVisible(true);
}
private void init() {
String str="卡片類型1,卡片類型2,卡片類型3,卡片類型4,卡片類型5";
jcb=new JComboBox(str.split(","));
labelId=new JLabel("賬號(hào): ");
labelName=new JLabel("姓名: ");
labelPass=new JLabel("密碼: ");
labelMoney=new JLabel("開(kāi)戶金額:");
labelSelect=new JLabel("存款類型:");
labelCar=new JLabel("卡片類型:");
addFun1();
addFun2();
}
private void addFun2() {
this.add(jp1);
this.add(jp2);
this.add(jp3);
this.add(jp4);
this.add(jp5);
this.add(jp6);
this.add(jp7);
}
private void addFun1() {
jp1=new JPanel();
jp1.add(labelId);
jp1.add(new JTextField(15));
jp2=new JPanel();
jp2.add(labelName);
jp2.add(new JTextField(15));
jp3=new JPanel();
jp3.add(labelPass);
jp3.add(new JTextField(15));
jp4=new JPanel();
jp4.add(labelMoney);
jp4.add(new JTextField(13));
jp5=new JPanel();
jp5.add(labelSelect);
btg=new ButtonGroup();
jr1=new JRadioButton("定期");
jr2=new JRadioButton("活期",true);
btg.add(jr1);
btg.add(jr2);
jp5.add(jr1);
jp5.add(jr2);
jp6=new JPanel();
jp6.add(labelCar);
jp6.add(jcb);
jp7=new JPanel();
jp7.add(new JButton("確定"));
jp7.add(new JButton("取消"));
}
public static void main(String[] args) {
new Day30A();
}
}