public void actionPerformed(ActionEvent e) { String name = null; name = JOptionPane.showInputDialog( objUpdate.this, "Enter a name (eg. John Russell)", "Input Person", JOptionPane.QUESTION_MESSAGE); if (!(name == null)) { // prompt the user for a date String date = null; date = JOptionPane.showInputDialog( objUpdate.this, "Enter Date (eg. 06/17/1946)", "Input Person", JOptionPane.QUESTION_MESSAGE); if (!(date == null)) { // convert String to Date try { Date d = f.parse(date); p = new Person(name, d); persons.add(p); index = persons.lastIndexOf(p); displayRecord(); } catch (ParseException ex) { JOptionPane.showMessageDialog( objUpdate.this, "Invalid date format!", "Input Error", JOptionPane.ERROR_MESSAGE); } } } }
public void display(ResultSet rs) { try { boolean recordNumber = rs.next(); if (recordNumber) { payNo = rs.getString(1); pasNo = rs.getString(2); pasName = rs.getString(3); mode = rs.getString(4); dt = rs.getString(5); amount = rs.getString(6); rev = rs.getString(7); text1.setText(payNo); combo1.setSelectedItem(pasNo); combo2.setSelectedItem(pasName); combo4.setSelectedItem(mode); p_date.setText(dt); combo8.setSelectedItem(amount); combo3.setSelectedItem(rev); } else { JOptionPane.showMessageDialog( null, "Record Not found", "ERROR", JOptionPane.DEFAULT_OPTION); } } catch (SQLException sqlex) { sqlex.printStackTrace(); } }
private void btnSalirActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSalirActionPerformed int respuesta = JOptionPane.showConfirmDialog(null, "¿Confirma que desea salir?"); if (respuesta == 0) { dispose(); } } // GEN-LAST:event_btnSalirActionPerformed
public void windowClosing(WindowEvent e) // write file on finish { FileOutputStream out = null; ObjectOutputStream data = null; try { // open file for output out = new FileOutputStream(DB); data = new ObjectOutputStream(out); // write Person objects to file using iterator class Iterator<Person> itr = persons.iterator(); while (itr.hasNext()) { data.writeObject((Person) itr.next()); } data.flush(); data.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( objUpdate.this, "Error processing output file" + "\n" + ex.toString(), "Output Error", JOptionPane.ERROR_MESSAGE); } finally { System.exit(0); } }
public static void main(String args[]) { BankAccount acc = new BankAccount(10000); acc.start(10); JOptionPane.showMessageDialog(null, "Keluar dari program?"); System.exit(0); }
void message(String message) { System.out.println("\007" + message); JOptionPane.showMessageDialog( null, message, "Timer Alert", // titlebar JOptionPane.INFORMATION_MESSAGE); // icon }
public static double getInputDouble() { try { String inputString = waitForInputString(); double d = Double.parseDouble(inputString.trim()); return d; } catch (Exception e) { JOptionPane.showMessageDialog(frame, null, "Improper double", JOptionPane.ERROR_MESSAGE); return 0; } }
public static int getInputInteger() { try { String inputString = waitForInputString(); int i = Integer.parseInt(inputString.trim()); return i; } catch (Exception e) { JOptionPane.showMessageDialog(frame, null, "Improper integer", JOptionPane.ERROR_MESSAGE); return 0; } }
@Override public void actionPerformed(ActionEvent e) { if (fc == null) { fc = new IDEFileChooser(); fc.setFileView(new IDEFileView()); fc.setAcceptAllFileFilterUsed(false); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false); fc.setDialogTitle( messagesBundle.getString("ImageViewerPanelSaveAction.Choose_filename_to_save_4")); //$NON-NLS-1$ // prepare file filters IIORegistry theRegistry = IIORegistry.getDefaultInstance(); Iterator it = theRegistry.getServiceProviders(ImageWriterSpi.class, false); while (it.hasNext()) { ImageWriterSpi writer = (ImageWriterSpi) it.next(); if ((imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_ARGB_PRE) && "JPEG".equals(writer.getFormatNames()[0].toUpperCase())) continue; ImageWriterSpiFileFilter ff = new ImageWriterSpiFileFilter(writer); fc.addChoosableFileFilter(ff); } } if (fc.showSaveDialog(viewerPanel) == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); if (selectedFile != null) { String fileName = selectedFile.getAbsolutePath(); ImageWriterSpiFileFilter ff = (ImageWriterSpiFileFilter) fc.getFileFilter(); if (!ff.hasCorrectSuffix(fileName)) fileName = ff.addSuffix(fileName); selectedFile = new File(fileName); if (selectedFile.exists()) { String message = MessageFormat.format( messagesBundle.getString("ImageViewerPanelSaveAction.Overwrite_question_5"), //$NON-NLS-1$ fileName); if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog( viewerPanel, message, messagesBundle.getString("ImageViewerPanelSaveAction.Warning_6"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE)) return; } writeToFile(selectedFile, ff); } } }
public void actionPerformed(ActionEvent e) { if (e.getSource() == submit) { if (rb1.isSelected()) { JFrame frame = Application.getFrame(); if (typeCodes.isEmpty()) { JOptionPane.showMessageDialog( frame, "Please select at least one toponym type.", "Error", JOptionPane.ERROR_MESSAGE); } else { Application.getMainCitiesPanel(this, typeCodes, 0, 0.0); } } else if (rb2.isSelected()) { JFrame frame = Application.getFrame(); try { nCities = new Integer(nCitiesField.getText()); if (nCities <= 0) throw new NumberFormatException(); typeCodes = new ArrayList<String>(); Application.getMainCitiesPanel(this, typeCodes, nCities, 0.0); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( frame, "Please enter a positive integer number.", "Error", JOptionPane.ERROR_MESSAGE); } } else { JFrame frame = Application.getFrame(); try { Double dist = new Double(distField.getText()); if (dist <= 0) throw new NumberFormatException(); typeCodes = new ArrayList<String>(); Application.getMainCitiesPanel(this, typeCodes, 0, dist); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( frame, "Please enter a positive number.", "Error", JOptionPane.ERROR_MESSAGE); } } } else { Application.getOptionPanel(this, countryName); } }
private void btnEliminarRenglonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnEliminarRenglonActionPerformed // TODO add your handling code here: int IDRenglon = this.tablaPrincipal.getSelectedRow(); if (IDRenglon != -1) { if (JOptionPane.showConfirmDialog( null, "¿Realmente desea eliminar el renglón seleccionado?", "¿Eliminar?", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { ((DefaultTableModel) tablaPrincipal.getModel()).removeRow(IDRenglon); } } } // GEN-LAST:event_btnEliminarRenglonActionPerformed
public void restartApplication() { try { final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw"; final File currentJar = new File(network.class.getProtectionDomain().getCodeSource().getLocation().toURI()); System.out.println("javaBin " + javaBin); System.out.println("currentJar " + currentJar); System.out.println("currentJar.getPath() " + currentJar.getPath()); /* is it a jar file? */ // if(!currentJar.getName().endsWith(".jar")){return;} try { // xmining = 0; // systemx.shutdown(); } catch (Exception e) { e.printStackTrace(); } /* Build command: java -jar application.jar */ final ArrayList<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-jar"); command.add("-Xms256m"); command.add("-Xmx1024m"); command.add(currentJar.getPath()); final ProcessBuilder builder = new ProcessBuilder(command); builder.start(); // try{Thread.sleep(10000);} catch (InterruptedException e){} // close and exit SystemTray.getSystemTray().remove(network.icon); System.exit(0); } // try catch (Exception e) { JOptionPane.showMessageDialog(null, e.getCause()); } } // ******************************
private void btnGuardarActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnGuardarActionPerformed gestorBitacora gestorB = new gestorBitacora(); Iterator ite = gestorH.listarClase(Viaje.class).iterator(); while (ite.hasNext()) { Viaje viaje = (Viaje) ite.next(); if (viaje.getIdViaje() == Long.parseLong(txtNumViaje.getText())) { Iterator ite1 = gestorH.listarClase(Vehiculo.class).iterator(); while (ite1.hasNext()) { Vehiculo vehiculo = (Vehiculo) ite1.next(); if (vehiculo.getDominio().equalsIgnoreCase(txtDominio.getText())) { viaje.setVehiculo(vehiculo); viaje.setEstado("Con vehiculo asignado"); gestorH.actualizarObjeto(viaje); vehiculo.setEstado("Asignado"); gestorH.actualizarObjeto(vehiculo); gestorB.cargarBitacora( String.valueOf(viaje.getIdViaje()), txtFecha.getText(), 3, labelusuario.getText(), ""); } } } } DefaultTableModel modeloT = (DefaultTableModel) tblViaje.getModel(); modeloT.setRowCount(0); gestorA.RellenarTablaViajes(tblViaje); txtNumeroSolicitud.setText(""); txtDestino.setText(""); txtCereal.setText(""); txtFechaRealizacion.setText(""); txtTipoViaje.setText(""); txtNumViaje.setText(""); txtProductor.setText(""); DefaultTableModel modelo = (DefaultTableModel) tblVehiculo.getModel(); modelo.setRowCount(0); txtVehiculo.setText(""); txtTara.setText(""); txtTipoVehiculo.setText(""); txtTransportista.setText(""); txtDominio.setText(""); JOptionPane.showMessageDialog(null, "Se asigno correctamente el vehiculo"); } // GEN-LAST:event_btnGuardarActionPerformed
private void writeToFile(File selectedFile, ImageWriterSpiFileFilter ff) { try { ImageOutputStream ios = ImageIO.createImageOutputStream(selectedFile); ImageWriter iw = ff.getImageWriterSpi().createWriterInstance(); iw.setOutput(ios); ImageWriteParam iwp = iw.getDefaultWriteParam(); if (iwp.canWriteCompressed()) { iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); // set maximum image quality iwp.setCompressionQuality(1.f); } Image image = viewerPanel.getImage(); BufferedImage bufferedImage; if (viewerPanel.getImage() instanceof BufferedImage) bufferedImage = (BufferedImage) viewerPanel.getImage(); else { bufferedImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); bufferedImage.createGraphics().drawImage(image, 0, 0, null); } iw.write(null, new IIOImage(bufferedImage, null, null), iwp); iw.dispose(); ios.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog( viewerPanel, messagesBundle.getString( "ImageViewerPanelSaveAction." + "Error_during_image_saving_message_7"), //$NON-NLS-1$ messagesBundle.getString("ImageViewerPanelSaveAction." + "Error_dialog_title_8"), //$NON-NLS-1$ JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } }
/** Pops up a dialog box with an error message in it. */ private void error(String message) { JOptionPane.showMessageDialog( this, new String[] {message}, "Error.", JOptionPane.ERROR_MESSAGE); }
public PowerSupply() { super(); String str = JOptionPane.showInputDialog("Enter frequency"); this.frequency = Double.parseDouble(str); this.impedance = new Complex(0.0, 0.0); }