import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.* ; public class aircraft extends Frame implements ActionListener { public Toolkit tk; public Image img; public TextField tf_date; public Panel Panel1; public Label lbl_acrcode1; public TextField tf_acrcode1; public Button but_retrieve; public Panel Panel2; public Label lbl_aircraft; public Label lbl_first; public Label lbl_executive; public Label lbl_economic; public Label lbl_acrcode; public TextField tf_acrcode; public Label lbl_acrnumber; public TextField tf_acrnumber; public Label lbl_fircode; public TextField tf_fircode; public Label lbl_firclass; public TextField tf_firclass; public Label lbl_execode; public TextField tf_execode; public Label lbl_execlass; public TextField tf_execlass; public Label lbl_ecocode; public TextField tf_ecocode; public Label lbl_ecoclass; public TextField tf_ecoclass; 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,s4,s5,s6,s7,s8,sqlstmt; public int i4,i6,i8,ret; public aircraft(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Aircraft 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_acrcode1 = new Label("Air Craft Code",Label.LEFT); tf_acrcode1 = new TextField(""); but_retrieve = new Button("Retrieve"); Panel2 = new Panel(); Panel2.setLayout(null); Panel2.setForeground(Color.black); Panel2.setBackground(Color.gray); lbl_aircraft = new Label("A I R C R A F T",Label.LEFT); lbl_first = new Label("FIRST" ,Label.LEFT); lbl_executive = new Label("EXECUTIVE",Label.LEFT); lbl_economic = new Label("ECONOMIC" ,Label.LEFT); lbl_acrcode = new Label("Code",Label.LEFT); tf_acrcode = new TextField(""); lbl_acrnumber = new Label("Number",Label.LEFT); tf_acrnumber = new TextField(""); lbl_fircode = new Label("Code",Label.LEFT); tf_fircode = new TextField("F"); lbl_firclass = new Label("Class",Label.LEFT); tf_firclass = new TextField(""); lbl_execode = new Label("Code",Label.LEFT); tf_execode = new TextField("J"); lbl_execlass = new Label("Class",Label.LEFT); tf_execlass = new TextField(""); lbl_ecocode = new Label("Code",Label.LEFT); tf_ecocode = new TextField("Y"); lbl_ecoclass = new Label("Class",Label.LEFT); tf_ecoclass = 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_acrcode1); Panel1.add(tf_acrcode1); Panel1.add(but_retrieve); add(Panel2); Panel2.add(lbl_aircraft); Panel2.add(lbl_first); Panel2.add(lbl_executive); Panel2.add(lbl_economic); Panel2.add(lbl_acrcode); Panel2.add(tf_acrcode); Panel2.add(tf_acrnumber); Panel2.add(lbl_acrnumber); Panel2.add(lbl_fircode); Panel2.add(tf_fircode); Panel2.add(lbl_firclass); Panel2.add(tf_firclass); Panel2.add(lbl_execode); Panel2.add(tf_execode); Panel2.add(lbl_execlass); Panel2.add(tf_execlass); Panel2.add(lbl_ecocode); Panel2.add(tf_ecocode); Panel2.add(lbl_ecoclass); Panel2.add(tf_ecoclass); 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_acrcode1.setBounds ( 90, 27,130,19); tf_acrcode1.setBounds (221, 21, 70,27); but_retrieve.setBounds (332, 21, 75,25); Panel2.setBounds (60,239,680,115); lbl_aircraft.setBounds (80,10,100,20); lbl_acrcode.setBounds (70,30,50,20); tf_acrcode.setBounds (70,55,50,25); lbl_acrnumber.setBounds (130,30, 50,20); tf_acrnumber.setBounds (130,55,180,25); lbl_first.setBounds (350,10, 40,20); lbl_fircode.setBounds (330,30, 30,20); tf_fircode.setBounds (330,55, 30,25); lbl_firclass.setBounds (370,30, 40,20); tf_firclass.setBounds (370,55, 40,25); lbl_executive.setBounds (440,10, 70,20); lbl_execode.setBounds (430,30, 30,20); tf_execode.setBounds (430,55, 30,25); lbl_execlass.setBounds (470,30, 40,20); tf_execlass.setBounds (470,55, 40,25); lbl_economic.setBounds (540,10, 70,20); lbl_ecocode.setBounds (530,30, 30,20); tf_ecocode.setBounds (530,55, 30,25); lbl_ecoclass.setBounds (570,30, 40,20); tf_ecoclass.setBounds (570,55, 40,25); 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_aircraft(?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1, tf_acrcode1.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.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); tf_acrcode1.setText(s1); tf_acrcode.setText(s1); tf_acrnumber.setText(s2); tf_fircode.setText(s3); tf_firclass.setText(s4); tf_execode.setText(s5); tf_execlass.setText(s6); tf_ecocode.setText(s7); tf_ecoclass.setText(s8); tf_acrcode.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_acrcode.setText(""); tf_acrnumber.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_aircraft(?,?,?,?,?,?,?,?)}" ); //set IN parameter cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setInt(4,i4); cstmt.setString(5,s5); cstmt.setInt(6,i6); cstmt.setString(7,s7); cstmt.setInt(8,i8); 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_aircraft(?,?,?,?,?,?,?,?)}"); cstmt.setString(1,s1); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.setInt(4,i4); cstmt.setString(5,s5); cstmt.setInt(6,i6); cstmt.setString(7,s7); cstmt.setInt(8,i8); 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_acrcode .setEnabled(true); tf_acrcode1 .setText(""); tf_acrcode .setText(""); tf_acrnumber .setText(""); tf_fircode .setText("F"); tf_firclass .setText(""); tf_execode .setText("J"); tf_execlass .setText(""); tf_ecocode .setText("Y"); tf_ecoclass .setText(""); ta_message .setText(""); tf_acrcode .requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_aircraft(?,?,?,?,?,?,?,?)}" ); 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.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); tf_acrcode1.setText(s1); tf_acrcode.setText(s1); tf_acrnumber.setText(s2); tf_fircode.setText(s3); tf_firclass.setText(s4); tf_execode.setText(s5); tf_execlass.setText(s6); tf_ecocode.setText(s7); tf_ecoclass.setText(s8); tf_acrcode.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_aircraft(?,?,?,?,?,?,?,?)}" ); 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.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); tf_acrcode1.setText(s1); tf_acrcode.setText(s1); tf_acrnumber.setText(s2); tf_fircode.setText(s3); tf_firclass.setText(s4); tf_execode.setText(s5); tf_execlass.setText(s6); tf_ecocode.setText(s7); tf_ecoclass.setText(s8); tf_acrcode.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_aircraft(?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1, tf_acrcode.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.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); tf_acrcode1.setText(s1); tf_acrcode.setText(s1); tf_acrnumber.setText(s2); tf_fircode.setText(s3); tf_firclass.setText(s4); tf_execode.setText(s5); tf_execlass.setText(s6); tf_ecocode.setText(s7); tf_ecoclass.setText(s8); tf_acrcode.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_aircraft(?,?,?,?,?,?,?,?,?)}" ); cstmt.setString(1, tf_acrcode.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.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); tf_acrcode1.setText(s1); tf_acrcode.setText(s1); tf_acrnumber.setText(s2); tf_fircode.setText(s3); tf_firclass.setText(s4); tf_execode.setText(s5); tf_execlass.setText(s6); tf_ecocode.setText(s7); tf_ecoclass.setText(s8); tf_acrcode.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_acrcode.getText(); s2 = tf_acrnumber.getText(); s3 = tf_fircode.getText(); s4 = tf_firclass.getText(); s5 = tf_execode.getText(); s6 = tf_execlass.getText(); s7 = tf_ecocode.getText(); s8 = tf_ecoclass.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") | (s4 == "") | (s5 == "") | (s6 == "") | (s7 == "") | (s8 == "") ) { return false; } else { i4 = Validate.stringToInt(s4); i6 = Validate.stringToInt(s6); i8 = Validate.stringToInt(s8); return true; } }// end of getInput } // end class