import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.*; public class city extends Frame implements ActionListener,ItemListener,FocusListener { public Toolkit tk; public Image img; public TextField tf_date; public cityperson cp; public Panel Panel1; public Label lbl_shortname1; public TextField tf_shortname1; public Button but_retrieve; public Panel Panel2; public Label lbl_1; public Label lbl_2; public Label lbl_3; public Label lbl_4; public TextField tf_citycode; public TextField tf_cityname; public TextField tf_shortname; public TextField tf_parttype; public Label lbl_5; public Label lbl_6; public Label lbl_7; public Label lbl_8; public Choice ch_countrycode; public TextField tf_countrycode; public TextField tf_gmt; public TextField tf_cityaddr1; public TextField tf_cityaddr2; public TextField tf_cityaddr3; public TextField tf_airaddr1; public TextField tf_airaddr2; public TextField tf_airaddr3; public Button but_addn; 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 ss,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,sqlstmt; public int i,ret; public city(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("City 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_shortname1 = new Label("Short Name",Label.LEFT); tf_shortname1 = new TextField(""); but_retrieve = new Button("Retrieve"); Panel2 = new Panel(); Panel2.setLayout(null); Panel2.setForeground(Color.black); Panel2.setBackground(Color.gray); lbl_1 = new Label("City code" ,Label.LEFT); lbl_2 = new Label("City name" ,Label.LEFT); lbl_3 = new Label("Short name",Label.LEFT); lbl_4 = new Label("Part type" ,Label.LEFT); lbl_5 = new Label("Country" ,Label.LEFT); lbl_6 = new Label("G M T" ,Label.LEFT); lbl_7 = new Label("City Address" ,Label.LEFT); lbl_8 = new Label("Airport Address" ,Label.LEFT); tf_citycode = new TextField(""); tf_cityname = new TextField(""); tf_shortname = new TextField(""); tf_parttype = new TextField(""); ch_countrycode = new Choice(); tf_countrycode = new TextField(""); tf_gmt = new TextField(""); tf_cityaddr1 = new TextField(""); tf_cityaddr2 = new TextField(""); tf_cityaddr3 = new TextField(""); tf_airaddr1 = new TextField(""); tf_airaddr2 = new TextField(""); tf_airaddr3 = new TextField(""); but_addn = new Button("Cityperson Information"); 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_shortname1); Panel1.add(tf_shortname1); Panel1.add(but_retrieve); add(Panel2); Panel2.add(lbl_1); Panel2.add(lbl_2); Panel2.add(lbl_3); Panel2.add(lbl_4); Panel2.add(tf_citycode); Panel2.add(tf_cityname); Panel2.add(tf_shortname); Panel2.add(tf_parttype); Panel2.add(lbl_5); Panel2.add(lbl_6); Panel2.add(lbl_7); Panel2.add(lbl_8); Panel2.add(ch_countrycode); Panel2.add(tf_countrycode); Panel2.add(tf_gmt); Panel2.add(tf_cityaddr1); Panel2.add(tf_cityaddr2); Panel2.add(tf_cityaddr3); Panel2.add(tf_airaddr1); Panel2.add(tf_airaddr2); Panel2.add(tf_airaddr3); Panel2.add(but_addn); 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 ch_countrycode .addItemListener(this); tf_countrycode .addFocusListener(this); tf_gmt .addFocusListener(this); but_retrieve .addActionListener(this); but_addn .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_shortname1.setBounds (140, 27, 80,19); tf_shortname1.setBounds (221, 21, 70,27); but_retrieve.setBounds (332, 21, 75,25); Panel2.setBounds ( 60,240,680,180); lbl_1.setBounds ( 50,10, 60,20); lbl_2.setBounds (130,10,200,20); lbl_3.setBounds (350,10, 80,20); lbl_4.setBounds (450,10,120,20); tf_citycode.setBounds ( 50,32, 60,25); tf_cityname.setBounds (130,32,200,25); tf_shortname.setBounds (350,32, 80,25); tf_parttype.setBounds (450,32,120,25); lbl_5.setBounds ( 50,60, 60,20); lbl_6.setBounds (130,60, 80,20); lbl_7.setBounds (230,60,200,20); lbl_8.setBounds (450,60,200,20); tf_countrycode.setBounds ( 50, 80, 60,25); ch_countrycode.setBounds ( 50,105, 60,25); tf_gmt.setBounds (130, 80, 80,25); tf_cityaddr1.setBounds (230, 80,200,25); tf_cityaddr2.setBounds (230,105,200,25); tf_cityaddr3.setBounds (230,130,200,25); tf_airaddr1.setBounds (450, 80,200,25); tf_airaddr2.setBounds (450,105,200,25); tf_airaddr3.setBounds (450,130,200,25); but_addn.setBounds ( 50,130,160,25); but_first.setBounds (90,440,75,25); but_previous.setBounds (90,470,75,25); but_next.setBounds (90,500,75,25); but_last.setBounds (90,530,75,25); lbl_message.setBounds (210,440,200,20); ta_message.setBounds (210,460,385,100); but_reset.setBounds (645,440,75,25); but_add.setBounds (645,470,75,25); but_delete.setBounds (645,500,75,25); but_update.setBounds (645,530,75,25); but_help.setBounds (320,564,75,25); but_exit.setBounds (400,564,75,25); // enable/disable buttons but_help.setVisible(false); tf_date.setEnabled(false); but_delete.setEnabled(false); ch_countrycode.setVisible(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 focusGained(FocusEvent e) { if(e.getSource()==tf_countrycode) { retrieveCountry(); ch_countrycode.setVisible(true); } if(e.getSource()==tf_gmt) { ch_countrycode.setVisible(false); } } // end of focusgained public void focusLost(FocusEvent e) { } // end of focuslost public void itemStateChanged(ItemEvent e) { if(e.getSource()==ch_countrycode) { tf_countrycode.setText( ch_countrycode.getSelectedItem() ); ch_countrycode.setVisible(false); } } // end of itemstatechanged // retrieve country codes public void retrieveCountry() { try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select country_code from country"); ch_countrycode.removeAll(); while (rs.next()) { String code = rs.getString(1); ch_countrycode.addItem(code); } } 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 country code retrieve } // end of retrieveCountry public void actionPerformed(ActionEvent e) { if(e.getSource()==but_exit) { if (cp != null) { cp.dispose(); } this.dispose(); } // end of exit if(e.getSource()==but_retrieve) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call retrieve_city(?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1, tf_shortname1.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.registerOutParameter(5,12); // string cstmt.registerOutParameter(6,12); // string cstmt.registerOutParameter(7,12); // string cstmt.registerOutParameter(8,12); // string cstmt.registerOutParameter(9,12); // string cstmt.registerOutParameter(10,12); // string cstmt.registerOutParameter(11,12); // string cstmt.registerOutParameter(12,12); // string cstmt.registerOutParameter(13,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); s6 = cstmt.getString(7); s7 = cstmt.getString(8); s8 = cstmt.getString(9); s9 = cstmt.getString(10); s10= cstmt.getString(11); s11= cstmt.getString(12); s12= cstmt.getString(13); tf_shortname1.setText(s3); tf_citycode.setText(s1); tf_cityname.setText(s2); tf_shortname.setText(s3); tf_parttype.setText(s4); tf_countrycode.setText(s5); tf_gmt.setText(s6); tf_cityaddr1.setText(s7); tf_cityaddr2.setText(s8); tf_cityaddr3.setText(s9); tf_airaddr1.setText(s10); tf_airaddr2.setText(s11); tf_airaddr3.setText(s12); tf_shortname.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_city(?,?,?,?,?,?,?,?,?,?,?,?)}" ); //set IN parameter cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setString(4,s4); cstmt.setString(5,s5); cstmt.setString(6,s6); cstmt.setString(7,s7); cstmt.setString(8,s8); cstmt.setString(9,s9); cstmt.setString(10,s10); cstmt.setString(11,s11); cstmt.setString(12,s12); 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_city(?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setString(4,s4); cstmt.setString(5,s5); cstmt.setString(6,s6); cstmt.setString(7,s7); cstmt.setString(8,s8); cstmt.setString(9,s9); cstmt.setString(10,s10); cstmt.setString(11,s11); cstmt.setString(12,s12); 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_citycode .setEnabled(true); tf_shortname1 .setText(""); tf_citycode .setText(""); tf_cityname .setText(""); tf_shortname .setText(""); tf_parttype .setText(""); tf_countrycode .setText(""); tf_gmt .setText(""); tf_cityaddr1 .setText(""); tf_cityaddr2 .setText(""); tf_cityaddr3 .setText(""); tf_airaddr1 .setText(""); tf_airaddr2 .setText(""); tf_airaddr3 .setText(""); ta_message .setText(""); ch_countrycode .setVisible(false); tf_citycode .requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_city(?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.registerOutParameter(1,12); // string cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.registerOutParameter(5,12); // string cstmt.registerOutParameter(6,12); // string cstmt.registerOutParameter(7,12); // string cstmt.registerOutParameter(8,12); // string cstmt.registerOutParameter(9,12); // string cstmt.registerOutParameter(10,12); // string cstmt.registerOutParameter(11,12); // string cstmt.registerOutParameter(12,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s4 = cstmt.getString(4); s5 = cstmt.getString(5); s6 = cstmt.getString(6); s7 = cstmt.getString(7); s8 = cstmt.getString(8); s9 = cstmt.getString(9); s10= cstmt.getString(10); s11= cstmt.getString(11); s12= cstmt.getString(12); tf_shortname1.setText(s3); tf_citycode.setText(s1); tf_cityname.setText(s2); tf_shortname.setText(s3); tf_parttype.setText(s4); tf_countrycode.setText(s5); tf_gmt.setText(s6); tf_cityaddr1.setText(s7); tf_cityaddr2.setText(s8); tf_cityaddr3.setText(s9); tf_airaddr1.setText(s10); tf_airaddr2.setText(s11); tf_airaddr3.setText(s12); tf_shortname.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_city(?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.registerOutParameter(1,12); // string cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.registerOutParameter(5,12); // string cstmt.registerOutParameter(6,12); // string cstmt.registerOutParameter(7,12); // string cstmt.registerOutParameter(8,12); // string cstmt.registerOutParameter(9,12); // string cstmt.registerOutParameter(10,12); // string cstmt.registerOutParameter(11,12); // string cstmt.registerOutParameter(12,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s4 = cstmt.getString(4); s5 = cstmt.getString(5); s6 = cstmt.getString(6); s7 = cstmt.getString(7); s8 = cstmt.getString(8); s9 = cstmt.getString(9); s10= cstmt.getString(10); s11= cstmt.getString(11); s12= cstmt.getString(12); tf_shortname1.setText(s3); tf_citycode.setText(s1); tf_cityname.setText(s2); tf_shortname.setText(s3); tf_parttype.setText(s4); tf_countrycode.setText(s5); tf_gmt.setText(s6); tf_cityaddr1.setText(s7); tf_cityaddr2.setText(s8); tf_cityaddr3.setText(s9); tf_airaddr1.setText(s10); tf_airaddr2.setText(s11); tf_airaddr3.setText(s12); tf_shortname.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_city(?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1,tf_shortname.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.registerOutParameter(5,12); // string cstmt.registerOutParameter(6,12); // string cstmt.registerOutParameter(7,12); // string cstmt.registerOutParameter(8,12); // string cstmt.registerOutParameter(9,12); // string cstmt.registerOutParameter(10,12); // string cstmt.registerOutParameter(11,12); // string cstmt.registerOutParameter(12,12); // string cstmt.registerOutParameter(13,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); s6 = cstmt.getString(7); s7 = cstmt.getString(8); s8 = cstmt.getString(9); s9 = cstmt.getString(10); s10= cstmt.getString(11); s11= cstmt.getString(12); s12= cstmt.getString(13); tf_shortname1.setText(s3); tf_citycode.setText(s1); tf_cityname.setText(s2); tf_shortname.setText(s3); tf_parttype.setText(s4); tf_countrycode.setText(s5); tf_gmt.setText(s6); tf_cityaddr1.setText(s7); tf_cityaddr2.setText(s8); tf_cityaddr3.setText(s9); tf_airaddr1.setText(s10); tf_airaddr2.setText(s11); tf_airaddr3.setText(s12); tf_shortname.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_city(?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1, tf_shortname.getText()); cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.registerOutParameter(5,12); // string cstmt.registerOutParameter(6,12); // string cstmt.registerOutParameter(7,12); // string cstmt.registerOutParameter(8,12); // string cstmt.registerOutParameter(9,12); // string cstmt.registerOutParameter(10,12); // string cstmt.registerOutParameter(11,12); // string cstmt.registerOutParameter(12,12); // string cstmt.registerOutParameter(13,12); // string cstmt.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); s6 = cstmt.getString(7); s7 = cstmt.getString(8); s8 = cstmt.getString(9); s9 = cstmt.getString(10); s10 = cstmt.getString(11); s11 = cstmt.getString(12); s12 = cstmt.getString(13); tf_shortname1.setText(s3); tf_citycode.setText(s1); tf_cityname.setText(s2); tf_shortname.setText(s3); tf_parttype.setText(s4); tf_countrycode.setText(s5); tf_gmt.setText(s6); tf_cityaddr1.setText(s7); tf_cityaddr2.setText(s8); tf_cityaddr3.setText(s9); tf_airaddr1.setText(s10); tf_airaddr2.setText(s11); tf_airaddr3.setText(s12); tf_shortname.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 if(e.getSource()==but_addn) { ss = tf_shortname.getText(); if (ss.trim().equals("") ) { ta_message.setText ("ERROR: Empty Short name \n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } else { ta_message.setText ("CITYPERSON : Connected"); if (cp != null) { cp.dispose() ; } cp = new cityperson(con,ss); cp.setVisible(true); cp.requestFocus(); } } // end but_addn }// action performed public static void main(String args[]) { } // end main public boolean getInput() throws Exception { s1 = tf_citycode.getText(); s2 = tf_cityname.getText(); s3 = tf_shortname.getText(); s4 = tf_parttype.getText(); s5 = tf_countrycode.getText(); s6 = tf_gmt.getText(); s7 = tf_cityaddr1.getText(); s8 = tf_cityaddr2.getText(); s9 = tf_cityaddr3.getText(); s10= tf_airaddr1.getText(); s11= tf_airaddr2.getText(); s12= tf_airaddr3.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") | (s4 == "") | (s5 == "") | (s6 == "") | (s7 == "") | (s10 == "") ) { return false; } else { return true; } }// end of getInput } // end class