import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.* ; public class country extends Frame implements ActionListener { public Toolkit tk; public Image img; public TextField tf_date; public Panel Panel1; public Label lbl_countrycode1; public TextField tf_countrycode1; public Button but_retrieve; public Panel Panel2; public Label lbl_countrycode; public TextField tf_countrycode; public Label lbl_countryname; public TextField tf_countryname; 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 country(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Country 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_countrycode1 = new Label("Country Code",Label.LEFT); tf_countrycode1 = new TextField(""); but_retrieve = new Button("Retrieve"); Panel2 = new Panel(); Panel2.setLayout(null); Panel2.setForeground(Color.black); Panel2.setBackground(Color.gray); lbl_countrycode = new Label("Country Code",Label.LEFT); tf_countrycode = new TextField(""); lbl_countryname = new Label("Country Name",Label.LEFT); tf_countryname = 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_countrycode1); Panel1.add(tf_countrycode1); Panel1.add(but_retrieve); add(Panel2); Panel2.add(lbl_countrycode); Panel2.add(tf_countrycode); Panel2.add(tf_countryname); Panel2.add(lbl_countryname); 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_countrycode1.setBounds (90,27,130,19); tf_countrycode1.setBounds (221,21,70,27); but_retrieve.setBounds (332,25,75,25); Panel2.setBounds (148,239,504,115); lbl_countrycode.setBounds (100,12,130,19); tf_countrycode.setBounds (257,12,60,27); lbl_countryname.setBounds (100,60,130,19); tf_countryname.setBounds (257,60,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 ..."); CallableStatement cstmt = con.prepareCall( "{call retrieve_country(?,?,?)}" ); cstmt.setString(1,tf_countrycode1.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); tf_countrycode.setText(s1); tf_countryname.setText(s2); tf_countrycode.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 "); 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_country(?,?)}" ); //set IN parameter cstmt.setString(1,s1); cstmt.setString(2,s2); 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_country(?,?)}"); cstmt.setString(1,s1); cstmt.setString(2,s2); 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_countrycode.setEnabled(true); tf_countrycode1.setText(""); tf_countrycode.setText(""); tf_countryname.setText(""); ta_message.setText(""); tf_countrycode.requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_country(?,?)}" ); cstmt.registerOutParameter(1,12); // integer cstmt.registerOutParameter(2,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); tf_countrycode1.setText(s1); tf_countrycode.setText(s1); tf_countryname.setText(s2); tf_countrycode.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_country(?,?)}" ); cstmt.registerOutParameter(1,12); // integer cstmt.registerOutParameter(2,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); tf_countrycode1.setText(s1); tf_countrycode.setText(s1); tf_countryname.setText(s2); tf_countrycode.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 ..."); CallableStatement cstmt = con.prepareCall( "{call previous_country(?,?,?)}" ); cstmt.setString(1,tf_countrycode.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); tf_countrycode1.setText(s1); tf_countrycode.setText(s1); tf_countryname.setText(s2); tf_countrycode.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 ..."); CallableStatement cstmt = con.prepareCall( "{call next_country(?,?,?)}" ); cstmt.setString(1,tf_countrycode.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); tf_countrycode1.setText(s1); tf_countrycode.setText(s1); tf_countryname.setText(s2); tf_countrycode.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_countrycode.getText(); s2 = tf_countryname.getText(); if ( (s1 == "") | (s2 == "") ) { return false; } else { return true; } }// end of getInput } // end class