public void actionPerformed(ActionEvent ae) { if (ae.getSource() == b1) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123"); PreparedStatement ps = con.prepareStatement("select * from LoginForm where username=? and password=?"); String UserName = t1.getText(); String Password = jp1.getText(); ps.setString(1, UserName); ps.setString(2, Password); ResultSet rs = ps.executeQuery(); boolean flag = rs.next(); if (flag) { new Main(); f.setVisible(false); } else { JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password"); } } catch (Exception e) { System.out.println("Error:" + e); } } else if (ae.getSource() == b2) { t1.setText(""); jp1.setText(""); } else if (ae.getSource() == b3) { f.setVisible(false); } }
public void actionPerformed(ActionEvent ae) { try { if (ae.getSource() == b7) { rs = st.executeQuery("select count(*) from employeemaster"); if (rs.next()) { t6.setText(rs.getString(1)); } rs = st.executeQuery("select * from Head"); if (rs.next()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t7.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t3.setText(rs.getString(6)); } } else if (ae.getSource() == b6) { dispose(); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error is" + e); } }
// -------------------------------------------------------------------------------- // Name: actionPerformed // Abstract: Event handler for control click events // -------------------------------------------------------------------------------- @Override public void actionPerformed(ActionEvent aeSource) { try { // // btnopenDatabaseConnection if (aeSource.getSource() == m_btnOK) btnOK_Click(); else if (aeSource.getSource() == m_btnCancel) btnCancel_Click(); } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } }
@Override public void actionPerformed(ActionEvent axnEve) { Object obj = axnEve.getSource(); if (obj == replyBut) { try { if (Home.composeDial != null && Home.composeDial.isShowing()) { } else { Home.composeDial = new ComposeMailDialog( msgID, workingSet.getString("mail_addresses"), workingSet.getString("subject")); } } catch (SQLException sqlExc) { sqlExc.printStackTrace(); } } else if (obj == forwardBut) { try { if (Home.composeDial != null && Home.composeDial.isShowing()) { } else { Home.composeDial = new ComposeMailDialog( msgID, workingSet.getString("subject") + "\n\n" + workingSet.getString("content")); } } catch (SQLException sqlExc) { sqlExc.printStackTrace(); } } }
// event handling public void actionPerformed(ActionEvent e) { if (e.getSource() == btnok) { PreparedStatement pstm; ResultSet rs; String sql; // if no entries has been made and hit ok button throw an error // you can do this step using try clause as well if ((tf1.getText().equals("") && (tf2.getText().equals("")))) { lblmsg.setText("Enter your details "); lblmsg.setForeground(Color.magenta); } else { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect = DriverManager.getConnection("jdbc:odbc:student_base"); System.out.println("Connected to the database"); pstm = connect.prepareStatement("insert into student_base values(?,?)"); pstm.setString(1, tf1.getText()); pstm.setString(2, tf2.getText()); // execute method to execute the query pstm.executeUpdate(); lblmsg.setText("Details have been added to database"); // closing the prepared statement and connection object pstm.close(); connect.close(); } catch (SQLException sqe) { System.out.println("SQl error"); } catch (ClassNotFoundException cnf) { System.out.println("Class not found error"); } } } // upon clickin button addnew , your textfield will be empty to enternext record if (e.getSource() == btnaddnew) { tf1.setText(""); tf2.setText(""); } if (e.getSource() == btnexit) { System.exit(1); } }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == bRes) { tname.setText(""); textra.setText(""); } else { if (it.isSelected()) field = 1; else if (civil.isSelected()) field = 2; else if (mech.isSelected()) field = 3; if (tname.getText().equals("") | textra.getText().equals("") | field == 0) JOptionPane.showMessageDialog(null, "Please Fill in All Entries!!"); else { String sal = (String) cbsal.getSelectedItem(); try { // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Connection conn=DriverManager.getConnection("jdbc:odbc:go"); Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:mysql:///go", "root", ""); Statement pst = conn.createStatement(); pst.executeUpdate( "Insert into company values('" + tname.getText() + "','" + textra.getText() + "','" + (String) sal + "','" + field + "','" + tusr.getText() + "','" + tpwd.getText() + "')"); conn.close(); String msg = "Your Details are Stored. Login again to View Related applicants! Thank You!!"; JOptionPane.showMessageDialog(null, msg); setVisible(false); login ab = new login(); } catch (Exception exc) { JOptionPane.showMessageDialog(null, tname.getText() + " : " + exc); System.exit(0); } } } }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() == b) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException pe) { System.out.println(pe); pe.printStackTrace(); } } } if (ae.getSource() == back) { new remindersub(); f.dispose(); } }
@Override public void actionPerformed(ActionEvent e) { // TODO action Object obj = e.getSource(); if (obj.equals(jtf) || obj.equals(textin)) { // name.setText(" 메시지 입력 "); pw.println(jtf.getText()); jtf.setText(""); } else if (obj.equals(serveropen)) { ServerOpen(); } else if (obj.equals(clientin) || obj.equals(pi)) { ClientIn(); } else if (obj.equals(conf)) { login(); } }
public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); if (b == bu) { j14 = new JLabel("NEW IMAGE"); j14.setBounds(840, 200, 300, 300); q.add(j14); JFileChooser filechooser = new JFileChooser(); int result = filechooser.showOpenDialog(this); f = filechooser.getSelectedFile(); try { String dir1 = f.getAbsolutePath(); // setText(dir); str = dir1; // ResizeImage.resize(dir); f = new File(dir1); } catch (Exception e1) { } repaint(); // b=(JButton)e.getSource(); } if (b == ba) { try { read(); patient.add(tadd.getText(), tsym.getText(), f, str); JOptionPane.showMessageDialog(null, "Patient ID: " + patient.pid + " Record Added"); } catch (Exception e4) { System.out.println("" + e4); } } if (b == bm) { try { setVisible(false); } catch (Exception e4) { System.out.println("" + e4); } } }
public void actionPerformed(ActionEvent e) { MainMenu M = new MainMenu(); Object source = e.getSource(); EmployeeNewReservation o = new EmployeeNewReservation(); EmployeeCheckRoom c = new EmployeeCheckRoom(); EmployeeCheckOut b = new EmployeeCheckOut(); if (source == order) { o.setEmployeeNewReservation(); dispose(); } if (source == exit) { M.setLoginPage(); dispose(); } if (source == check) { c.setEmployeeCheckRoom(); dispose(); } if (source == bill) { b.setEmployeeCheckOut(); dispose(); } }
public void actionPerformed(ActionEvent event) { // if clear button is pressed, clear all fields if (event.getSource() == clear_button) { // erase all fields taskname_field.setText(""); taskdesc_field.setText(""); priority_checkbox.setSelected(false); numberofdays_field.setText(""); // isallocatedcheckbox.setSelected(false); duedate_field.setText(""); } // if submit button is pressed, save all data onto database if (event.getSource() == submit_button) { try { { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); // set to current date calendar.add( Calendar.DAY_OF_MONTH, Integer.parseInt(this.numberofdays_field.getText()) - 1); // add days required... then: // ^ subtract one day, because if task is created today and allocated tomorrow for one // day, // then it should be done by end of day tomorrow Date date = calendar.getTime(); // (see next *1) use this date to be the earliest // because of expected task duration /*This is a constraint * the date and the length of days that user expected to take * if not feasible then the program will say so * */ // method compares the current date and the date that was entered by the user if (this.task_idfield.getText().length() != 7 // check chars || this.taskname_field.getText().length() > 50 // check chars || this.taskdesc_field.getText().length() > 50 || ((Date) this.duedate_field.getValue()).compareTo(date) < 0 // check that the date is possible (see last *1) || this.numberofdays_field.getText().length() > 2 || this.numberofdays_field.getText().length() == 0 // check number of digits || Integer.parseInt(this.numberofdays_field.getText()) < 1) // check number of days required for task { JOptionPane.showMessageDialog( this, "Task ID has to be 7 chars; " + "\n" + "Description <= 50 chars; " + "\n" + "Because the expected duration of the task is " + Integer.parseInt(this.numberofdays_field.getText()) + " days, the due date cannot be earlier than: " + new StringBuffer(new SimpleDateFormat("dd/MM/yyyy").format(date)).toString() + "; " + "\n" + "Task duration must be 2 digit number maximum and must be an integer greater than 0"); } else // check if taskid_field is equals to any of the fields on the database if (task_idfield.equals("")) { JOptionPane.showMessageDialog( this, "Please insert an identification number for a task"); } else // add constraint and tell customer to enter 7 values if (taskname_field.equals("")) { JOptionPane.showMessageDialog(this, "Please insert a name to identity the task"); } else { // get all inputs from user inputs and store in variables taskid_input = task_idfield.getText(); taskname_input = taskname_field.getText(); taskdesc_input = taskdesc_field.getText(); if (priority_checkbox.isSelected()) { priority_input = 1; } else { priority_input = 0; } // create and store date from user input date = (Date) duedate_field.getValue(); // store number of days input from user numberofdays_input = Integer.parseInt(numberofdays_field.getText()); // String[] column_names = { "Task ID", "Task Name", "Task Description", "Task // Priority", "Due Date", "Number of Days", "Is Allocated" , "Unallocateable" }; task = new Object[8]; task[0] = taskid_input; task[1] = taskname_input; task[2] = taskdesc_input; task[3] = priority_input; task[4] = date; task[5] = numberofdays_input; task[6] = 0; task[7] = 0; try { // SqlConnection.connect(); SqlConnection.ps = SqlConnection.connection.prepareStatement( "INSERT INTO TASK VALUES (?,?,?,?,?,?,?,?)"); SqlConnection.ps.setString(1, taskid_input); SqlConnection.ps.setString(2, taskname_input); SqlConnection.ps.setString(3, taskdesc_input); SqlConnection.ps.setInt(4, priority_input); SqlConnection.ps.setDate(5, new java.sql.Date(date.getTime())); SqlConnection.ps.setInt(6, numberofdays_input); SqlConnection.ps.setInt(7, 0); SqlConnection.ps.setInt(8, 0); SqlConnection.ps.executeUpdate(); // now enter skills into TASK SKILL database for (int i = 0; i < skill_list.size(); i++) { if (skill_list.get(i).isSelected()) { String skillid = skill_list.get(i).getText(); SqlConnection.statement.executeUpdate( "INSERT INTO TASKSKILL VALUES ('" + taskid_input + "', '" + skillid + "')"); } } SqlConnection.ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } // SqlConnection.ps.close(); SqlConnection.closeConnection(); this.setVisible(false); } } } catch (Exception exc) { JOptionPane.showMessageDialog( this, "Check your inputs:" + "\n" + "Priority has to be a 1-digit number;" + "\n" + "Date has to be in the format dd/MM/yyyy;" + "\n" + "Task length has to be 2-digit number"); System.out.println(exc); } } // display dialog box asking task manager if they want to quit, // if task manager does not want to quit, go back to adding more tasks // if customer quits, close the dialog box and the frame // now close the window after saving }
public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { if (makeConnection()) { if (!t1.getText().equals("") & !t2.getText().equals("") & !t3.getText().equals("") & !t4.getText().equals("")) { det dez = new det(); if (dez.date(t4.getText())) { String a = t1.getText(); String b = t2.getText(); String c = t3.getText(); String d = t4.getText(); String ef = t5.getText(); try { st = cn.createStatement(); String sql = "insert into detalle_ventas values('"; sql += a; sql += "', '"; sql += b + "', '" + c + "', '" + d + "', '" + ef; sql += "')"; int eaz = st.executeUpdate(sql); javax.swing.JOptionPane.showMessageDialog( null, "Se han creado " + eaz + " registros en la base de datos", "informacion", javax.swing.JOptionPane.INFORMATION_MESSAGE); start(); } catch (SQLException exz) { javax.swing.JOptionPane.showMessageDialog( null, "Ha ocurrido un error, favor de checar que la clave no ha sido ingresada ya con anterioridad \n si el problema persiste contacte con el administrador \nError: " + exz.getSQLState() + "" + exz.getMessage(), "Error", javax.swing.JOptionPane.INFORMATION_MESSAGE); } catch (Exception ez) { System.out.println(ez.getMessage()); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar la fecha con un formato correcto dd/mm/aaaa", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Favor de llenar todos los datos correctamente", "Error!!!", javax.swing.JOptionPane.ERROR_MESSAGE); } } else { javax.swing.JOptionPane.showMessageDialog( null, "Un error ha ocurrido al intentar conectar con la base de datos, \n reinicie el componente o contacte con el administrador", "Error", javax.swing.JOptionPane.ERROR_MESSAGE); } } try { cn.close(); } catch (Exception esa) { System.out.println(esa.getMessage()); } }
@Override public void actionPerformed(ActionEvent axnEve) { Object obj = axnEve.getSource(); if (obj == selectAllCB) { Boolean state; if (selectAllCB.isSelected()) { state = true; deleteBut.setVisible(true); if (Home.titlePan.getTitle().equals("Trash")) { restoreBut.setVisible(true); } } else { state = false; deleteBut.setVisible(false); if (Home.titlePan.getTitle().equals("Trash")) { restoreBut.setVisible(false); } } for (int i = 0; i < table.getRowCount(); i++) { table.setValueAt(state, i, 0); } } else if (obj == refreshBut || obj == backBut) { setContent(Home.titlePan.getTitle()); backBut.setVisible(false); } else if (obj == deleteBut) { ArrayList selectedMessages = getSelectedMessages(); if (selectedMessages.isEmpty()) { FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE); } else { int option = JOptionPane.showConfirmDialog( Home.home.homeFrame, "Are You Sure?", "DELETE", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == 0) { Database.deleteMessages(selectedMessages, Home.titlePan.getTitle()); setContent(Home.titlePan.getTitle()); } } } else if (obj == restoreBut) { ArrayList selectedMessages = getSelectedMessages(); if (selectedMessages.isEmpty()) { FootPan.setMessage(FootPan.NO_SELECTION_MESSAGE); } else { int option = JOptionPane.showConfirmDialog( Home.home.homeFrame, "Are You Sure?", "RESTORE", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == 0) { Database.restoreMessages(selectedMessages); setContent(Home.titlePan.getTitle()); } } } }
public void actionPerformed(ActionEvent ev) { String s = ev.getActionCommand(); if (s == null) { if (ev.getSource() instanceof JMenuItem) { JMenuItem i; s = ((JMenuItem) ev.getSource()).getText(); } } /* // button replace by toolbar if (s.equals("Execute")) { execute(); } else */ if (s.equals("Exit")) { windowClosing(null); } else if (s.equals("Transfer")) { Transfer.work(null); } else if (s.equals("Dump")) { Transfer.work(new String[] {"-d"}); } else if (s.equals("Restore")) { Transfer.work(new String[] {"-r"}); } else if (s.equals("Logging on")) { javaSystem.setLogToSystem(true); } else if (s.equals("Logging off")) { javaSystem.setLogToSystem(false); } else if (s.equals("Refresh Tree")) { refreshTree(); } else if (s.startsWith("#")) { int i = Integer.parseInt(s.substring(1)); txtCommand.setText(sRecent[i]); } else if (s.equals("Connect...")) { connect(ConnectionDialogSwing.createConnection(fMain, "Connect")); refreshTree(); } else if (s.equals("Results in Grid")) { iResult = 0; pResult.removeAll(); pResult.add(gScrollPane, BorderLayout.CENTER); pResult.doLayout(); gResult.fireTableChanged(null); pResult.repaint(); } else if (s.equals("Open Script...")) { JFileChooser f = new JFileChooser("."); f.setDialogTitle("Open Script..."); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setCurrentDirectory(new File(defDirectory)); } int option = f.showOpenDialog(fMain); if (option == JFileChooser.APPROVE_OPTION) { File file = f.getSelectedFile(); if (file != null) { StringBuffer buf = new StringBuffer(); ifHuge = DatabaseManagerCommon.readFile(file.getAbsolutePath()); if (4096 <= ifHuge.length()) { buf.append("This huge file cannot be edited. Please execute\n"); txtCommand.setText(buf.toString()); } else { txtCommand.setText(ifHuge); } } } } else if (s.equals("Save Script...")) { JFileChooser f = new JFileChooser("."); f.setDialogTitle("Save Script"); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setCurrentDirectory(new File(defDirectory)); } int option = f.showSaveDialog(fMain); if (option == JFileChooser.APPROVE_OPTION) { File file = f.getSelectedFile(); if (file != null) { DatabaseManagerCommon.writeFile(file.getAbsolutePath(), txtCommand.getText()); } } } else if (s.equals("Save Result...")) { JFileChooser f = new JFileChooser("."); f.setDialogTitle("Save Result..."); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setCurrentDirectory(new File(defDirectory)); } int option = f.showSaveDialog(fMain); if (option == JFileChooser.APPROVE_OPTION) { File file = f.getSelectedFile(); if (file != null) { showResultInText(); DatabaseManagerCommon.writeFile(file.getAbsolutePath(), txtResult.getText()); } } } else if (s.equals("Results in Text")) { iResult = 1; pResult.removeAll(); pResult.add(txtResultScroll, BorderLayout.CENTER); pResult.doLayout(); showResultInText(); pResult.repaint(); } else if (s.equals("AutoCommit on")) { try { cConn.setAutoCommit(true); } catch (SQLException e) { } } else if (s.equals("AutoCommit off")) { try { cConn.setAutoCommit(false); } catch (SQLException e) { } } else if (s.equals("Commit")) { try { cConn.commit(); } catch (SQLException e) { } } else if (s.equals("Insert test data")) { insertTestData(); } else if (s.equals("Rollback")) { try { cConn.rollback(); } catch (SQLException e) { } } else if (s.equals("Disable MaxRows")) { try { sStatement.setMaxRows(0); } catch (SQLException e) { } } else if (s.equals("Set MaxRows to 100")) { try { sStatement.setMaxRows(100); } catch (SQLException e) { } } else if (s.equals("SELECT")) { showHelp(DatabaseManagerCommon.selectHelp); } else if (s.equals("INSERT")) { showHelp(DatabaseManagerCommon.insertHelp); } else if (s.equals("UPDATE")) { showHelp(DatabaseManagerCommon.updateHelp); } else if (s.equals("DELETE")) { showHelp(DatabaseManagerCommon.deleteHelp); } else if (s.equals("CREATE TABLE")) { showHelp(DatabaseManagerCommon.createTableHelp); } else if (s.equals("DROP TABLE")) { showHelp(DatabaseManagerCommon.dropTableHelp); } else if (s.equals("CREATE INDEX")) { showHelp(DatabaseManagerCommon.createIndexHelp); } else if (s.equals("DROP INDEX")) { showHelp(DatabaseManagerCommon.dropIndexHelp); } else if (s.equals("CHECKPOINT")) { showHelp(DatabaseManagerCommon.checkpointHelp); } else if (s.equals("SCRIPT")) { showHelp(DatabaseManagerCommon.scriptHelp); } else if (s.equals("SHUTDOWN")) { showHelp(DatabaseManagerCommon.shutdownHelp); } else if (s.equals("SET")) { showHelp(DatabaseManagerCommon.setHelp); } else if (s.equals("Test Script")) { showHelp(DatabaseManagerCommon.testHelp); } }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() == exit) { this.dispose(); new HomePage(); } }
public void actionPerformed(ActionEvent e) { String a, b, c, f, g, h, j, k, l, m, n, o, p, tol = ""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:db2"); stm = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (Exception error) { System.out.println(error); } if (e.getSource() == student) { name = "Student"; cl.show(pnc, "cstu"); try { rs = stm.executeQuery("Select * from Student"); rs.next(); t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == teacher) { name = "Teacher"; cl.show(pnc, "ctea"); try { rs = stm.executeQuery("Select * from Teacher"); rs.next(); t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == course) { name = "Course"; cl.show(pnc, "ccou"); try { rs = stm.executeQuery("Select * from Course"); rs.next(); t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == result) { name = "Result"; cl.show(pnc, "cres"); try { rs = stm.executeQuery("Select * from Result"); rs.next(); t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b6) { Vector cols = new Vector(); Vector rows = new Vector(); if (z == 1) { String sql = "Select * from " + co; try { rs = stm.executeQuery(sql); meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) cols.addElement(meta.getColumnName(i)); while (rs.next()) { Vector currow = new Vector(); for (int i = 1; i <= meta.getColumnCount(); i++) currow.addElement(rs.getString(i)); rows.addElement(currow); } } catch (Exception ex) { System.out.print(ex); } tb = new JTable(rows, cols); js = new JScrollPane(tb); pne2.remove(js); pne2.add(blk, "bb"); cl2.show(pne2, "bb"); pne2.add(js, "jjs"); cl2.show(pne2, "jjs"); pne2.remove(blk); z = 0; } } if (e.getSource() == b1) // **** ADD BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Insert into Student values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "')"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Insert into Teacher values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Insert into Course values ('" + a + "','" + b + "','" + c + "','" + f + "')"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Insert into Result values ('" + a + "','" + b + "','" + c + "','" + f + "','" + g + "','" + h + "','" + j + "','" + k + "','" + l + "','" + m + "','" + n + "','" + o + "','" + p + "')"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b2) // **** DELETE BUTTON ****// { if (name == "Student") { b = t2.getText(); tol = "Delete from Student where Id = '" + b + "'"; } if (name == "Teacher") { b = t12.getText(); tol = "Delete from Teacher where Id = '" + b + "'"; } if (name == "Course") { b = t8.getText(); tol = "Delete from Course where Id = '" + b + "'"; } if (name == "Result") { b = t16.getText(); tol = "Delete from Result where Code = '" + b + "'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b3) // **** UPDATE BUTTON ****// { if (name == "Student") { a = t1.getText(); b = t2.getText(); c = t3.getText(); f = t4.getText(); g = t5.getText(); h = t6.getText(); tol = "Update Student set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', CGPA = '" + f + "', Address = '" + g + "', Cell = '" + h + "' where ID = '" + b + "'"; } if (name == "Teacher") { a = t11.getText(); b = t12.getText(); c = t13.getText(); f = t14.getText(); tol = "Update Teacher set Name = '" + a + "', ID = '" + b + "', Dept = '" + c + "', Course = '" + f + "' where ID = '" + b + "'"; } if (name == "Course") { a = t7.getText(); b = t8.getText(); c = t9.getText(); f = t0.getText(); tol = "Update Course set Name = '" + a + "', Code = '" + b + "', Credit = '" + c + "', Prerecusite = '" + f + "' where Code = '" + b + "'"; } if (name == "Result") { a = t15.getText(); b = t16.getText(); c = t17.getText(); f = t18.getText(); g = t19.getText(); h = t20.getText(); j = t21.getText(); k = t22.getText(); l = t23.getText(); m = t24.getText(); n = t25.getText(); o = t26.getText(); p = t27.getText(); tol = "Update Result set Course = '" + a + "', Code = '" + b + "', Credit = '" + c + "', A = '" + f + "', B+ = '" + g + "', B = '" + h + "', C+ = '" + j + "', C = '" + k + "', D+ = '" + l + "', D = '" + m + "', F = '" + n + "', I = '" + o + "', W = '" + p + "' where Code = '" + b + "'"; // JOptionPane.showMessageDialog(null,tol,null,JOptionPane.PLAIN_MESSAGE); // tol = "Update Result set Course = '"+a+"', Code = '"+b+"', Credit = '"+c+"' where Code = // '"+b+"'"; } try { stm.executeUpdate(tol); } catch (Exception error) { System.out.println(error); } } if (e.getSource() == b4) // **** NEXT BUTTON ****// { if (name == "Student") { try { if (rs.next()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.next()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.next()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.next()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } if (e.getSource() == b5) // **** PREVIOUS BUTTON ****// { if (name == "Student") { try { if (rs.previous()) { t1.setText(rs.getString(1)); t2.setText(rs.getString(2)); t3.setText(rs.getString(3)); t4.setText(rs.getString(4)); t5.setText(rs.getString(5)); t6.setText(rs.getString(6)); } } catch (Exception error) { System.out.println(error); } } if (name == "Teacher") { try { if (rs.previous()) { t11.setText(rs.getString(1)); t12.setText(rs.getString(2)); t13.setText(rs.getString(3)); t14.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Course") { try { if (rs.previous()) { t7.setText(rs.getString(1)); t8.setText(rs.getString(2)); t9.setText(rs.getString(3)); t0.setText(rs.getString(4)); } } catch (Exception error) { System.out.println(error); } } if (name == "Result") { try { if (rs.previous()) { t15.setText(rs.getString(1)); t16.setText(rs.getString(2)); t17.setText(rs.getString(3)); t18.setText(rs.getString(4)); t19.setText(rs.getString(5)); t20.setText(rs.getString(6)); t21.setText(rs.getString(7)); t22.setText(rs.getString(8)); t23.setText(rs.getString(9)); t24.setText(rs.getString(10)); t25.setText(rs.getString(11)); t26.setText(rs.getString(12)); t27.setText(rs.getString(13)); } } catch (Exception error) { System.out.println(error); } } } }
/** * Method declaration * * @param ev */ public void actionPerformed(ActionEvent ev) { String s = ev.getActionCommand(); if (s == null) { if (ev.getSource() instanceof MenuItem) { MenuItem i; s = ((MenuItem) ev.getSource()).getLabel(); } } if (s.equals("Execute")) { execute(); } else if (s.equals("Exit")) { windowClosing(null); } else if (s.equals("Transfer")) { Transfer.work(null); } else if (s.equals("Dump")) { Transfer.work(new String[] {"-d"}); /* NB - 26052002 Restore is not implemented yet in the transfer tool */ /* } else if (s.equals("Restore")) { Transfer.work(new String[]{"-r"}); */ } else if (s.equals("Logging on")) { jdbcSystem.setLogToSystem(true); } else if (s.equals("Logging off")) { jdbcSystem.setLogToSystem(false); } else if (s.equals("Refresh Tree")) { refreshTree(); } else if (s.startsWith("#")) { int i = Integer.parseInt(s.substring(1)); txtCommand.setText(sRecent[i]); } else if (s.equals("Connect...")) { connect(ConnectionDialog.createConnection(fMain, "Connect")); refreshTree(); } else if (s.equals("Results in Grid")) { iResult = 0; pResult.removeAll(); pResult.add("Center", gResult); pResult.doLayout(); } else if (s.equals("Open Script...")) { FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file)); } } else if (s.equals("Save Script...")) { FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText()); } } else if (s.equals("Save Result...")) { FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE); // (ulrivo): set default directory if set from command line if (defDirectory != null) { f.setDirectory(defDirectory); } f.show(); String file = f.getFile(); if (file != null) { showResultInText(); DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText()); } } else if (s.equals("Results in Text")) { iResult = 1; pResult.removeAll(); pResult.add("Center", txtResult); pResult.doLayout(); showResultInText(); } else if (s.equals("AutoCommit on")) { try { cConn.setAutoCommit(true); } catch (SQLException e) { } } else if (s.equals("AutoCommit off")) { try { cConn.setAutoCommit(false); } catch (SQLException e) { } } else if (s.equals("Enlarge Tree")) { Dimension d = tTree.getMinimumSize(); d.width += 20; tTree.setMinimumSize(d); fMain.pack(); } else if (s.equals("Shrink Tree")) { Dimension d = tTree.getMinimumSize(); d.width -= 20; if (d.width >= 0) { tTree.setMinimumSize(d); } fMain.pack(); } else if (s.equals("Enlarge Command")) { txtCommand.setRows(txtCommand.getRows() + 1); fMain.pack(); } else if (s.equals("Shrink Command")) { int i = txtCommand.getRows() - 1; txtCommand.setRows(i < 1 ? 1 : i); fMain.pack(); } else if (s.equals("Commit")) { try { cConn.commit(); } catch (SQLException e) { } } else if (s.equals("Insert test data")) { insertTestData(); } else if (s.equals("Rollback")) { try { cConn.rollback(); } catch (SQLException e) { } } else if (s.equals("Disable MaxRows")) { try { sStatement.setMaxRows(0); } catch (SQLException e) { } } else if (s.equals("Set MaxRows to 100")) { try { sStatement.setMaxRows(100); } catch (SQLException e) { } } else if (s.equals("SELECT")) { showHelp(DatabaseManagerCommon.selectHelp); } else if (s.equals("INSERT")) { showHelp(DatabaseManagerCommon.insertHelp); } else if (s.equals("UPDATE")) { showHelp(DatabaseManagerCommon.updateHelp); } else if (s.equals("DELETE")) { showHelp(DatabaseManagerCommon.deleteHelp); } else if (s.equals("CREATE TABLE")) { showHelp(DatabaseManagerCommon.createTableHelp); } else if (s.equals("DROP TABLE")) { showHelp(DatabaseManagerCommon.dropTableHelp); } else if (s.equals("CREATE INDEX")) { showHelp(DatabaseManagerCommon.createIndexHelp); } else if (s.equals("DROP INDEX")) { showHelp(DatabaseManagerCommon.dropIndexHelp); } else if (s.equals("CHECKPOINT")) { showHelp(DatabaseManagerCommon.checkpointHelp); } else if (s.equals("SCRIPT")) { showHelp(DatabaseManagerCommon.scriptHelp); } else if (s.equals("SHUTDOWN")) { showHelp(DatabaseManagerCommon.shutdownHelp); } else if (s.equals("SET")) { showHelp(DatabaseManagerCommon.setHelp); } else if (s.equals("Test Script")) { showHelp(DatabaseManagerCommon.testHelp); } }
/** * ************************************************************************ Action Listener * * @param e event */ public void actionPerformed(ActionEvent e) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == bDisassociate) cmd_disassociate(); else if (e.getSource() == bNewProduct) cmd_newProduct(); } // actionPerformed