下面是一個(gè)簡(jiǎn)單的登錄示例:
創(chuàng)新互聯(lián)是一個(gè)技術(shù)型專業(yè)網(wǎng)站制作公司,致力于為廣大企業(yè)、創(chuàng)業(yè)者打造切實(shí)有效的PC站、WAP站、APP站點(diǎn)等企業(yè)網(wǎng)站。無(wú)論是企業(yè)宣傳的成都全網(wǎng)營(yíng)銷推廣、致力于營(yíng)銷的電商網(wǎng)站、內(nèi)容資訊分享的各行業(yè)網(wǎng)站或其他類型網(wǎng)站,我們都從網(wǎng)站前期定位分析策劃、技術(shù)架構(gòu),到網(wǎng)站界面設(shè)計(jì)、創(chuàng)意表現(xiàn)、站點(diǎn)架構(gòu)搭建以及后續(xù)訪問(wèn)監(jiān)控、維護(hù)、網(wǎng)站托管運(yùn)營(yíng)反饋建議等提供整套服務(wù)。
代碼復(fù)制展示:
public class ATMLogin {
public static void main(String[] args) {
// 設(shè)置用戶名和密碼
String username = "gqk";
String password = "520";
// 最多可以登錄 3 次
for (int i = 0; i 3; i++) {
// 讀取用戶輸入的用戶名和密碼
Scanner in = new Scanner(System.in);
System.out.print("請(qǐng)輸入用戶名:");
String inputUsername = in.nextLine();
System.out.print("請(qǐng)輸入密碼:");
String inputPassword = in.nextLine();
// 檢查用戶名和密碼是否正確
if (inputUsername.equals(username) inputPassword.equals(password)) {
System.out.println("歡迎" + username + "登錄!");
break; // 登錄成功,退出循環(huán)
} else {
System.out.println("用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!");
}
}
// 如果 3 次登錄都失敗,則提示用戶
System.out.println("卡片已經(jīng)被鎖,請(qǐng)聯(lián)系客服人員!");
}
}
回答不易望請(qǐng)采納
CS結(jié)構(gòu)系統(tǒng)的退出如下:public void init() {\x0d\x0a this.setTitle("用戶登錄界面");\x0d\x0a this.add(createCenterPane());\x0d\x0a this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);\x0d\x0a this.setSize(new Dimension(450, 335));\x0d\x0a this.setLocationRelativeTo(null);\x0d\x0a // this.setVisible(true);\x0d\x0a this.addWindowListener(new WindowAdapter() {\x0d\x0a public void windowClosing(WindowEvent e) {\x0d\x0a int choose = JOptionPane.showConfirmDialog(null, "是否要退出登錄界面?",\x0d\x0a "系統(tǒng)提示:", JOptionPane.YES_NO_OPTION);\x0d\x0a if (choose == JOptionPane.YES_OPTION) {\x0d\x0a System.exit(1);\x0d\x0a }\x0d\x0a }\x0d\x0a });\x0d\x0a }其中this為JFrame對(duì)象。BS結(jié)構(gòu)的退出直接用windows.close()方法就行了!
import java.awt.*; \x0d\x0aimport javax.swing.*; \x0d\x0aimport java.awt.event.*; \x0d\x0aimport java.sql.*; \x0d\x0a\x0d\x0aclass LoginFrm extends JFrame implements ActionListener \x0d\x0a{ \x0d\x0aJLabel lbl1=new JLabel("用戶名"); \x0d\x0aJLabel lbl2=new JLabel("密碼"); \x0d\x0aJTextField txt=new JTextField(15); \x0d\x0aJPasswordField pf=new JPasswordField(); \x0d\x0aJButton btn1=new JButton("確定"); \x0d\x0aJButton btn2=new JButton("取消"); \x0d\x0a\x0d\x0apublic LoginFrm() \x0d\x0a{ \x0d\x0athis.setTitle("登陸"); \x0d\x0aJPanel jp=(JPanel)this.getContentPane(); \x0d\x0ajp.setLayout(new GridLayout(3,2,10,10)); \x0d\x0ajp.add(lbl1);jp.add(txt); \x0d\x0ajp.add(lbl2);jp.add(pf); \x0d\x0ajp.add(btn1);jp.add(btn2); \x0d\x0abtn1.addActionListener(this); \x0d\x0abtn2.addActionListener(this); \x0d\x0a} \x0d\x0a\x0d\x0apublic void actionPerformed(ActionEvent ae) \x0d\x0a{ \x0d\x0aif(ae.getSource()==btn1) \x0d\x0a{ \x0d\x0atry \x0d\x0a{ \x0d\x0aClass.forName("sun.jdbc.odbc.JdbcOdbcDriver"); \x0d\x0aConnection con=DriverManager.getConnection("jdbc:odbc:MyDB","",""); \x0d\x0aStatement cmd=con.createStatement(); \x0d\x0aResultSet rs=cmd.executeQuery("select * from loginAndpassword where login='"+txt.getText()+"' and password='"+pf.getText()+"'"); \x0d\x0aif(rs.next()) \x0d\x0a{ \x0d\x0aJOptionPane.showMessageDialog(null,"登陸成功!"); \x0d\x0a} \x0d\x0aelse \x0d\x0aJOptionPane.showMessageDialog(null,"用戶名或密碼錯(cuò)誤!"); \x0d\x0a} catch(Exception ex){} \x0d\x0a\x0d\x0aif(ae.getSource()==btn2) \x0d\x0a{ \x0d\x0atxt.setText(""); \x0d\x0apf.setText(""); \x0d\x0a} \x0d\x0a} \x0d\x0a} \x0d\x0a\x0d\x0apublic static void main(String arg[]) \x0d\x0a{ \x0d\x0aJFrame.setDefaultLookAndFeelDecorated(true); \x0d\x0aLoginFrm frm=new LoginFrm(); \x0d\x0afrm.setSize(400,200); \x0d\x0afrm.setVisible(true); \x0d\x0a} \x0d\x0a}