資源描述:
《java課程設(shè)計源程序》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、packagejavabigwork;importjavaxeswing?*;importjava.awt.*;importjava.awt.event?*;importjava.sq1?*;publicclassLoginFrmextendsJFrameimplementsActionListener{privateDLabellblTitle=new3Label(H歡迎進(jìn)入家庭財務(wù)管理系統(tǒng)”);privateDLabellblName=newDLabel("用戶名”);privateDLabellbl
2、Pwd=new3Label("密碼”);privateDTextFieldtxtName二new3TextField();privateDPasswordFieldtxtPwd=new3PasswordField();private^ButtonbtnOk=newJButton("用戶登陸”);private^ButtonbtnCancel=newJButton(H退出系統(tǒng)”);privateStringdriver=nsun?jdbc.odbc.DdbcOdbcDriver'1;privateStrin
3、gurl="jdbc:odbc:mydbH;privateintrowcount=0;publicLoginFrm(){DPaneljp=(JPanel)thiSegetContentPane();jp.setLayout(null);jp.add(lblTitle);lblTitle.setBounds(300?50,200,50);jp.add(lblName);lblName.setBound$(200^100^100,20);jp.add(txtName);txtName.setBound$(50
4、0^100,100^20);jp.add(lblPwd);lblPwd.setBounds(200150,100,20);jp.add(txtPwd);txtPwd.setBounds(500^150^100^20);jp.add(btnOk);btnOk.setBounds(200^220,100^20);jp.add(btnCancel);btnCancel?setBounds(500>220,100^20);this?setTitle(M家庭用戶登陸”);this.setSize(800400);t
5、his?setVisible(true);this?setDefaultCloseOperation(EXI7^OA/_CLOSE);btnOk.addActionListener(this);btnCancel.addActionListener(this);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==btnOk){String[][]rows=this>queryCustome「s();Stringsl=txtName.getT
6、ext();Strings2=txtPwd.getText();for(inti=0;ishok/AfessageDiatog(this>”用戶名和密碼止確“);newCustomerFrm();}elseJOptionPane.sho^MessageDiaLog(this,"用戶名或密碼錯誤“);}}}if(e?getSource()==btnCa
7、ncel){System.exit(0);}}publicString[][]queryCustomers(){String[][]rows=null;try{Class.forName(drix/er);Connectioncon=DriverManager.getCo門門ectio門(url);Statementcmd=con.createstatement();Stringsql="selectcount(*)fromadmin";ResultSetrs=cmd.executeQue“y(sql);
8、rs.next();rowcount=rs.getint⑴;rows=newString[rowcount][2];sql=Hselect*fromadmin”;rs=cmd?executeQuery(sql);rowcount=0;while(rs>next()){for(inti=1;i<=2;i++)rows[rowcount][i-1]=rs.getString(i);rowcount++;}con.close();}