import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.PrintStream; import java.sql.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class MyFrame2 implements ActionListener{ String title1 = "Frame 1"; Frame fMain1 = new Frame(title1); String title2 = "Frame 2"; Frame fMain2 = new Frame(title2); Label FullName = new Label("Empty"); Label FullNameHeader = new Label("Full Name"); Label FirstNameHeader = new Label("First Name"); Label LastNameHeader = new Label("Last Name"); Label PhoneNumberHeader = new Label("Phone"); Label AddressHeader = new Label("Address"); Label MailAddressHeader = new Label("Email"); Label HomeAddressHeader = new Label("Home Address"); Label StreetAddressHeader = new Label("Street"); Label CityHeader = new Label("City"); Label StateHeader = new Label("State"); Label ZipHeader = new Label("Zip"); Label CommentHeader = new Label("Comment"); Label FirstName = new Label("Empty"); Label LastName = new Label("Empty"); Label PhoneNumber = new Label(""); Label StreetAddress = new Label(""); Label City = new Label(""); Label State = new Label(""); Label Zip = new Label(""); Label HomeAddress = new Label(""); Label MailAddress = new Label(""); //Label Comment = new Label(""); TextArea Comment = new TextArea(16,26); int x=0; String y; Panel panel3 = new Panel(); //Panel panel4 = new Panel(); Panel panel5 = new Panel(); // Panel pResultSet2 = new Panel(); public MyFrame2(){ } public static void main(String args[]){ MyFrame2 MyFrame2 = new MyFrame2(); MyFrame2.start(""); } public void start(String s){ //String title = "Frame Title"; //Frame fMain1 = new Frame(title); final Button button1 = new Button("Close"); button1.addActionListener(this); final Button button7 = new Button("Close"); button7.addActionListener(this); Button button2 = new Button("New Window"); button2.addActionListener(this); Button button3 = new Button("1"); button3.addActionListener(this); //final Button button4 = new Button("2"); //button4.addActionListener(this); Button button5 = new Button("3"); button5.addActionListener(this); //final Label One = new Label("One"); //final Label Two = new Label("Two"); final Panel panel3 = new Panel(); //panel4.setLayout( new GridLayout(20,1) ); //final Panel panel4 = new Panel(); final Panel panel5 = new Panel(); //final Panel pResultSet2 = new Panel(); //panel4.setLayout(setLayout(null)); //panel4.setLayout(null); //panel3.add(button2); //panel3.add(button3); //panel3.add(button5); //panel3.add(button5); Panel pResultSet = new Panel(); ScrollPane scroll = new ScrollPane(); scroll.setSize(200,200); scroll.add(pResultSet); panel3.add(scroll,"Center"); panel3.add(button1,"South"); fMain1.add(panel3, BorderLayout.CENTER); fMain1.setResizable(false); fMain1.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { fMain1.dispose(); System.exit(0); } }); final Panel pResultSet2 = new Panel(); pResultSet2.setSize(237,800); ScrollPane junk = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); junk.setSize(236,250); pResultSet2.setLayout(null); //panel4.setLayout(null); junk.add(pResultSet2); fMain2.add(junk); // Add the component to the frame; by default, the frame has a border layout //fMain.add(comp, BorderLayout.CENTER); GridBagLayout gbl = new GridBagLayout(); pResultSet.setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1.0; gbc.gridwidth = GridBagConstraints.REMAINDER; //end row gbc.weightx = 0.0; gbc.gridwidth = GridBagConstraints.REMAINDER; //// String url="jdbc:mysql://192.168.168.206/names?user=root&password="; Connection con; String query = "SELECT * FROM person ORDER BY FullName"; Statement stmt; try { //Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver"); Class.forName("org.gjt.mm.mysql.Driver"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { System.out.println("Trying to connect..."); con = DriverManager.getConnection (url, "root", ""); System.out.println("connected!"); stmt = con.createStatement(); ResultSet result = stmt.executeQuery(query); while (result.next()) { //// //for(int j=0;j<20; j++){ if (!result.getString("FullName").equals("null")){ //One.setText(result.getString("FullName")); final Label Three = new Label(result.getString("FullName")); gbl.setConstraints(Three,gbc); pResultSet.add(Three); Three.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { //btnUnsignedRight_mouseClicked(e); //System.out.println(One.getText()); /// fMain1.setVisible(false); String url="jdbc:mysql://192.168.168.206/names?user=root&password="; Connection con; String query = "SELECT * FROM person WHERE FullName ='" + Three.getText() + "'"; Statement stmt; //System.out.println(One.getText()); try { //Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver"); Class.forName("org.gjt.mm.mysql.Driver"); } catch (java.lang.ClassNotFoundException ee) { System.err.print("ClassNotFoundException: "); System.err.println(ee.getMessage()); } try { System.out.println("Trying to connect..."); con = DriverManager.getConnection (url, "root", ""); System.out.println("connected!"); stmt = con.createStatement(); ResultSet result = stmt.executeQuery(query); while (result.next()) { System.out.println(result.getString("PhoneNumber")); } FullName.setText(result.getString("FullName")); PhoneNumber.setText(result.getString("PhoneNumber")); Zip.setText(result.getString("Zip")); HomeAddress.setText(result.getString("HomeAddress")); MailAddress.setText(result.getString("MailAddress")); FirstName.setText(result.getString("FirstName")); LastName.setText(result.getString("LastName")); StreetAddress.setText(result.getString("StreetAddress")); City.setText(result.getString("City")); State.setText(result.getString("State")); Zip.setText(result.getString("Zip")); Comment.setText(result.getString("Comment")); //System.out.println(Comment); stmt.close(); con.close(); } catch(SQLException ex2) { System.err.print("SQLException: "); System.err.println(ex2.getMessage()); } ///////// //Frame f = new Frame("No LayoutManager Example"); fMain2.setSize(300, 300); fMain2.setLayout(null); fMain2.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { fMain2.dispose(); fMain1.setVisible(true); } }); int spacer=12; spacer=spacer+12; FullNameHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(FullNameHeader); FullNameHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; FullName.setBounds(5, spacer, 200, 12); pResultSet2.add(FullName); spacer=spacer+12; FirstNameHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(FirstNameHeader); FirstNameHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; FirstName.setBounds(5, spacer, 235, 12); pResultSet2.add(FirstName); spacer=spacer+12; LastNameHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(LastNameHeader); LastNameHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; LastName.setBounds(5, spacer, 235, 14); pResultSet2.add(LastName); spacer=spacer+12; PhoneNumberHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(PhoneNumberHeader); PhoneNumberHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; PhoneNumber.setBounds(5, spacer, 235, 14); pResultSet2.add(PhoneNumber); spacer=spacer+12; MailAddressHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(MailAddressHeader); MailAddressHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; MailAddress.setBounds(5, spacer, 235, 14); pResultSet2.add(MailAddress); spacer=spacer+12; StreetAddressHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(StreetAddressHeader); StreetAddressHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; StreetAddress.setBounds(5, spacer, 235, 14); pResultSet2.add(StreetAddress); spacer=spacer+12; CityHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(CityHeader); CityHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; City.setBounds(5, spacer, 235, 14); pResultSet2.add(City); spacer=spacer+12; StateHeader.setBounds(5, spacer, 70, 12); pResultSet2.add(StateHeader); StateHeader.setFont(new Font("Arial", Font.BOLD, 12)); //spacer=spacer+12; ZipHeader.setBounds(75, spacer, 235, 12); pResultSet2.add(ZipHeader); ZipHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; State.setBounds(5, spacer, 70, 14); pResultSet2.add(State); //spacer=spacer+12; Zip.setBounds(75, spacer, 228, 14); pResultSet2.add(Zip); spacer=spacer+12; CommentHeader.setBounds(5, spacer, 235, 12); pResultSet2.add(CommentHeader); CommentHeader.setFont(new Font("Arial", Font.BOLD, 12)); spacer=spacer+12; Comment.setBounds(5, spacer, 210, 100); //Comment.setEnabled(false); pResultSet2.add(Comment); spacer=spacer+12; button7.setBounds(80, 255, 60, 20); fMain2.add(button7); Button b1 = new Button("Button1"); b1.setBounds(0, 50, 80, 50); Label b2 = new Label("Button2"); b2.setBounds(100, 100, 100, 100); Button b3 = new Button("Button3"); b3.setBounds(150, 150, 100, 100); // f.add(b1); // f.add(b2); //f.add(b3); int width = 240; int height = 280; fMain2.setSize(width, height); fMain2.setVisible(true); /* fMain2.add("North", panel4); panel4.add("South", panel5); panel5.setLocation(140,140); //works */ // Show the frame //int width = 240; //int height = 280; //fMain2.setSize(width, height); //fMain2.setResizable(false); //fMain2.setVisible(true); //FirstNameHeader.setLocation(140,140); //works //LastNameHeader.setLocation(150,140); //works /// } }); /* Button button6 = new Button(result.getString("FullName")+result.getString("PhoneNumber")+"-"); button6.setActionCommand(result.getString("FullName")); button6.addActionListener(this); gbl.setConstraints(button6,gbc); pResultSet.add(button6);*/ //pResultSet.add(One); } else { /* Button button7 = new Button(result.getString("FullName")); button7.setActionCommand(result.getString(1)); button7.addActionListener(this); gbl.setConstraints(button7,gbc); pResultSet.add(button7); */ } //addComponent(pResultSet,label2,gbl,gbc); }//end of loop stmt.close(); con.close(); } catch(SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } // Show the frame int width = 240; int height = 280; fMain1.setSize(width, height); fMain1.setVisible(true); } private void addComponent( Container p, Component c, GridBagLayout gbl, GridBagConstraints gbc ) { gbl.setConstraints(c,gbc); p.add(c); } public void actionPerformed(ActionEvent actionevent) { String b = actionevent.getActionCommand(); if(b.equals("Close")&&(fMain2.isVisible())) { //System.exit(1); fMain2.dispose(); fMain1.setVisible(true); b=""; } if(b.equals("Close")&&(fMain1.isVisible())) { System.exit(1); //fMain2.dispose(); //fMain2.setVisible(true); b=""; } /* if(b.equals("1")) { button4.setText("1"); x=0; } if(b.equals("1")) { //fMain2.dispose(); //String title = "Frame Title"; //Frame fMain2 = new Frame(title); //TextField button4 = new TextField("Close"); //button4.addActionListener(this); //Button button4 = new Button("Close"); //button4.addActionListener(this); //Button button2 = new Button("New Window"); //button2.addActionListener(this); button4.setText("1"); panel3.add(button4); fMain2.add(panel3, BorderLayout.CENTER); // Show the frame int width = 240; int height = 280; fMain2.setSize(width, height); fMain2.setVisible(true); } if(b.equals("3")) { //fMain2.dispose(); //String title = "Frame Title"; //Frame fMain2 = new Frame(title); //TextField button4 = new TextField("Close"); //button4.addActionListener(this); //Button button4 = new Button("Close"); //button4.addActionListener(this); //Button button2 = new Button("New Window"); //button2.addActionListener(this); button4.setText("3"); panel3.add(button4); fMain2.add(panel3, BorderLayout.CENTER); // Show the frame int width = 240; int height = 280; fMain2.setSize(width, height); fMain2.setVisible(true); }*/ /* if(!b.equals("1")&&!b.equals("3")) { ///////// System.out.println(b); String url="jdbc:mysql://192.168.0.1/names?user=root&password=root"; Connection con; String query = "SELECT * FROM person WHERE FullName ='" + actionevent.getActionCommand() + "'"; Statement stmt; try { //Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver"); Class.forName("org.gjt.mm.mysql.Driver"); } catch (java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: "); System.err.println(e.getMessage()); } try { System.out.println("Trying to connect..."); con = DriverManager.getConnection (url, "root", ""); System.out.println("connected!"); stmt = con.createStatement(); ResultSet result = stmt.executeQuery(query); while (result.next()) { } button4.setText(result.getString(1)); stmt.close(); con.close(); } catch(SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } ///////// panel4.add(button4); fMain2.add(panel4, BorderLayout.CENTER); // Show the frame int width = 240; int height = 280; fMain2.setSize(width, height); fMain2.setVisible(true); }*/ } }