This is the code I wrote at the school's Innovation center four years ago (see, a Java class file in a red box last edited on 2012/4/28 21:24).
Remember this is a SE construction of Student information management system, which landed part of the code, I excerpt as follows, now looks flawed, haha, table spray Ah, this is my past:
Package Com.global.xxl.studentinfo.control;import Java.awt.event.*;import Com.global.xxl.studentinfo.db.DbLogin; Import Com.global.xxl.studentinfo.ui.uilogin;import com.global.xxl.studentinfo.ui.uiregister;/** * * Operation of Control Login Interface (uilogin) * */public class Controllogin implements ActionListener {public static uiregister register;public void actionperformed (ActionEvent e) {///Login button corresponds to the method if (E.getactioncommand (). Equals ("Login")) { System.out.println ("Landing"); new Dblogin ();//ui_01 ui=new ui_01 (); } The Cancel button corresponds to the method if (E.getactioncommand (). Equals ("Cancel")) {System.out.println ("Cancel");//Empty text box UiLogin.jtf.setText (""); UiLogin.jpf.setText ("");} The Register button corresponds to the method if (E.getactioncommand (). Equals ("register")) {System.out.println ("register"); register =new Uiregister ();} The Exit button corresponds to the method if (E.getactioncommand (). Equals ("Exit")) {System.out.println ("exit");//Close window system.exit (0);}}
Package Com.global.xxl.studentinfo.ui;import java.awt.*; Import javax.swing.*; Import com.global.xxl.studentinfo.control.controllogin;/** * * Display student Information Management system-Login Interface */public class Uilogin extends JFrame {/** * */private static final long serialversionuid = 1l;private JPanel jp1,jp2,jp3; Private JLabel jlb1,jlb2;public static JTextField jtf;public static JPasswordField jpf;private JButton JB1,JB2,JB 3,jb4;private Controllogin BH; Call Control (Listen) class public static uilogin login;public static void Main (string[] args) {login=new uilogin ();} Public Uilogin () {jp1=new JPanel (); jp2=new JPanel (); jp3=new JPanel (); Jlb1=new JLabel ("User name"); Jlb2=new JLabel ("password") jtf=new JTextField (jpf=new JPasswordField) jb1=new JButton ("login") jb2=new JButton ("Cancel") ; jb3=new JButton ("registration"); Jb4=new JButton ("exit"); bh=new controllogin ();//monitoring Jb1.addactionlistener (BH); Jb2.addactionlistener (BH); Jb3.addaCtionlistener (BH); Jb4.addactionlistener (BH); This.setlayout (new GridLayout (3,1,10,10)); Jp1.add (JLB1); Jp1.add (JTF); Jp2.add (JLB2); Jp2.add (JPF); Jp3.add (JB1); Jp3.add (JB2); Jp3.add (JB3); Jp3.add (JB4); This.add (JP1); This.add (JP2); This.add (JP3); This.settitle ("User login"); this.setbounds (900,300,300,175); this.setdefaultcloseoperation (jframe.exit_on_close); this.setvisible (True);}}
Package Com.global.xxl.studentinfo.db;import Java.sql.connection;import Java.sql.drivermanager;import Java.sql.resultset;import Java.sql.sqlexception;import Java.sql.statement;import Com.global.xxl.studentinfo.ui.uilogin;import Com.global.xxl.studentinfo.ui.uiloginfailure;import com.global.xxl.studentinfo.ui.uifunction;/** * * Login Interface (uilogin) connection Database class * */public class Dblogin {public dblogin () {String Driver = "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url = "Jdbc:sqlserver://localhost;databasename=person"; String username = "sa"; String password = "111111"; Connection CN = null;//Create connection Statement st = null; Create statement to send statement string sql;//sql statement ResultSet rs = null;//return result set//username and Password Compare database Try{class.forname (driver); Load driver System.out.println ("load driver succeeded"); cn = Drivermanager.getconnection (Url,username,password); Create Connection System.out.println ("Connection succeeded. "); }catch (Exception E1) {E1.printstaCktrace ();} Compare database try{st = Cn.createstatement (); Create statement to send statement sql = "SELECT * from login where id= '" +uilogin.jtf.gettext () + "'"; SYSTEM.OUT.PRINTLN (sql), rs = st.executequery (sql), while (Rs.next ()) {String getid=rs.getstring ("id"); String getpass=rs.getstring ("password"); String Text=uilogin.jtf.gettext (); @SuppressWarnings ("deprecation") string Pass=uilogin.jpf.gettext (); Text.equals (GetID) &&pass.equals (Getpass))//Login succeeded {UiLogin.login.dispose (); new Uifunction ();} else {UiLogin.login.dispose (); new Uiloginfailure ();}}} catch (Exception E2) {e2.printstacktrace ();} Try//close resource {rs.close (); St.close (); Cn.close (); SYSTEM.OUT.PRINTLN ("Close resource success"); } catch (SQLException E1) {e1.printstacktrace ();}} public void Main (String args[]) {}}
Edited at: 2016-05-13 20:14
Unconsciously I have written four code, posted four years ago code, table spray ha