import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.*; public class flightdetails extends Frame implements ActionListener,ItemListener,FocusListener { public Panel Panel1; public Label lbl_1; public Label lbl_2; public Label lbl_3; public Label lbl_4; public Label lbl_5; public Label lbl_6; public TextField tf_routecode; public TextField tf_flightno; public TextField tf_mon; public TextField tf_tue; public TextField tf_wed; public TextField tf_thu; public TextField tf_fri; public TextField tf_sat; public TextField tf_sun; public TextField tf_acrcode1; public Choice ch_acrcode1; public TextField tf_acrcode2; public Choice ch_acrcode2; public TextField tf_city1; public TextField tf_city2; public TextField tf_city3; public TextField tf_city4; public TextField tf_city5; public TextField tf_remarks; 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,con1; public String ss,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,s15,s16,s17,sqlstmt; public int i,ret; public flightdetails(Connection c,String s) { con = c; ss = s; setResizable(false); setForeground(Color.black); // setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Flight Details"); setLayout(null); Panel1 = new Panel(); Panel1.setLayout(null); Panel1.setForeground(Color.black); Panel1.setBackground(Color.gray); lbl_1 = new Label("Route Code" ,Label.LEFT); lbl_2 = new Label("Flight No." ,Label.LEFT); lbl_3 = new Label(" M T W T F S S" ,Label.LEFT); lbl_4 = new Label("ACR-Type" ,Label.LEFT); lbl_5 = new Label("Via Cities" ,Label.LEFT); lbl_6 = new Label("Remarks" ,Label.LEFT); tf_routecode = new TextField(""); tf_flightno = new TextField(""); tf_mon = new TextField("."); tf_tue = new TextField("."); tf_wed = new TextField("."); tf_thu = new TextField("."); tf_fri = new TextField("."); tf_sat = new TextField("."); tf_sun = new TextField("."); tf_acrcode1 = new TextField(""); ch_acrcode1 = new Choice(); tf_acrcode2 = new TextField(""); ch_acrcode2 = new Choice(); tf_city1 = new TextField(""); tf_city2 = new TextField(""); tf_city3 = new TextField(""); tf_city4 = new TextField(""); tf_city5 = new TextField(""); tf_remarks = 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(""); tf_routecode.setText(ss); // set value of routecode // Add()s add(Panel1); Panel1.add(lbl_1); Panel1.add(lbl_2); Panel1.add(lbl_3); Panel1.add(lbl_4); Panel1.add(lbl_5); Panel1.add(lbl_6); Panel1.add(tf_routecode); Panel1.add(tf_flightno); Panel1.add(tf_mon); Panel1.add(tf_tue); Panel1.add(tf_wed); Panel1.add(tf_thu); Panel1.add(tf_fri); Panel1.add(tf_sat); Panel1.add(tf_sun); Panel1.add(tf_acrcode1); Panel1.add(ch_acrcode1); Panel1.add(tf_acrcode2); Panel1.add(ch_acrcode2); Panel1.add(tf_city1); Panel1.add(tf_city2); Panel1.add(tf_city3); Panel1.add(tf_city4); Panel1.add(tf_city5); Panel1.add(tf_remarks); 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 tf_acrcode1 .addFocusListener(this); ch_acrcode1 .addItemListener(this); tf_acrcode2 .addFocusListener(this); ch_acrcode2 .addItemListener(this); tf_city1 .addFocusListener(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,300,800,295); Panel1.setBounds (5,30,795,85); lbl_1.setBounds ( 10,10, 60,20); lbl_2.setBounds ( 80,10, 60,20); lbl_3.setBounds (145,10,210,20); lbl_4.setBounds (375,10, 60,20); lbl_5.setBounds (550,10, 80,20); lbl_6.setBounds (725,10, 80,20); tf_routecode .setBounds( 10,35, 60,25); tf_flightno .setBounds( 80,35, 65,25); tf_mon .setBounds(150,35, 30,25); tf_tue .setBounds(180,35, 30,25); tf_wed .setBounds(210,35, 30,25); tf_thu .setBounds(240,35, 30,25); tf_fri .setBounds(270,35, 30,25); tf_sat .setBounds(300,35, 30,25); tf_sun .setBounds(330,35, 30,25); tf_acrcode1 .setBounds(365,35, 40,25); ch_acrcode1 .setBounds(365,60, 50,25); tf_acrcode2 .setBounds(405,35, 40,25); ch_acrcode2 .setBounds(405,60, 50,25); tf_city1 .setBounds(460,35, 50,25); tf_city2 .setBounds(510,35, 50,25); tf_city3 .setBounds(560,35, 50,25); tf_city4 .setBounds(610,35, 50,25); tf_city5 .setBounds(660,35, 50,25); tf_remarks .setBounds(720,35, 60,25); but_first.setBounds (60,120,75,25); but_previous.setBounds (60,150,75,25); but_next.setBounds (60,180,75,25); but_last.setBounds (60,210,75,25); lbl_message.setBounds (190,120,200,20); ta_message.setBounds (190,150,385,100); but_reset.setBounds (620,120,75,25); but_add.setBounds (620,150,75,25); but_delete.setBounds (620,180,75,25); but_update.setBounds (620,210,75,25); but_help.setBounds (290,260,75,25); but_exit.setBounds (370,260,75,25); // enable/disable buttons but_help.setVisible(false); tf_routecode.setEnabled(false); ch_acrcode1.setVisible(false); ch_acrcode2.setVisible(false); ta_message.setEditable(false); // retrieveAircraft (acr_codes) retrieveAircraft(ch_acrcode1); retrieveAircraft(ch_acrcode2); // focus this.requestFocus(); } //end of constructor // retrieve acr codes public void retrieveAircraft(Choice ch) { try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select acr_code from aircraft"); ch.removeAll(); while (rs.next()) { String code = rs.getString(1); ch.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 acr code retrieve } // end of retrieveAircraft() public void focusGained(FocusEvent e) { if(e.getSource()==tf_sun) { ch_acrcode1.setVisible(false); ch_acrcode2.setVisible(false); } if(e.getSource()==tf_acrcode1) { ch_acrcode1.setVisible(true); ch_acrcode2.setVisible(false); } if(e.getSource()==tf_acrcode2) { ch_acrcode1.setVisible(false); ch_acrcode2.setVisible(true); } if(e.getSource()==tf_city1) { ch_acrcode1.setVisible(false); ch_acrcode2.setVisible(false); } } // end of focusgained public void focusLost(FocusEvent e) { if(e.getSource()==tf_routecode) { } } // end of focuslost public void itemStateChanged(ItemEvent e) { if(e.getSource()==ch_acrcode1) { tf_acrcode1.setText( ch_acrcode1.getSelectedItem() ); ch_acrcode1.setVisible(false); } if(e.getSource()==ch_acrcode2) { tf_acrcode2.setText( ch_acrcode2.getSelectedItem() ); ch_acrcode2.setVisible(false); } } // end of itemstatechanged public void actionPerformed(ActionEvent e) { if(e.getSource()==but_exit) { this.dispose(); } // end of exit if(e.getSource()==but_add) { try { ta_message.setText("ACTION: Adding new record ..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call insert_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); //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.setString(13,s13); cstmt.setString(14,s14); cstmt.setString(15,s15); cstmt.setString(16,s16); cstmt.setString(17,s17); 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_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); 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.setString(13,s13); cstmt.setString(14,s14); cstmt.setString(15,s15); cstmt.setString(16,s16); cstmt.setString(17,s17); cstmt.setInt(18,i); 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_delete) { try { ta_message.setText("ACTION: Deleting record..."); CallableStatement cstmt = con.prepareCall( "{call delete_flightdetails(?)}" ); cstmt.setInt(1,i); cstmt.executeUpdate(); ta_message.setText("ACTION: Record deleted."); } 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_delete if(e.getSource()==but_reset) { i = 0 ; tf_routecode.setEnabled(false); tf_flightno .setEnabled(true); tf_flightno .setText(""); tf_mon .setText("."); tf_tue .setText("."); tf_wed .setText("."); tf_thu .setText("."); tf_fri .setText("."); tf_sat .setText("."); tf_sun .setText("."); tf_acrcode1 .setText(""); tf_acrcode2 .setText(""); tf_city1 .setText(""); tf_city2 .setText(""); tf_city3 .setText(""); tf_city4 .setText(""); tf_city5 .setText(""); tf_remarks .setText(""); ta_message .setText(""); ch_acrcode1 .setVisible(false); ch_acrcode2 .setVisible(false); tf_flightno .requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1,tf_routecode.getText()); cstmt.registerOutParameter(2,4 ); cstmt.registerOutParameter(3,12); cstmt.registerOutParameter(4,12); cstmt.registerOutParameter(5,12); cstmt.registerOutParameter(6,12); cstmt.registerOutParameter(7,12); cstmt.registerOutParameter(8,12); cstmt.registerOutParameter(9,12); cstmt.registerOutParameter(10,12); cstmt.registerOutParameter(11,12); cstmt.registerOutParameter(12,12); cstmt.registerOutParameter(13,12); cstmt.registerOutParameter(14,12); cstmt.registerOutParameter(15,12); cstmt.registerOutParameter(16,12); cstmt.registerOutParameter(17,12); cstmt.registerOutParameter(18,12); cstmt.registerOutParameter(19,12); cstmt.executeUpdate(); i = cstmt.getInt(2); s1 = cstmt.getString(3); s2 = cstmt.getString(4); s3 = cstmt.getString(5); s4 = cstmt.getString(6); s5 = cstmt.getString(7); s6 = cstmt.getString(8); s7 = cstmt.getString(9); s8 = cstmt.getString(10); s9 = cstmt.getString(11); s10= cstmt.getString(12); s11= cstmt.getString(13); s12= cstmt.getString(14); s13= cstmt.getString(15); s14= cstmt.getString(16); s15= cstmt.getString(17); s16= cstmt.getString(18); s17= cstmt.getString(19); tf_routecode.setText(s1); tf_flightno.setText(s2); tf_mon.setText(s3); tf_tue.setText(s4); tf_wed.setText(s5); tf_thu.setText(s6); tf_fri.setText(s7); tf_sat.setText(s8); tf_sun.setText(s9); tf_acrcode1.setText(s10); tf_acrcode2.setText(s11); tf_city1.setText(s12); tf_city2.setText(s13); tf_city3.setText(s14); tf_city4.setText(s15); tf_city5.setText(s16); tf_remarks.setText(s17); tf_routecode.setEnabled(false); tf_flightno.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_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1,tf_routecode.getText()); cstmt.registerOutParameter(2,4 ); cstmt.registerOutParameter(3,12); cstmt.registerOutParameter(4,12); cstmt.registerOutParameter(5,12); cstmt.registerOutParameter(6,12); cstmt.registerOutParameter(7,12); cstmt.registerOutParameter(8,12); cstmt.registerOutParameter(9,12); cstmt.registerOutParameter(10,12); cstmt.registerOutParameter(11,12); cstmt.registerOutParameter(12,12); cstmt.registerOutParameter(13,12); cstmt.registerOutParameter(14,12); cstmt.registerOutParameter(15,12); cstmt.registerOutParameter(16,12); cstmt.registerOutParameter(17,12); cstmt.registerOutParameter(18,12); cstmt.registerOutParameter(19,12); cstmt.executeUpdate(); i = cstmt.getInt(2); s1 = cstmt.getString(3); s2 = cstmt.getString(4); s3 = cstmt.getString(5); s4 = cstmt.getString(6); s5 = cstmt.getString(7); s6 = cstmt.getString(8); s7 = cstmt.getString(9); s8 = cstmt.getString(10); s9 = cstmt.getString(11); s10= cstmt.getString(12); s11= cstmt.getString(13); s12= cstmt.getString(14); s13= cstmt.getString(15); s14= cstmt.getString(16); s15= cstmt.getString(17); s16= cstmt.getString(18); s17= cstmt.getString(19); tf_routecode.setText(s1); tf_flightno.setText(s2); tf_mon.setText(s3); tf_tue.setText(s4); tf_wed.setText(s5); tf_thu.setText(s6); tf_fri.setText(s7); tf_sat.setText(s8); tf_sun.setText(s9); tf_acrcode1.setText(s10); tf_acrcode2.setText(s11); tf_city1.setText(s12); tf_city2.setText(s13); tf_city3.setText(s14); tf_city4.setText(s15); tf_city5.setText(s16); tf_remarks.setText(s17); tf_routecode.setEnabled(false); tf_flightno.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_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setInt(1,i); cstmt.setString(2,tf_routecode.getText()); cstmt.registerOutParameter(3,4 ); cstmt.registerOutParameter(4,12); cstmt.registerOutParameter(5,12); cstmt.registerOutParameter(6,12); cstmt.registerOutParameter(7,12); cstmt.registerOutParameter(8,12); cstmt.registerOutParameter(9,12); cstmt.registerOutParameter(10,12); cstmt.registerOutParameter(11,12); cstmt.registerOutParameter(12,12); cstmt.registerOutParameter(13,12); cstmt.registerOutParameter(14,12); cstmt.registerOutParameter(15,12); cstmt.registerOutParameter(16,12); cstmt.registerOutParameter(17,12); cstmt.registerOutParameter(18,12); cstmt.registerOutParameter(19,12); cstmt.registerOutParameter(20,12); cstmt.executeUpdate(); i = cstmt.getInt(3); s1 = cstmt.getString(4); s2 = cstmt.getString(5); s3 = cstmt.getString(6); s4 = cstmt.getString(7); s5 = cstmt.getString(8); s6 = cstmt.getString(9); s7 = cstmt.getString(10); s8 = cstmt.getString(11); s9 = cstmt.getString(12); s10= cstmt.getString(13); s11= cstmt.getString(14); s12= cstmt.getString(15); s13= cstmt.getString(16); s14= cstmt.getString(17); s15= cstmt.getString(18); s16= cstmt.getString(19); s17= cstmt.getString(20); tf_routecode.setText(s1); tf_flightno.setText(s2); tf_mon.setText(s3); tf_tue.setText(s4); tf_wed.setText(s5); tf_thu.setText(s6); tf_fri.setText(s7); tf_sat.setText(s8); tf_sun.setText(s9); tf_acrcode1.setText(s10); tf_acrcode2.setText(s11); tf_city1.setText(s12); tf_city2.setText(s13); tf_city3.setText(s14); tf_city4.setText(s15); tf_city5.setText(s16); tf_remarks.setText(s17); tf_routecode.setEnabled(false); tf_flightno.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_flightdetails(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}" ); cstmt.setInt(1,i); cstmt.setString(2,tf_routecode.getText()); cstmt.registerOutParameter(3,4 ); cstmt.registerOutParameter(4,12); cstmt.registerOutParameter(5,12); cstmt.registerOutParameter(6,12); cstmt.registerOutParameter(7,12); cstmt.registerOutParameter(8,12); cstmt.registerOutParameter(9,12); cstmt.registerOutParameter(10,12); cstmt.registerOutParameter(11,12); cstmt.registerOutParameter(12,12); cstmt.registerOutParameter(13,12); cstmt.registerOutParameter(14,12); cstmt.registerOutParameter(15,12); cstmt.registerOutParameter(16,12); cstmt.registerOutParameter(17,12); cstmt.registerOutParameter(18,12); cstmt.registerOutParameter(19,12); cstmt.registerOutParameter(20,12); cstmt.executeUpdate(); i = cstmt.getInt(3); s1 = cstmt.getString(4); s2 = cstmt.getString(5); s3 = cstmt.getString(6); s4 = cstmt.getString(7); s5 = cstmt.getString(8); s6 = cstmt.getString(9); s7 = cstmt.getString(10); s8 = cstmt.getString(11); s9 = cstmt.getString(12); s10= cstmt.getString(13); s11= cstmt.getString(14); s12= cstmt.getString(15); s13= cstmt.getString(16); s14= cstmt.getString(17); s15= cstmt.getString(18); s16= cstmt.getString(19); s17= cstmt.getString(20); tf_routecode.setText(s1); tf_flightno.setText(s2); tf_mon.setText(s3); tf_tue.setText(s4); tf_wed.setText(s5); tf_thu.setText(s6); tf_fri.setText(s7); tf_sat.setText(s8); tf_sun.setText(s9); tf_acrcode1.setText(s10); tf_acrcode2.setText(s11); tf_city1.setText(s12); tf_city2.setText(s13); tf_city3.setText(s14); tf_city4.setText(s15); tf_city5.setText(s16); tf_remarks.setText(s17); tf_routecode.setEnabled(false); tf_flightno.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_routecode.getText(); s2 = tf_flightno.getText(); s3 = tf_mon.getText(); s4 = tf_tue.getText(); s5 = tf_wed.getText(); s6 = tf_thu.getText(); s7 = tf_fri.getText(); s8 = tf_sat.getText(); s9 = tf_sun.getText(); s10= tf_acrcode1.getText(); s11= tf_acrcode2.getText(); s12= tf_city1.getText(); s13= tf_city2.getText(); s14= tf_city3.getText(); s15= tf_city4.getText(); s16= tf_city5.getText(); s17= tf_remarks.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") | (s4 == "") | (s5 == "") | (s6 == "") | (s7 == "") | (s8 == "") | (s9 == "") | (s10 == "") | (s11 == "") | (s12 == "") | (s13 == "") ) { return false; } else { return true; } }// end of getInput } // end class