public void actionPerformed(ActionEvent a) { if (a.getSource() == byes) { msg = "You Pressed Yes Button"; } else if (a.getSource() == bno) { msg = "You Pressed No Button"; } repaint(); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == top) { tabbedpane.setTabPlacement(JTabbedPane.TOP); } else if (e.getSource() == left) { tabbedpane.setTabPlacement(JTabbedPane.LEFT); } else if (e.getSource() == bottom) { tabbedpane.setTabPlacement(JTabbedPane.BOTTOM); } else if (e.getSource() == right) { tabbedpane.setTabPlacement(JTabbedPane.RIGHT); } }
public void actionPerformed(ActionEvent e) { if (!e.getActionCommand().equals("re")) { int pos = Integer.parseInt(e.getActionCommand()); int count = Integer.parseInt(a[pos].getText()); String input = ""; int count2 = 0; if (count < 1) JOptionPane.showMessageDialog( null, "Error", "Error! Already empty!", JOptionPane.WARNING_MESSAGE); else if (count < 9) { try { input = JOptionPane.showInputDialog("How many do you want to remove? "); count2 = Integer.parseInt(input); } catch (NullPointerException w) { } catch (NumberFormatException w) { } if (count2 > 0 && count2 < 9) { a[pos].setLabel((count - count2) + ""); if ((count - count2) > 2) a[pos].setBackground(Color.yellow); else if ((count - count2) > 0) a[pos].setBackground(Color.red); else { a[pos].setBackground(Color.white); win++; } if (count2 > 0 && input != null) turn++; repaint(); } else JOptionPane.showMessageDialog( null, "Error", "Error! Invalid Input!", JOptionPane.WARNING_MESSAGE); } } else { for (int i = 0; i < row; i++) { a[i].setLabel("8"); a[i].setBackground(Color.yellow); } status.setText("Welcome! The person to remove the final stones loses!"); } if (turn % 2 == 0) status.setText(name + "'s turn!"); else status.setText(name2 + "'s turn!"); if (win >= 10) { if (turn % 2 == 1) status.setText(name + " is the winner!"); else status.setText(name2 + " is the winner!"); } }
public void actionPerformed(ActionEvent ae) { String action = ae.getActionCommand(); if (action.equals("refresh")) { routerThread = new Thread(this); routerThread.start(); } }
public void actionPerformed(ActionEvent ae) { String s = ae.getActionCommand(); double we, h; double r; we = Integer.parseInt(weight.getText()); h = Integer.parseInt(height.getText()); h = (h / 100); h = h * h; r = we / h; result.setText(String.valueOf(r)); if (r < 18.5) { not.setForeground(Color.YELLOW); not.setText(String.valueOf("UnderWeight")); } if (r >= 18.5 && r < 24.9) { not.setForeground(Color.GREEN); not.setText(String.valueOf("Normal")); } if (r > 25 && r < 29.9) { not.setForeground(Color.ORANGE); not.setText(String.valueOf("Overweight")); } if (r >= 30) { not.setForeground(Color.RED); not.setText(String.valueOf("Obese")); } repaint(); }
public void actionPerformed(ActionEvent e) { JButton tempB = (JButton) e.getSource(); option = tempB.getText(); if (option.equals("+")) { txt.setText(myCalculat.opAdd(txt.getText())); ifOp = true; } else if (option.equals("-")) { txt.setText(myCalculat.opSubtract(txt.getText())); ifOp = true; } else if (option.equals("*")) { txt.setText(myCalculat.opMultiply(txt.getText())); ifOp = true; } else if (option.equals("/")) { txt.setText(myCalculat.opDivide(txt.getText())); ifOp = true; } else if (option.equals("=")) { txt.setText(myCalculat.opEquals(txt.getText())); ifOp = true; } else if (option.equals("C")) { txt.setText(""); ifOp = true; } }
/** * 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); } }
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()); } }
import java.applet.*;
public void actionPerformed(ActionEvent e) { JButton tempB = (JButton) e.getSource(); s = tempB.getText(); setTextFieldText(); }
// // This method is called when a button is pressed. // public synchronized void actionPerformed(ActionEvent evt) { if (viewer.inSeparateFrame) viewer.vncFrame.dispose(); if (evt.getSource() == reloginButton) viewer.getAppletContext().showDocument(viewer.getDocumentBase()); }
public void actionPerformed(ActionEvent e) { Object src = e.getSource(); if (src == timer) { for (int i = 0; i < speed; i++) // integrate a few steps md.vv(); repaint(); return; } boolean adjCanvasScale = false; if (src == bTstat) md.thermostat = !md.thermostat; if (src == bPot) { md.ljPotential = !md.ljPotential; md.clearData(); if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } if (src == tTemp || src == bReset) { double kT = Double.parseDouble(tTemp.getText().trim()); if (kT < 1e-8) { kT = 1e-8; tTemp.setText(" " + kT); } md.kT = kT; md.clearData(); } if (src == tRho || src == bReset) { double rho = Double.parseDouble(tRho.getText().trim()); if (rho < 1e-3) { rho = 1e-3; tRho.setText(" " + rho); } if (rho > 1.2) { rho = 1.2; tRho.setText(" " + rho); } md.setDensity(rho); md.clearData(); adjCanvasScale = true; } if (src == tSpeed || src == bReset) { speed = Integer.parseInt(tSpeed.getText().trim()); if (speed < 1) { speed = 1; tSpeed.setText(" " + speed); } } if (src == bRetime) md.clearData(); if (src == bStart) { boolean on = bStart.isSelected(); if (on) { timer.restart(); bStart.setText("Pause"); } else { timer.stop(); bStart.setText("Resume"); } } if (src == tNum) { int n = Integer.parseInt(tNum.getText().trim()); if (n < 2) { n = 2; tNum.setText(" " + n); } md.N = n; md.init(md.rho); adjCanvasScale = true; } if (src == bReset) { if (timer.isRunning()) timer.stop(); bStart.setSelected(false); bStart.setText("Start"); md.init(md.rho); } canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale); repaint(); }
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); } } } }