/* -- ' Copyright by Erica Andrews aka CyLiKoN JeZuZ aka Li'L CJ, ' Febuary 2000. No one is permitted to implement this code ' or any portion of it on their site without the express written consent ' of the author (cylikon@hotmail.com - ./IcedPinky/). ' All rights reserved. ' This is the client for an RMI application I created to query ' my MySQL database and list all available rows in the db. The implementation uses ' a JDBC-compatible driver and VECTORS for processing the ResultSet, since RMI ' will throw a ResultSetNotSerializableException if you attempt to process a ' a result set the usual way. All info in the resultset is stored in a big Vector ' which is returned to the client. This client then processes the Vector. ' The query results are printed into a TextArea called "textscreen". Due to the nature ' of the query in the RMI implementation this GUI is only prepared to handle ' ResultSets with exactly FIVE columns - to handle other amounts of columns the ' way the Vector is printed to the textarea in the DoQuery() method will have ' to be adjusted. ' This class was hand-coded in Java by Erica Andrews on Feb. 1, 2000 ' The implementation uses the ' gweMySQLJDBC 0.9.2 driver and MySQL 3.22.9 for database connectivity. -- */ /* Feb 1, 1999 */ import java.io.*; import java.util.*; import java.sql.*; import java.awt.*; import java.awt.Font; import java.awt.event.*; import java.rmi.*; import java.util.Vector; public class RMIMySQLClient extends Frame implements WindowListener,MouseListener { TextArea textscreen; Button doit; Label label; Panel panel1; Panel panel2; public RMIMySQLClient () { setTitle("MySQL Query Powered By Java"); setLayout(null); setBackground(Color.cyan); setForeground(Color.black); setBounds(new Rectangle(5,5,790,570)); textscreen = new TextArea ( 5, 80 ); textscreen.setBackground(Color.blue); textscreen.setForeground(Color.white); textscreen.setBounds(new Rectangle(10,175,775,340)); doit = new Button("Show ALL Sites!"); doit.setForeground(Color.black); doit.setBackground(Color.pink); doit.addMouseListener( this ); doit.setBounds(new Rectangle(600,95,185,70)); label = new Label("MySQL Query Powered By Java"); label.setAlignment(Label.CENTER); label.setForeground(Color.white); label.setBackground(Color.blue); label.setFont(new Font("Helvetica", Font.BOLD, 26)); label.setBounds(new Rectangle(2,25,790,60)); add (label); add (doit); add (textscreen ); addWindowListener ( this ); resize ( 790, 570); pack(); show (); } // end GUI constructor // ************** Listener Events ****************** //**** WindowListener methods public void windowActivated ( WindowEvent e ) { } public void windowDeactivated ( WindowEvent e ) { } public void windowOpened ( WindowEvent e ) { } public void windowClosed ( WindowEvent e ) { } public void windowClosing ( WindowEvent e ) { this.hide (); this.dispose (); System.exit(0); } public void windowIconified ( WindowEvent e ) { } public void windowDeiconified ( WindowEvent e ) { } //**** MouseListener methods public void mouseClicked ( MouseEvent e ) { } public void mousePressed ( MouseEvent e ) { doit.setBackground(Color.red); label.setForeground(Color.red); label.setBackground(Color.white); label.setText("SEARCHING..."); } public void mouseReleased ( MouseEvent e ) { DoQuery(); } public void DoQuery() { // - showing the SELECT query statement in the Textarea "textscreen" try { RMIMySQL obj = (RMIMySQL) Naming.lookup("//127.0.0.1/RMIMySQLIMPL"); obj.VectorCleanUp(); // --- cleaning out the vector Vector rst = new Vector(); rst = obj.RMIResultSet(); int x = 0; // ---- for counting the number of results int end = rst.size(); // -- for controlling when counting/printing stops int querycount = end/5; textscreen.appendText("\n"); while (x < end) { textscreen.appendText(rst.elementAt(x)+" "); x++; textscreen.appendText(rst.elementAt(x)+" "); x++; textscreen.appendText(rst.elementAt(x)+" "); x++; textscreen.appendText(rst.elementAt(x)+" "); x++; textscreen.appendText(rst.elementAt(x)+"\n"); x++; // --- incrementing x } // - end of while statement textscreen.appendText("\n\n\n QUERY FOUND "+querycount+" RESULTS."); } catch (Exception exc) { textscreen.appendText("A problem occurred: "+exc); } // --- end of try/catch doit.setBackground(Color.pink); label.setForeground(Color.white); label.setBackground(Color.blue); label.setText("MySQL Query Powered By Java"); } //---------- end of method DoQuery for MouseReleased public void mouseEntered ( MouseEvent e ) { doit.setBackground(Color.green); } public void mouseExited ( MouseEvent e ) { doit.setBackground(Color.pink); } public static void main(String args[]) { new RMIMySQLClient(); } } // end of Class