Simulated name

xiaoxiao2021-03-20  223

One.

Package MZL;

Import java.awt. *; import java.awt.Event. *; import javax.swing. *; import javax.swing.event. *; import java.sql. *; import java.io. *; import javax.swing .Table. *; Import javax.swing.text. *; import java.util. *; import javax.imageio. *; import java.applet. *;

public class NameAndAddress extends JFrame implements ActionListener {private JTextArea display; private JButton delete, find, add, renew, update, look; private JLabel mean, word, mobile, phone, compony, address; private JTextField meantext, wordtext, mobiletext, phonetext, comptext, addrtext; private JPanel jp; protected JScrollPane jsp; private JSplitPane jst; private Connection conn; protected Statement stmt; protected JTable jt = new JTable () ;; private Vector row = new Vector (); private Vector cols = new Vector ( ); Private vector headname = new vector (); private defaultTableModel DTM = new defaultTableModel (); UpdateFrame UDF = New UpdateFrame (this);

Public nameAnddress () {Super ("Delist"; /// this.add (time); / ** * Settings Table Title * / String [] A = {"Name", "Job", "Mobile" , "Company", "Phone", "Address"}; headname = new vector (); for (int i = 0; i

Look.SetBounds (290, 80, 60, 20); Look.AddActionListener (this); update = new jbutton ("Modify"); Update.SetBounds (360, 80, 60, 20); Update.AddActionListener (this); JP.Add (MEAN); JP.Add (Word); jp.add (mobile); jp.add (compony); jp.add (address); jp.add (meantext); JP .add (wordtext); jp.add (mobileText); jp.add (phonetext); jp.add (complex); jp.add (delete); jp.add (find); JP. Add (add); jp.add (renew); jp.add (update); jp.add (look); jsp = new jscrollpane (jt); jst = new jsplitpane (JSPLITPANE.VERTICAL_SPLIT, JP, JSP); JST. SetDividerLocation (110); jst.setdividersize (10); jst.setonetouchexpandable (TRUE);

This.Add (jst); this.setsize (600, 400); this.setResizable (TRUE); / ** * Server-side display * / Dimension ScreenSize = Toolkit.getDefaultToolkit (). getScreensize (); Dimension Framesize = this. getSize (); if (frameSize.width> screenSize.width) {frameSize.width = screenSize.width;} if (frameSize.height> screenSize.height) {frameSize.height = screenSize.height;} setBounds ((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2,600,400); this.setVisible (true); / ** * Close window * / this.addWindowListener (new WindowAdapter () {public void windowClosing (WindowEvent e) {Try {stmt.close (); conn.close ();} catch (sqlexception ee) { Ee.PrintStackTrace ();} system.exit (0);}}); / ** * Connect database * / try = conn = getConnection (); stmt = conn.createstatement (); system.out.println ("database Successful connection ");} catch (sqlexception e) {E.PrintStackTrace ();} catch (ioException e) {E.PrintStackTrace ();} catch (classnotfoundexception e) {E.PrintStackTrace ();} ExecuiteQuery ();

Public void actionPerformed (ActionEvent E) {/ ** * Reset button ** / if (E.GetSource () == Renew) {WordText.Settext ("); meantext.setText ("); MobileText.setText ( ""); Phonetext.setText (""); CompText.setText (""); addrtext.settext ("");} / ** * Add button * / if (E.Getsource () == add) {string g = WordText.getText (). Trim (); string h = meantext.getText (). Trim (); string m = mobile.get.getText (). Trim (); string p = phonetext.getText (). Trim () String c = comptext.getText (). Trim (); string a = addrtext.getText (). Trim (); resultset = null; if (g.equals (") || H.Equals (") || m.equals ("") || p.equals ("") || c.Equals ("") || a.equals ("")) {JOPANE.SHOWMESSAGEDIALOG (NULL, "Please enter all information" , "Tips", JOPANE.WARNING_MESSAGE);} else {Try {int b = jt.getSelectedRowCount (); Stmt.execute ("Insert Into Inform (Sname, SJOB, SMOBILE, SPHONE, SCOMPONY, SADDRESS) VALUES ('" G "','" h ", '" m "', '" p ",'" c "", '" a " ")"); row.removeallelements (); execuiteQuery (); JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, "Add success, please refresh!");} catch (Exception EG) {system.out.println (" Add "); Eg.PrintStackTrace ();}}} / ** * Delete button * / if (E.getsource () ==

delete) {int selectedNum = jt.getSelectedRowCount (); int [] selectedRows = jt.getSelectedRows (); if (selectedNum = 0) {try {if (JOptionPane.showConfirmDialog (this, "you sure you want to delete the message /!? N deleted information will not be recovered, continue? " SELECTEDNUM; I ) {Try {SELECTEDNAME [I] = jt.getvalueat (SELECTEDROWS [I], 0);

} Catch (exception ex) {system.out.println ("ddd");}}}}}}}}}}} for (INT i = SELECTEDNUM-1; I> = 0; I -) {system.out.println (SELECTEDNAME [i]) Stmt.execute ("Delete from Inform Where Sname =" " " "); Row.RemoveElelementat (SELECTEDROWELEMENTAT);} DTM.SetDataVector (Row, HeadName); JOPTIONPANE. ShowMessageDialog (NULL, "Delete Success!");}}}}}}} Catch (Exception EE) {system.out.println ("delete");} finally {system.out.println ("firmly);}}}}} else {JOPANE. ShowMessageDialog (NULL, "Unselected content");}} / ** * Refresh button * / if (E.GetSource () == Find) {row.removeallelements (); execuiteQuery ();} / ** * modification button * / If (e.getsource () == UPD "{udf.Update ();} / ** * Query button * / if (E.GetSource () == LOOK) {string g = WordText.getText (). Trim (); string h = meantext.getText. ) .trim (); string m = mobileEText.getText (). Trim (); string p = phonetext.getText (). Trim (); string c = compText.getText (). Trim (); string a = addrtext. GetText (). Trim (); ResultSet RS; try {if (! g.Equals (") ||! h.equals (") ||! m.equals ("") ||! p.equals "") ||! c.Equals (") ||! a.equals (")) {r = stmt.executeQuery ("SELECT * from inform where sname =" "" g "

'" " Or " "' " " or " " smobile = '" m " " " "scompony ='" c "" "OR " " sphone = '" p "' " " or " " saddress = '" A "); if (! rs.next ()) {JOPAANE.SHOWMESSAGEDIALOG (NULL, "Find a record ");} Row.removeallelements (); while (rs.next ()) {cols = new vector (); cols.add (rs.getstring (" sname ")); cols.add (rs.getstring (" sjob ")); Cols.add (rs.getstring (" smobile ")); cols.add (rs.getstring (" scompony ")); cols.add (rs.getstring (" sphone "); cols.add RS.GetString ("saddress")); row.add (cols);} DTM.SetDataVector (RS.Close ();} else {JOPANE.SHOWMESSAGEDIALOG (NULL, Unfill Query Conditions "); }}}}}}} Public static connection getConnection () Throws IOException, SQLException, ClassNotFoundException {String strurl = "jdbc: odbc: driver = {Microsoft Access Driver (* .mdb)}; DBQ = word.mdb"; Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver" ); Return DriverManager.getConnection (Strurl, "," ");

} / ** * Retrieve Database * / Public Void ExecuiteQuery () {rate {RESUTSET RS = Stmt.executeQuery ("SELECT * from Inform"); while (rs.next ()) {cols = new vector (); cols. Add ("sname")); cols.add (rs.getstring ("sjob")); cols.add (rs.getstring ("smobile"); cols.add (rs.getstring ("scompony ")); Cols.add (rs.getstring (" sphone ")); cols.add (" saddress "); row.add (cols);} DTM.SetDataVector (Row, HeadName); rs. .close ();} catch (sqlexception e) {}} / ** * main method * / public static void main (String [] args) {nameAnddress frame = new nameAndaddress (); Toolkit Tool = frame.gettoolkit (); Image MyImage = Tool.getiMage ("Images // icon.gif"); frame.seticonImage (MyImage);}}}

Package MZL;

Import java.awt. *; import java.awt.Event. *; import javax.swing. *; import javax.swing.event. *; import java.sql. *; import java.io. *; import javax.swing .Table. *; Import java.util. *;

public class UpdateFrame extends JFrame implements ActionListener {JButton ok, no; JLabel name, job, phone, mobile, address, compony; JTextField ntext, jtext, ptext, mtext, atext, ctext; NameAndAddress naa; int rowNumber; public UpdateFrame (NameAndAddress naa ) {Super ("Modify Window"); this.naa = naa; ok = new jbutton ("OK"); Ok.SetBounds (30, 20, 60, 20); ok.addActionListener (this); no = new jbutton (" Cancel "); No.SetBounds (110, 200, 60, 20); No.AddActionListener (this); name = new jlabel (" Name: "); Name.SetBounds (10, 10, 40, 20); job = new Jlabel ("Job:"); Job.SetBounds (10, 40, 40, 20); phone = new Jlabel ("Mobile:"); Phone.setBounds (10, 70, 40, 20); Mobile = New Jlabel (" Company: "); Mobile.setBounds (10,100,40,20); Compony = New Jlabel (" Phone: "); Compony.setBounds (10,130,40,20); address = new Jlabel (Address); Address .SetBounds (10,160,40,20); ntext = new jtextfield (); nText.setBounds (60, 10, 60, 20); jtext = new jtextfield (); jtext.setBounds (60, 40, 60, 20); MTEXT = New jtextfield (); mtext.setbounds (60, 70, 100, 20); ctext = new JTextField (); ctext.setBounds (60,100,100,20); ptext = new JTextField (); ptext.setBounds (60,130,160,20); atext = new JTextField (); atext.setBounds (60,160,160,20); add (name) add (job); add (movile); add (compony); add (address); add (ntext); add (jtext); add (mtext); add (ctext) Add (atExt); Add (OK); ad (no); this.setLayout (null); this.setBounds (400, 200, 250, 300); this.setVisible (false); this.setAlwaysontop (True) Public void update () {Try {rownumber = naa.jt.getSelectedRow ();

THIS.NTEXT.SETTEXT (String) Naa.jt.getValueat (RowNumber, 0)); this.jtext.Settext (String) Naa.jt.getValueat (RowNumber, 1)); this.PText.setText (String ) naa.jt.getvalueat (RowNumber, 2)); this.mtext.Settext (String) Naa.jt.getValueat (RowNumber, 3)); this.ctext.setText (String) Naa.jt.getValueat (Rownumber , 4)); this.atext.Settext (String) Naa.jt.getValueat (Rownumber, 5)); this.setVisible (TRUE);} catch (Exception EA) {JOPANE.SHOWMESSAGEDIALOG (NULL, "please select a one Record ");}} public void actionperformed (an) {if (e.GetSource () == ok) {Try {naa.stmt.execute (" Update Inform Set SName = " " " NText.getText ( ) "'" ", Sjob =" "" " ", smobile = " "' " mtext.getText () " " ", sphone = " " '" PText.getText () " ", scompony =" "'" ctext.getText () "'" ", saddress =" "" " " " " ) "'" "Where sname =" "'" (string) naa.jt.getValueat (Rownumber, 0) ""); naa.jt.setValueat (nText.getText (), Rownumbe R, 0); naa.jt.setValueat (jtext.getText (), RowNumber, 1); naa.jt.set (), rownumber, 2); naa.jt.setValueat (ctext.getText () , RowNumber, 3); naa.jt.set (PTEXT.GETTEXT (), ROWNUMBER, 4); naa.jt.set (), RowNumber, 5); this.Show (false);} catch Exception EE) {system.out.println ("DDDD");

转载请注明原文地址:https://www.9cbs.com/read-130313.html

New Post(0)