import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.*; public class flight extends Frame implements ActionListener { public Toolkit tk; public Image img; public TextField tf_date; public flightdetails fd; public Panel Panel1; public Label lbl_routecode1; public TextField tf_routecode1; 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_routecode; public TextField tf_source; public TextField tf_destination; public TextField tf_via; public TextField tf_via2; 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,sqlstmt; public int i,ret; public flight(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Flight 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_routecode1 = new Label("Route code",Label.LEFT); tf_routecode1 = 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("Route code" ,Label.LEFT); lbl_2 = new Label("Source" ,Label.LEFT); lbl_3 = new Label("Destination",Label.LEFT); lbl_4 = new Label("Via" ,Label.LEFT); tf_routecode = new TextField(""); tf_source = new TextField(""); tf_destination = new TextField(""); tf_via = new TextField(""); tf_via2 = new TextField(""); but_addn = new Button("Flight Details"); 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 tf_date.setText( Validate.getDate() ); // Add()s add(tf_date); add(Panel1); Panel1.add(lbl_routecode1); Panel1.add(tf_routecode1); 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_routecode); Panel2.add(tf_source); Panel2.add(tf_destination); Panel2.add(tf_via); Panel2.add(tf_via2); 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 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_routecode1.setBounds (140, 27, 80,19); tf_routecode1.setBounds (221, 21, 70,27); but_retrieve.setBounds (332, 21, 75,25); Panel2.setBounds ( 60,240,680,180); lbl_1.setBounds ( 50,10, 80,20); lbl_2.setBounds (350,10,200,20); lbl_3.setBounds ( 50,65,200,20); lbl_4.setBounds (350,65,200,20); tf_routecode.setBounds ( 50,35, 60,25); tf_source.setBounds (350,35,200,25); tf_destination.setBounds ( 50,90,200,25); tf_via.setBounds (350,90,200,25); tf_via2.setBounds (350,140,200,25); but_addn.setBounds ( 50,140,200,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); 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) { if (fd != null) { fd.dispose(); } this.dispose(); } // end of exit if(e.getSource()==but_retrieve) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call retrieve_flight(?,?,?,?,?,?)}" ); cstmt.setString(1, tf_routecode1.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.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); tf_routecode1.setText(s1); tf_routecode.setText(s1); tf_source.setText(s2); tf_destination.setText(s3); tf_via.setText(s4); tf_via2.setText(s5); tf_routecode.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_flight(?,?,?,?,?)}" ); //set IN parameter cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setString(4,s4); cstmt.setString(5,s5); 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_flight(?,?,?,?,?)}" ); cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setString(4,s4); cstmt.setString(5,s5); 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..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call delete_flight(?)}" ); cstmt.setString(1,tf_routecode.getText()); 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) { tf_routecode .setEnabled(true); tf_routecode1 .setText(""); tf_routecode .setText(""); tf_source .setText(""); tf_destination .setText(""); tf_via .setText(""); tf_via2 .setText(""); ta_message .setText(""); tf_routecode .requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_flight(?,?,?,?,?)}" ); 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.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s4 = cstmt.getString(4); s5 = cstmt.getString(5); tf_routecode1.setText(s1); tf_routecode.setText(s1); tf_source.setText(s2); tf_destination.setText(s3); tf_via.setText(s4); tf_via2.setText(s5); tf_routecode.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_flight(?,?,?,?,?)}" ); 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.executeUpdate(); s1 = cstmt.getString(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s4 = cstmt.getString(4); s5 = cstmt.getString(5); tf_routecode1.setText(s1); tf_routecode.setText(s1); tf_source.setText(s2); tf_destination.setText(s3); tf_via.setText(s4); tf_via2.setText(s5); tf_routecode.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_flight(?,?,?,?,?,?)}" ); cstmt.setString(1,tf_routecode.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.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); tf_routecode1.setText(s1); tf_routecode.setText(s1); tf_source.setText(s2); tf_destination.setText(s3); tf_via.setText(s4); tf_via2.setText(s5); tf_routecode.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_flight(?,?,?,?,?,?)}" ); cstmt.setString(1, tf_routecode.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.executeUpdate(); s1 = cstmt.getString(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s4 = cstmt.getString(5); s5 = cstmt.getString(6); tf_routecode1.setText(s1); tf_routecode.setText(s1); tf_source.setText(s2); tf_destination.setText(s3); tf_via.setText(s4); tf_via2.setText(s5); tf_routecode.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_routecode.getText(); if (ss.trim().equals("") ) { ta_message.setText ("ERROR: Empty Flight code \n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } else { ta_message.setText ("FLIGHT DETAILS : Connected"); if (fd != null) { fd.dispose(); } fd = new flightdetails(con,ss); fd.setVisible(true); fd.requestFocus(); } } // end but_addn }// action performed public static void main(String args[]) { } // end main public boolean getInput() throws Exception { s1 = tf_routecode.getText(); s2 = tf_source.getText(); s3 = tf_destination.getText(); s4 = tf_via.getText(); s5 = tf_via2.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") | (s4 == "") | (s5 == "") ) { return false; } else { return true; } }// end of getInput } // end class