List of usage examples for javax.swing JOptionPane showConfirmDialog
public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException
optionType
parameter, where the messageType
parameter determines the icon to display. From source file:serial.ChartFromSerial.java
private boolean attemptConnection(String desiredPort, int baudRate) { //Port Setup//from w w w . j a v a2 s . co m chosenPort = SerialPort.getCommPort(desiredPort); chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0); chosenPort.setBaudRate(baudRate); //Making sure all goes well chosenPort.openPort(); if (chosenPort.openPort()) { createSerialThread(chosenPort); buttonsConnected(); // buttonsConnected(); // if (createSerialThread(chosenPort)){ // buttonsConnected(); // } else { // JOptionPane.showMessageDialog(rootPane, "Failed to create a serial connection.", "Serial connection failed.", JOptionPane.ERROR_MESSAGE); // chosenPort.closePort(); // } } else { //Prompt user for response if (JOptionPane.showConfirmDialog(rootPane, "Error at " + portList_jCombo.getSelectedItem().toString() + "\nWould you like to refresh?", "Trouble connecting to " + portList_jCombo.getSelectedItem().toString(), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) == JOptionPane.YES_OPTION) { hardRefresh(); } else { buttonsOff(); } } return false; }
From source file:pi.bestdeal.gui.InterfacePrincipale.java
private void Add_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Add_ButtonActionPerformed Panel_Ajouter panajout = new Panel_Ajouter(); Deal deal = new Deal(); int result = JOptionPane.showConfirmDialog(null, panajout, "Test", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { deal.setTitreDeal_Deal(panajout.txtTitre.getText()); Vendeur vendeur = new Vendeur(); VendeurDAO daov = VendeurDAO.getInstance(); for (Vendeur a : daov.displayvendeurByNom(String.valueOf(panajout.jList1.getSelectedValue()))) { vendeur = a;/*from w ww . ja v a 2 s . c o m*/ } if (panajout.jList1.getSelectedValue() == null) { vendeur.setIdVendeur(0); } deal.setDescDeal_Deal(panajout.txtDesc.getText()); deal.setPrixDeal_Deal(Double.valueOf(panajout.txtPrix.getText())); deal.setNbrAchatValidation(Integer.valueOf(panajout.txtValidation.getText())); deal.setNbrAchatActuelDeal_Deal(0); deal.setNbrAffichage_Deal(0); deal.setEtatDeal_Deal("Comming"); deal.setCategorie_Deal(panajout.ComboCategorie.getSelectedItem().toString()); deal.setStatutDeal_Deal(false); java.util.Date d1 = panajout.jdateDebut.getCalendar().getTime(); java.sql.Date sqlDate = new java.sql.Date(d1.getTime()); java.util.Date d2 = panajout.jdateFin.getCalendar().getTime(); java.sql.Date sqlDate2 = new java.sql.Date(d2.getTime()); if (d1.after(d2)) { JOptionPane.showMessageDialog(null, "les Dates sont non compatibles"); } else { deal.setDateDebutDeal_Deal(sqlDate); deal.setDateFinDeal_Deal(sqlDate2); deal.setIdVendeur_Deal(vendeur.getIdVendeur()); DealDAO dealdao = DealDAO.getInstance(); dealdao.insertDeal(deal); Deal dd = dealdao.displayDeal().get((dealdao.displayDeal().size() - 1)); y = dd.getIdDeal_Deal(); System.out.println(y); if (panajout.fc.getSelectedFiles().length != 0) { for (int i = 0; i < panajout.fc.getSelectedFiles().length; i++) { FileInputStream fis = null; try { fis = new FileInputStream(panajout.file[i]); } catch (FileNotFoundException ex) { Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex); } ImageDeal imgdeal = new ImageDeal(); Path path = Paths.get(panajout.file[i].getAbsolutePath()); try { imgdeal.setImage(Files.readAllBytes(path)); } catch (IOException ex) { Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex); } imgdeal.setIdDeal(y); ImageDAO im = ImageDAO.getInstance(); im.InsertImage(imgdeal); } } JOptionPane.showMessageDialog(null, "Ajout termin"); DealTableModel mymodel = new DealTableModel(list.displayDeal()); jTable1.setModel(mymodel); jTable1.removeColumn(jTable1.getColumn("ID")); jTable1.removeColumn(jTable1.getColumn("Description")); jTable1.removeColumn(jTable1.getColumn("Achat Actuel")); jTable1.removeColumn(jTable1.getColumn("Etat")); jTable1.removeColumn(jTable1.getColumn("Statut")); jTable1.removeColumn(jTable1.getColumn("Nombre d'Affichage")); jTable1.removeColumn(jTable1.getColumn("Vendeur")); jTable1.getColumnModel().setColumnMargin(20); jTable1.setRowSelectionInterval(0, 0); y = mymodel.getRowCount(); panajout.w = y; System.out.println("la valeur de y est :" + y + "et " + panajout.w); } } else { System.out.println("Cancelled"); } }