import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.* ; public class symbol extends Frame implements ActionListener { public Toolkit tk; public Image img; public TextField tf_date; public Panel Panel1; public Label lbl_symbolcode1; public TextField tf_symbolcode1; public Button but_retrieve; public Panel Panel2; public Label lbl_symbolcode; public TextField tf_symbolcode; public Label lbl_symbol; public TextField tf_symbol; public Label lbl_desc; public TextField tf_desc; public Button but_first; public Button but_previous; public Button but_next; public Button but_last; public Label lbl_message; public TextArea ta_message; public Button but_reset; public Button but_add; public Button but_delete; public Button but_update; public Button but_help; public Button but_exit; // public Connection con; public String s1,s2,s3,sqlstmt; public int i,ret; public symbol(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Symbol Information"); setLayout(null); tk = getToolkit(); img = tk.getImage("air.gif"); tf_date = new TextField(""); Panel1 = new Panel(); Panel1.setLayout(null); Panel1.setForeground(Color.black); Panel1.setBackground(Color.gray); lbl_symbolcode1 = new Label("Symbol Code",Label.LEFT); tf_symbolcode1 = new TextField(""); but_retrieve = new Button("Retrieve"); Panel2 = new Panel(); Panel2.setLayout(null); Panel2.setForeground(Color.black); Panel2.setBackground(Color.gray); lbl_symbolcode = new Label("Symbol Code",Label.LEFT); tf_symbolcode = new TextField(""); lbl_symbol = new Label("Symbol",Label.LEFT); tf_symbol = new TextField(""); lbl_desc = new Label("Symbol Description",Label.LEFT); tf_desc = new TextField(""); but_first = new Button("First"); but_previous = new Button("Previous"); but_next = new Button("Next"); but_last = new Button("Last"); but_reset = new Button("Reset"); but_add = new Button("Add"); but_delete = new Button("Delete"); but_update = new Button("Update"); but_help = new Button("Help"); but_exit = new Button("Exit"); lbl_message = new Label("MESSAGE / ACTION / ERROR",Label.LEFT); ta_message = new TextArea(""); // set date & time tf_date.setText( Validate.getDate()); // Add()s add(tf_date); add(Panel1); Panel1.add(lbl_symbolcode1); Panel1.add(tf_symbolcode1); Panel1.add(but_retrieve); add(Panel2); Panel2.add(lbl_symbolcode); Panel2.add(tf_symbolcode); Panel2.add(lbl_symbol); Panel2.add(tf_symbol); Panel2.add(tf_desc); Panel2.add(lbl_desc); add(but_first); add(but_previous); add(but_next); add(but_last); add(lbl_message); add(ta_message); add(but_reset); add(but_add); add(but_delete); add(but_update); add(but_help); add(but_exit); // Events add but_retrieve. addActionListener(this); but_first. addActionListener(this); but_previous. addActionListener(this); but_next. addActionListener(this); but_last. addActionListener(this); but_reset. addActionListener(this); but_add. addActionListener(this); but_delete. addActionListener(this); but_update. addActionListener(this); but_help. addActionListener(this); but_exit. addActionListener(this); // InitialPosition setBounds(0,0,800,600); tf_date.setBounds (580,100,215,25); Panel1.setBounds (148,141,506,72); lbl_symbolcode1.setBounds (90,27,130,19); tf_symbolcode1.setBounds (221,21,70,27); but_retrieve.setBounds (332,25,75,25); Panel2.setBounds (148,239,504,115); lbl_symbolcode.setBounds (100,12,130,19); tf_symbolcode.setBounds (257,12,60,27); lbl_symbol.setBounds (100,46,130,19); tf_symbol.setBounds (257,46,60,27); lbl_desc.setBounds (100,80,130,19); tf_desc.setBounds (257,80,230,27); but_first.setBounds (90,392,75,25); but_previous.setBounds (90,418,75,25); but_next.setBounds (90,444,75,25); but_last.setBounds (90,470,75,25); ta_message.setBounds (210,395,384,101); lbl_message.setBounds (210,371,198,19); but_reset.setBounds (643,395,75,25); but_add.setBounds (643,421,75,25); but_delete.setBounds (643,447,75,25); but_update.setBounds (643,473,75,25); but_help.setBounds (320,507,75,25); but_exit.setBounds (401,507,75,25); // enable/disable buttons but_help.setVisible(false); tf_date.setEnabled(false); but_delete.setEnabled(false); ta_message.setEditable(false); // focus this.requestFocus(); } //end of constructor public void paint(Graphics g) { g.drawImage(img,0,45,this); } // end of paint public void actionPerformed(ActionEvent e) { if(e.getSource()==but_exit) { this.dispose(); } // end of exit if(e.getSource()==but_retrieve) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_symbolcode1.getText() ); CallableStatement cstmt = con.prepareCall( "{call retrieve_symbol(?,?,?,?)}" ); cstmt.setInt(1,i); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); tf_symbolcode.setText( new Integer(i).toString() ); tf_symbol .setText(s2); tf_desc .setText(s3); tf_symbolcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Incorrect data entered / Row does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); tf_symbolcode.setText(""); tf_symbol.setText(""); tf_desc.setText(""); return; } }// end of but_retrieve if(e.getSource()==but_add) { try { ta_message.setText("ACTION: Adding new record ..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call insert_symbol(?,?,?)}" ); //set IN parameter cstmt.setInt(1,i); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.executeUpdate(); ta_message.setText("ACTION: Record Added."); } catch(Exception er) { ta_message.setText ("ERROR: Incorrect data entered / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } } // end of but_add if(e.getSource()==but_update) { try { ta_message.setText("ACTION: Updating record..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call update_symbol(?,?,?)}"); cstmt.setInt(1,i); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.executeUpdate(); ta_message.setText("ACTION: Record updated."); } catch(Exception er) { ta_message.setText ("ERROR: Incorrect data entered / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); } }// end of but_update if(e.getSource()==but_reset) { tf_symbolcode.setEnabled(true); tf_symbolcode1.setText(""); tf_symbolcode.setText(""); tf_symbol.setText(""); tf_desc.setText(""); ta_message.setText(""); tf_symbolcode.requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_symbol(?,?,?)}" ); cstmt.registerOutParameter(1,4); // integer cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); i = cstmt.getInt(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); tf_symbolcode1.setText( new Integer(i).toString() ); tf_symbolcode.setText( new Integer(i).toString() ); tf_symbol .setText(s2); tf_desc .setText(s3); tf_symbolcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Row does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_first if(e.getSource()==but_last) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call last_symbol(?,?,?)}" ); cstmt.registerOutParameter(1,4); // integer cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); i = cstmt.getInt(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); tf_symbolcode1.setText( new Integer(i).toString() ); tf_symbolcode.setText( new Integer(i).toString() ); tf_symbol .setText(s2); tf_desc .setText(s3); tf_symbolcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Row does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_last if(e.getSource()==but_previous) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_symbolcode.getText() ); CallableStatement cstmt = con.prepareCall( "{call previous_symbol(?,?,?,?)}" ); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.setInt(1,i); cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); tf_symbolcode1.setText( new Integer(i).toString() ); tf_symbolcode.setText( new Integer(i).toString() ); tf_symbol .setText(s2); tf_desc .setText(s3); tf_symbolcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Row does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_previous if(e.getSource()==but_next) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_symbolcode.getText() ); CallableStatement cstmt = con.prepareCall( "{call next_symbol(?,?,?,?)}" ); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.setInt(1,i); cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); tf_symbolcode1.setText( new Integer(i).toString() ); tf_symbolcode.setText( new Integer(i).toString() ); tf_symbol .setText(s2); tf_desc .setText(s3); tf_symbolcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Row does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_next }// action performed public static void main(String args[]) { } // end main public boolean getInput() throws Exception { s1 = tf_symbolcode.getText(); s2 = tf_symbol.getText(); s3 = tf_desc.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") ) { return false; } else { i = Validate.stringToInt(s1); return true; } }// end of getInput } // end class