Advertisement
Guest User

Untitled

a guest
Aug 27th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.65 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package carpoolingGUI;
  6.  
  7. import carpooling.Carpooling2;
  8. import carpooling.Login;
  9. import carpooling.Tratta;
  10. import java.io.IOException;
  11. import java.net.MalformedURLException;
  12. import java.util.Calendar;
  13. import java.util.Random;
  14. import java.util.concurrent.TimeoutException;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import javax.swing.JOptionPane;
  18. import javax.swing.JSpinner;
  19. import javax.swing.SpinnerNumberModel;
  20.  
  21. /**
  22.  *
  23.  * @author gorgo
  24.  */
  25. public class Addtrip3 extends javax.swing.JFrame {
  26.     Calendar cal = Calendar.getInstance();
  27.     int day = cal.get(Calendar.DATE);
  28.     int month = cal.get(Calendar.MONTH) + 1;
  29.     int year = cal.get(Calendar.YEAR);
  30.     int dow = cal.get(Calendar.DAY_OF_WEEK);
  31.     int dom = cal.get(Calendar.DAY_OF_MONTH);
  32.     int doy = cal.get(Calendar.DAY_OF_YEAR);
  33.     int hour = cal.get(Calendar.HOUR_OF_DAY);
  34.     int minutes = cal.get(Calendar.MINUTE);
  35.    
  36.     boolean checkDate = true;
  37.     boolean checkOP = true;
  38.     boolean checkOA = true;
  39.     /**
  40.      * Creates new form Addtrip3
  41.      */
  42.     public Addtrip3() {
  43.         initComponents();
  44.     }
  45.  
  46.     /**
  47.      * This method is called from within the constructor to initialize the form.
  48.      * WARNING: Do NOT modify this code. The content of this method is always
  49.      * regenerated by the Form Editor.
  50.      */
  51.     @SuppressWarnings("unchecked")
  52.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  53.     private void initComponents() {
  54.  
  55.         jPanel1 = new javax.swing.JPanel();
  56.         jLabel1 = new javax.swing.JLabel();
  57.         jLabel2 = new javax.swing.JLabel();
  58.         jLabel3 = new javax.swing.JLabel();
  59.         jLabel4 = new javax.swing.JLabel();
  60.         jLabel5 = new javax.swing.JLabel();
  61.         jLabel6 = new javax.swing.JLabel();
  62.         jLabel7 = new javax.swing.JLabel();
  63.         jLabel8 = new javax.swing.JLabel();
  64.         jLabel9 = new javax.swing.JLabel();
  65.         jTextPartenza = new javax.swing.JTextField();
  66.         jTextArrivo = new javax.swing.JTextField();
  67.         jTextCosto = new javax.swing.JTextField();
  68.         spinTripD = new javax.swing.JSpinner();
  69.         spinTripM = new javax.swing.JSpinner();
  70.         spinTripY = new javax.swing.JSpinner();
  71.         spinOPh = new javax.swing.JSpinner();
  72.         spinOPm = new javax.swing.JSpinner();
  73.         spinOAh = new javax.swing.JSpinner();
  74.         spinOAm = new javax.swing.JSpinner();
  75.         spinPosti = new javax.swing.JSpinner();
  76.         jTextInfo = new javax.swing.JTextField();
  77.         ErrorLabelDate = new javax.swing.JLabel();
  78.         OkLabelDate = new javax.swing.JLabel();
  79.         ErrorLabelHour1 = new javax.swing.JLabel();
  80.         OkLabelHour1 = new javax.swing.JLabel();
  81.         ErrorLabelHour2 = new javax.swing.JLabel();
  82.         OkLabelHour2 = new javax.swing.JLabel();
  83.         HoursPrevContainer = new javax.swing.JLabel();
  84.         jButton1 = new javax.swing.JButton();
  85.         jButton2 = new javax.swing.JButton();
  86.         jButton3 = new javax.swing.JButton();
  87.  
  88.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  89.  
  90.         jLabel1.setText("Riempi i seguenti campi con i dati della tratta");
  91.  
  92.         jLabel2.setText("Luogo Partenza:");
  93.  
  94.         jLabel3.setText("Luogo Arrivo:");
  95.  
  96.         jLabel4.setText("Data:");
  97.  
  98.         jLabel5.setText("Ora Partenza:");
  99.  
  100.         jLabel6.setText("Ora Prevista Arrivo:");
  101.  
  102.         jLabel7.setText("Costo per persona:");
  103.  
  104.         jLabel8.setText("Posti disponibili:");
  105.  
  106.         jLabel9.setText("Info:");
  107.  
  108.         jTextCosto.setText("0");
  109.  
  110.         spinTripD.setModel(new SpinnerNumberModel(day, 1, 31, 1));
  111.  
  112.         spinTripM.setModel(new SpinnerNumberModel(month, 1, 12, 1));
  113.  
  114.         spinTripY.setModel(new SpinnerNumberModel(year, 2012, 2015, 1));
  115.  
  116.         spinOPh.setModel(new SpinnerNumberModel(hour, 0, 23, 1));
  117.  
  118.         spinOPm.setModel(new SpinnerNumberModel(minutes, 0, 59, 1));
  119.  
  120.         spinOAh.setModel(new SpinnerNumberModel(hour, 0, 23, 1));
  121.  
  122.         spinOAm.setModel(new SpinnerNumberModel(minutes+1, 0, 59, 1));
  123.  
  124.         spinPosti.setModel(new SpinnerNumberModel(1, 1, 100, 1));
  125.  
  126.         ErrorLabelDate.setForeground(new java.awt.Color(255, 0, 0));
  127.         ErrorLabelDate.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
  128.         ErrorLabelDate.setText("Data non valida");
  129.         ErrorLabelDate.setFocusable(false);
  130.         ErrorLabelDate.setVisible(false);
  131.  
  132.         OkLabelDate.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
  133.         OkLabelDate.setVisible(true);
  134.  
  135.         ErrorLabelHour1.setForeground(new java.awt.Color(255, 0, 0));
  136.         ErrorLabelHour1.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
  137.         ErrorLabelHour1.setText("Ora non valida");
  138.         ErrorLabelHour1.setFocusable(false);
  139.         ErrorLabelDate.setVisible(false);
  140.         ErrorLabelHour1.setVisible(false);
  141.  
  142.         OkLabelHour1.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
  143.         OkLabelDate.setVisible(true);
  144.  
  145.         ErrorLabelHour2.setForeground(new java.awt.Color(255, 0, 0));
  146.         ErrorLabelHour2.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
  147.         ErrorLabelHour2.setText("Ora non valida");
  148.         ErrorLabelHour2.setFocusable(false);
  149.         ErrorLabelDate.setVisible(false);
  150.         ErrorLabelHour1.setVisible(false);
  151.         ErrorLabelHour2.setVisible(false);
  152.         OkLabelHour2.setVisible(false);
  153.  
  154.         OkLabelHour2.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
  155.         OkLabelHour2.setVisible(true);
  156.  
  157.         HoursPrevContainer.add(ErrorLabelHour2);
  158.         HoursPrevContainer.add(OkLabelHour2);
  159.  
  160.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  161.         jPanel1.setLayout(jPanel1Layout);
  162.         jPanel1Layout.setHorizontalGroup(
  163.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  164.             .addGroup(jPanel1Layout.createSequentialGroup()
  165.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  166.                     .addGroup(jPanel1Layout.createSequentialGroup()
  167.                         .addComponent(jLabel5)
  168.                         .addGap(18, 18, 18)
  169.                         .addComponent(spinOPh, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
  170.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  171.                         .addComponent(spinOPm, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
  172.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  173.                         .addComponent(ErrorLabelHour1)
  174.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  175.                         .addComponent(OkLabelHour1))
  176.                     .addComponent(jLabel1)
  177.                     .addGroup(jPanel1Layout.createSequentialGroup()
  178.                         .addComponent(jLabel2)
  179.                         .addGap(18, 18, 18)
  180.                         .addComponent(jTextPartenza, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
  181.                     .addGroup(jPanel1Layout.createSequentialGroup()
  182.                         .addComponent(jLabel3)
  183.                         .addGap(18, 18, 18)
  184.                         .addComponent(jTextArrivo, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
  185.                     .addGroup(jPanel1Layout.createSequentialGroup()
  186.                         .addComponent(jLabel4)
  187.                         .addGap(18, 18, 18)
  188.                         .addComponent(spinTripD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  189.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  190.                         .addComponent(spinTripM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  191.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  192.                         .addComponent(spinTripY, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
  193.                         .addGap(18, 18, 18)
  194.                         .addComponent(ErrorLabelDate)
  195.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  196.                         .addComponent(OkLabelDate)))
  197.                 .addGap(0, 0, Short.MAX_VALUE))
  198.             .addGroup(jPanel1Layout.createSequentialGroup()
  199.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  200.                     .addGroup(jPanel1Layout.createSequentialGroup()
  201.                         .addComponent(jLabel9)
  202.                         .addGap(18, 18, 18)
  203.                         .addComponent(jTextInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
  204.                     .addGroup(jPanel1Layout.createSequentialGroup()
  205.                         .addComponent(jLabel8)
  206.                         .addGap(18, 18, 18)
  207.                         .addComponent(spinPosti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  208.                     .addGroup(jPanel1Layout.createSequentialGroup()
  209.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  210.                             .addGroup(jPanel1Layout.createSequentialGroup()
  211.                                 .addComponent(jLabel6)
  212.                                 .addGap(6, 6, 6)
  213.                                 .addComponent(spinOAh, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
  214.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  215.                                 .addComponent(spinOAm, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
  216.                             .addGroup(jPanel1Layout.createSequentialGroup()
  217.                                 .addComponent(jLabel7)
  218.                                 .addGap(18, 18, 18)
  219.                                 .addComponent(jTextCosto)))
  220.                         .addGap(12, 12, 12)
  221.                         .addComponent(HoursPrevContainer)
  222.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  223.                         .addComponent(ErrorLabelHour2)
  224.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  225.                         .addComponent(OkLabelHour2)))
  226.                 .addContainerGap(139, Short.MAX_VALUE))
  227.         );
  228.         jPanel1Layout.setVerticalGroup(
  229.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  230.             .addGroup(jPanel1Layout.createSequentialGroup()
  231.                 .addComponent(jLabel1)
  232.                 .addGap(18, 18, 18)
  233.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  234.                     .addComponent(jLabel2)
  235.                     .addComponent(jTextPartenza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  236.                 .addGap(18, 18, 18)
  237.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  238.                     .addComponent(jLabel3)
  239.                     .addComponent(jTextArrivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  240.                 .addGap(18, 18, 18)
  241.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  242.                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  243.                         .addComponent(jLabel4)
  244.                         .addComponent(spinTripD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  245.                         .addComponent(spinTripM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  246.                         .addComponent(spinTripY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  247.                         .addComponent(ErrorLabelDate))
  248.                     .addComponent(OkLabelDate))
  249.                 .addGap(18, 18, 18)
  250.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  251.                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  252.                         .addComponent(jLabel5)
  253.                         .addComponent(spinOPh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  254.                         .addComponent(spinOPm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  255.                         .addComponent(ErrorLabelHour1))
  256.                     .addComponent(OkLabelHour1))
  257.                 .addGap(18, 18, 18)
  258.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  259.                     .addGroup(jPanel1Layout.createSequentialGroup()
  260.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  261.                             .addComponent(jLabel6)
  262.                             .addComponent(spinOAh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  263.                             .addComponent(spinOAm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  264.                             .addComponent(ErrorLabelHour2)
  265.                             .addComponent(HoursPrevContainer))
  266.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  267.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  268.                             .addComponent(jLabel7)
  269.                             .addComponent(jTextCosto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  270.                         .addGap(18, 18, 18)
  271.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  272.                             .addComponent(jLabel8)
  273.                             .addComponent(spinPosti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  274.                         .addGap(18, 18, 18)
  275.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  276.                             .addComponent(jLabel9)
  277.                             .addComponent(jTextInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  278.                     .addComponent(OkLabelHour2))
  279.                 .addContainerGap(22, Short.MAX_VALUE))
  280.         );
  281.  
  282.         JSpinner.DefaultEditor editorD = (JSpinner.DefaultEditor) spinTripD.getEditor();
  283.         editorD.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  284.             public void focusLost(java.awt.event.FocusEvent evt) {
  285.                 spinTripDFocusLost(evt);
  286.             }
  287.         });
  288.         JSpinner.DefaultEditor editorM = (JSpinner.DefaultEditor) spinTripM.getEditor();
  289.         editorM.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  290.             public void focusLost(java.awt.event.FocusEvent evt) {
  291.                 spinTripDFocusLost(evt);
  292.             }
  293.         });
  294.         JSpinner.DefaultEditor editorY = (JSpinner.DefaultEditor) spinTripY.getEditor();
  295.         editorY.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  296.             public void focusLost(java.awt.event.FocusEvent evt) {
  297.                 spinTripDFocusLost(evt);
  298.             }
  299.         });
  300.         JSpinner.DefaultEditor editorHP = (JSpinner.DefaultEditor) spinOPh.getEditor();
  301.         editorHP.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  302.             public void focusLost(java.awt.event.FocusEvent evt) {
  303.                 spinTripOPFocusLost(evt);
  304.             }
  305.         });
  306.         JSpinner.DefaultEditor editorMP = (JSpinner.DefaultEditor) spinOPm.getEditor();
  307.         editorMP.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  308.             public void focusLost(java.awt.event.FocusEvent evt) {
  309.                 spinTripOPFocusLost(evt);
  310.             }
  311.         });
  312.         JSpinner.DefaultEditor editorHA = (JSpinner.DefaultEditor) spinOAh.getEditor();
  313.         editorHA.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  314.             public void focusLost(java.awt.event.FocusEvent evt) {
  315.                 spinTripOAFocusLost(evt);
  316.             }
  317.         });
  318.         JSpinner.DefaultEditor editorMA = (JSpinner.DefaultEditor) spinOAm.getEditor();
  319.         editorMA.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
  320.             public void focusLost(java.awt.event.FocusEvent evt) {
  321.                 spinTripOAFocusLost(evt);
  322.             }
  323.         });
  324.  
  325.         jButton1.setText("Aggiungi Percorso");
  326.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  327.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  328.                 jButton1ActionPerformed(evt);
  329.             }
  330.         });
  331.  
  332.         jButton2.setText("Annulla");
  333.  
  334.         jButton3.setText("Clear");
  335.  
  336.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  337.         getContentPane().setLayout(layout);
  338.         layout.setHorizontalGroup(
  339.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  340.             .addGroup(layout.createSequentialGroup()
  341.                 .addContainerGap()
  342.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  343.                     .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  344.                     .addGroup(layout.createSequentialGroup()
  345.                         .addComponent(jButton2)
  346.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  347.                         .addComponent(jButton3)
  348.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  349.                         .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
  350.                 .addContainerGap())
  351.         );
  352.         layout.setVerticalGroup(
  353.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  354.             .addGroup(layout.createSequentialGroup()
  355.                 .addContainerGap()
  356.                 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  357.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  358.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  359.                     .addComponent(jButton1)
  360.                     .addComponent(jButton2)
  361.                     .addComponent(jButton3))
  362.                 .addContainerGap())
  363.         );
  364.  
  365.         pack();
  366.     }// </editor-fold>
  367.  
  368.     private String makeid(){
  369.        
  370.     Random r = new Random();
  371.     String token = Long.toString(Math.abs(r.nextLong()), 36);
  372.     return token;
  373.    
  374.     }
  375.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  376.         checkDate = checkDate();
  377.         checkOP = checkOP();
  378.         checkOA = checkOA();
  379.         System.out.println(makeid());
  380.        
  381.         if( checkDate && checkOP && checkOA ){
  382.             try {
  383.                 Tratta.addTratta(makeid(),
  384.                         jTextPartenza.getText(), //Partenza
  385.                         jTextArrivo.getText(), //Arrivo
  386.                         spinTripY.getValue() + "-" + spinTripM.getValue() + "-" + spinTripD.getValue(), //Data
  387.                         spinOPh.getValue().toString(), //Ora Partenza
  388.                         spinOPm.getValue().toString(), //Min Partenza
  389.                         spinOAh.getValue().toString(), //Ora arrivo
  390.                         spinOAm.getValue().toString(), //Min arrivo
  391.                         jTextCosto.getText(), //Costo
  392.                         spinPosti.getValue().toString(), //Posti disponibili
  393.                         Login.logged.getUsers(),
  394.                         jTextInfo.getText()
  395.                         );
  396.             } catch (    NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException | TimeoutException ex) {
  397.                 Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
  398.             } catch (MalformedURLException ex) {
  399.                 Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
  400.             } catch (IOException ex) {
  401.                 Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
  402.             }
  403.             System.out.println("Tratta AGGIUNTA");
  404.             try {
  405.                 Carpooling2.mainPage2.tripRepaint();
  406.             } catch (MalformedURLException ex) {
  407.                 Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
  408.             } catch (Exception ex) {
  409.                 Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
  410.             }
  411.            
  412.             setVisible(false);
  413.             return;
  414.         }
  415.        
  416.         if (checkDate == false){
  417.             OkLabelDate.setVisible(false);
  418.             ErrorLabelDate.setVisible(true);
  419.         }
  420.        
  421.         if (checkOP == false){
  422.             OkLabelHour1.setVisible(false);
  423.             ErrorLabelHour1.setVisible(true);
  424.         }
  425.        
  426.         if(checkOA == false){
  427.             OkLabelHour2.setVisible(false);
  428.             ErrorLabelHour2.setVisible(true);
  429.         }
  430.        
  431.        JOptionPane.showMessageDialog(null,
  432.                "Ricontrolla i valori inseriti",
  433.                "Inane error",
  434.                JOptionPane.ERROR_MESSAGE);
  435.     }                                        
  436.  
  437.     private void spinTripDFocusLost(java.awt.event.FocusEvent evt){
  438.         if ( (Integer)spinTripY.getValue() < year ){
  439.             checkDate = false;
  440.             ErrorLabelDate.setVisible(true);
  441.             OkLabelDate.setVisible(false);
  442.         }
  443.         else if ( (Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() < month){
  444.             checkDate = false;
  445.             ErrorLabelDate.setVisible(true);
  446.             OkLabelDate.setVisible(false);
  447.         }
  448.         else if ( (Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() == month && (Integer)spinTripD.getValue() < day ){
  449.             checkDate = false;
  450.             ErrorLabelDate.setVisible(true);
  451.             OkLabelDate.setVisible(false);
  452.         }
  453.         else{
  454.             checkDate = true;
  455.             ErrorLabelDate.setVisible(false);
  456.             OkLabelDate.setVisible(true);
  457.         }    
  458.     }
  459.    
  460.     private void spinTripOPFocusLost(java.awt.event.FocusEvent evt){
  461.         if ( (Integer)spinTripY.getValue() == year &&
  462.                 (Integer)spinTripM.getValue() == month &&
  463.                 (Integer)spinTripD.getValue() == day &&
  464.                 (Integer)spinOPh.getValue() < hour){
  465.             checkOP = false;
  466.             ErrorLabelHour1.setVisible(true);
  467.             OkLabelHour1.setVisible(false);
  468.         }
  469.         else if ((Integer)spinTripY.getValue() == year &&
  470.                 (Integer)spinTripM.getValue() == month &&
  471.                 (Integer)spinTripD.getValue() == day &&
  472.                 (Integer)spinOPh.getValue() == hour &&
  473.                 (Integer)spinOPm.getValue() < minutes){
  474.             checkOP = false;
  475.             ErrorLabelHour1.setVisible(true);
  476.             OkLabelHour1.setVisible(false);
  477.         }
  478.         else {
  479.             checkOP = true;
  480.             ErrorLabelHour1.setVisible(false);
  481.             OkLabelHour1.setVisible(true);
  482.         }
  483.     }
  484.     private void spinTripOAFocusLost(java.awt.event.FocusEvent evt){
  485.         if ( (Integer)spinTripY.getValue() == year &&
  486.                 (Integer)spinTripM.getValue() == month &&
  487.                 (Integer)spinTripD.getValue() == day &&
  488.                 (Integer)spinOPh.getValue() > (Integer)spinOAh.getValue()){
  489.             checkOA = false;
  490.             ErrorLabelHour2.setVisible(true);
  491.             OkLabelHour2.setVisible(false);
  492.         }
  493.         else if ( (Integer)spinTripY.getValue() == year &&
  494.                 (Integer)spinTripM.getValue() == month &&
  495.                 (Integer)spinTripD.getValue() == day &&
  496.                 (Integer)spinOPh.getValue() == (Integer)spinOAh.getValue() &&
  497.                 (Integer)spinOPm.getValue() >= (Integer)spinOAm.getValue()){
  498.             checkOA = false;
  499.             ErrorLabelHour2.setVisible(true);
  500.             OkLabelHour2.setVisible(false);
  501.         }
  502.         else {
  503.              checkOA = true;
  504.              ErrorLabelHour2.setVisible(false);
  505.              OkLabelHour2.setVisible(true);
  506.         }
  507.     }
  508.    
  509.     private boolean checkDate(){
  510.         if (((Integer)spinTripY.getValue() < year) ||
  511.                 ((Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() < month) ||
  512.                 (Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() == month && (Integer)spinTripD.getValue() < day )
  513.             return false;
  514.         else
  515.                 return true;
  516.     }
  517.    
  518.     private boolean checkOP(){
  519.         if ( ((Integer)spinTripY.getValue() == year &&
  520.                 (Integer)spinTripM.getValue() == month &&
  521.                 (Integer)spinTripD.getValue() == day &&
  522.                 (Integer)spinOPh.getValue() < hour ) ||
  523.                 ( (Integer)spinTripY.getValue() == year &&
  524.                 (Integer)spinTripM.getValue() == month &&
  525.                 (Integer)spinTripD.getValue() == day &&
  526.                 (Integer)spinOPh.getValue() == hour &&
  527.                 (Integer)spinOPm.getValue() < minutes) )
  528.             return false;
  529.         else
  530.             return true;            
  531.     }
  532.    
  533.     private boolean checkOA(){
  534.         if ( ((Integer)spinTripY.getValue() == year &&
  535.                 (Integer)spinTripM.getValue() == month &&
  536.                 (Integer)spinTripD.getValue() == day &&
  537.                 (Integer)spinOPh.getValue() > (Integer)spinOAh.getValue()) ||
  538.                 ( (Integer)spinTripY.getValue() == year &&
  539.                 (Integer)spinTripM.getValue() == month &&
  540.                 (Integer)spinTripD.getValue() == day &&
  541.                 (Integer)spinOPh.getValue() == (Integer)spinOAh.getValue() &&
  542.                 (Integer)spinOPm.getValue() >= (Integer)spinOAm.getValue()))
  543.             return false;
  544.         else
  545.             return true;
  546.     }
  547.  
  548.     /**
  549.      * @param args the command line arguments
  550.      */
  551.     public static void main(String args[]) {
  552.         /*
  553.          * Set the Nimbus look and feel
  554.          */
  555.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  556.         /*
  557.          * If Nimbus (introduced in Java SE 6) is not available, stay with the
  558.          * default look and feel. For details see
  559.          * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  560.          */
  561.         try {
  562.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  563.                 if ("Nimbus".equals(info.getName())) {
  564.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  565.                     break;
  566.                 }
  567.             }
  568.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
  569.             java.util.logging.Logger.getLogger(Addtrip3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  570.         }
  571.         //</editor-fold>
  572.  
  573.         /*
  574.          * Create and display the form
  575.          */
  576.         java.awt.EventQueue.invokeLater(new Runnable() {
  577.  
  578.             @Override
  579.             public void run() {
  580.                 new Addtrip3().setVisible(true);
  581.             }
  582.         });
  583.     }
  584.     // Variables declaration - do not modify
  585.     private javax.swing.JLabel ErrorLabelDate;
  586.     private javax.swing.JLabel ErrorLabelHour1;
  587.     private javax.swing.JLabel ErrorLabelHour2;
  588.     private javax.swing.JLabel HoursPrevContainer;
  589.     private javax.swing.JLabel OkLabelDate;
  590.     private javax.swing.JLabel OkLabelHour1;
  591.     private javax.swing.JLabel OkLabelHour2;
  592.     private javax.swing.JButton jButton1;
  593.     private javax.swing.JButton jButton2;
  594.     private javax.swing.JButton jButton3;
  595.     private javax.swing.JLabel jLabel1;
  596.     private javax.swing.JLabel jLabel2;
  597.     private javax.swing.JLabel jLabel3;
  598.     private javax.swing.JLabel jLabel4;
  599.     private javax.swing.JLabel jLabel5;
  600.     private javax.swing.JLabel jLabel6;
  601.     private javax.swing.JLabel jLabel7;
  602.     private javax.swing.JLabel jLabel8;
  603.     private javax.swing.JLabel jLabel9;
  604.     private javax.swing.JPanel jPanel1;
  605.     private javax.swing.JTextField jTextArrivo;
  606.     private javax.swing.JTextField jTextCosto;
  607.     private javax.swing.JTextField jTextInfo;
  608.     private javax.swing.JTextField jTextPartenza;
  609.     private javax.swing.JSpinner spinOAh;
  610.     private javax.swing.JSpinner spinOAm;
  611.     private javax.swing.JSpinner spinOPh;
  612.     private javax.swing.JSpinner spinOPm;
  613.     private javax.swing.JSpinner spinPosti;
  614.     private javax.swing.JSpinner spinTripD;
  615.     private javax.swing.JSpinner spinTripM;
  616.     private javax.swing.JSpinner spinTripY;
  617.     // End of variables declaration
  618. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement