/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package carpoolingGUI;
import carpooling.Carpooling2;
import carpooling.Login;
import carpooling.Tratta;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Random;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
/**
*
* @author gorgo
*/
public class Addtrip3 extends javax.swing.JFrame {
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
int dow = cal.get(Calendar.DAY_OF_WEEK);
int dom = cal.get(Calendar.DAY_OF_MONTH);
int doy = cal.get(Calendar.DAY_OF_YEAR);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
boolean checkDate = true;
boolean checkOP = true;
boolean checkOA = true;
/**
* Creates new form Addtrip3
*/
public Addtrip3() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jTextPartenza = new javax.swing.JTextField();
jTextArrivo = new javax.swing.JTextField();
jTextCosto = new javax.swing.JTextField();
spinTripD = new javax.swing.JSpinner();
spinTripM = new javax.swing.JSpinner();
spinTripY = new javax.swing.JSpinner();
spinOPh = new javax.swing.JSpinner();
spinOPm = new javax.swing.JSpinner();
spinOAh = new javax.swing.JSpinner();
spinOAm = new javax.swing.JSpinner();
spinPosti = new javax.swing.JSpinner();
jTextInfo = new javax.swing.JTextField();
ErrorLabelDate = new javax.swing.JLabel();
OkLabelDate = new javax.swing.JLabel();
ErrorLabelHour1 = new javax.swing.JLabel();
OkLabelHour1 = new javax.swing.JLabel();
ErrorLabelHour2 = new javax.swing.JLabel();
OkLabelHour2 = new javax.swing.JLabel();
HoursPrevContainer = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Riempi i seguenti campi con i dati della tratta");
jLabel2.setText("Luogo Partenza:");
jLabel3.setText("Luogo Arrivo:");
jLabel4.setText("Data:");
jLabel5.setText("Ora Partenza:");
jLabel6.setText("Ora Prevista Arrivo:");
jLabel7.setText("Costo per persona:");
jLabel8.setText("Posti disponibili:");
jLabel9.setText("Info:");
jTextCosto.setText("0");
spinTripD.setModel(new SpinnerNumberModel(day, 1, 31, 1));
spinTripM.setModel(new SpinnerNumberModel(month, 1, 12, 1));
spinTripY.setModel(new SpinnerNumberModel(year, 2012, 2015, 1));
spinOPh.setModel(new SpinnerNumberModel(hour, 0, 23, 1));
spinOPm.setModel(new SpinnerNumberModel(minutes, 0, 59, 1));
spinOAh.setModel(new SpinnerNumberModel(hour, 0, 23, 1));
spinOAm.setModel(new SpinnerNumberModel(minutes+1, 0, 59, 1));
spinPosti.setModel(new SpinnerNumberModel(1, 1, 100, 1));
ErrorLabelDate.setForeground(new java.awt.Color(255, 0, 0));
ErrorLabelDate.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
ErrorLabelDate.setText("Data non valida");
ErrorLabelDate.setFocusable(false);
ErrorLabelDate.setVisible(false);
OkLabelDate.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
OkLabelDate.setVisible(true);
ErrorLabelHour1.setForeground(new java.awt.Color(255, 0, 0));
ErrorLabelHour1.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
ErrorLabelHour1.setText("Ora non valida");
ErrorLabelHour1.setFocusable(false);
ErrorLabelDate.setVisible(false);
ErrorLabelHour1.setVisible(false);
OkLabelHour1.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
OkLabelDate.setVisible(true);
ErrorLabelHour2.setForeground(new java.awt.Color(255, 0, 0));
ErrorLabelHour2.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Delete_32.png")); // NOI18N
ErrorLabelHour2.setText("Ora non valida");
ErrorLabelHour2.setFocusable(false);
ErrorLabelDate.setVisible(false);
ErrorLabelHour1.setVisible(false);
ErrorLabelHour2.setVisible(false);
OkLabelHour2.setVisible(false);
OkLabelHour2.setIcon(new javax.swing.ImageIcon("/home/gorgo/NetBeansProjects/carpooling/src/carpoolingGUI/Symbol - Check_32.png")); // NOI18N
OkLabelHour2.setVisible(true);
HoursPrevContainer.add(ErrorLabelHour2);
HoursPrevContainer.add(OkLabelHour2);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(spinOPh, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spinOPm, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ErrorLabelHour1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(OkLabelHour1))
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jTextPartenza, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jTextArrivo, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(18, 18, 18)
.addComponent(spinTripD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spinTripM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spinTripY, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(ErrorLabelDate)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(OkLabelDate)))
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel9)
.addGap(18, 18, 18)
.addComponent(jTextInfo, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel8)
.addGap(18, 18, 18)
.addComponent(spinPosti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(6, 6, 6)
.addComponent(spinOAh, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spinOAm, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(18, 18, 18)
.addComponent(jTextCosto)))
.addGap(12, 12, 12)
.addComponent(HoursPrevContainer)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ErrorLabelHour2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(OkLabelHour2)))
.addContainerGap(139, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextPartenza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextArrivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(spinTripD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinTripM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinTripY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ErrorLabelDate))
.addComponent(OkLabelDate))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(spinOPh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinOPm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ErrorLabelHour1))
.addComponent(OkLabelHour1))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(spinOAh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(spinOAm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ErrorLabelHour2)
.addComponent(HoursPrevContainer))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jTextCosto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(spinPosti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jTextInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(OkLabelHour2))
.addContainerGap(22, Short.MAX_VALUE))
);
JSpinner.DefaultEditor editorD = (JSpinner.DefaultEditor) spinTripD.getEditor();
editorD.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripDFocusLost(evt);
}
});
JSpinner.DefaultEditor editorM = (JSpinner.DefaultEditor) spinTripM.getEditor();
editorM.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripDFocusLost(evt);
}
});
JSpinner.DefaultEditor editorY = (JSpinner.DefaultEditor) spinTripY.getEditor();
editorY.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripDFocusLost(evt);
}
});
JSpinner.DefaultEditor editorHP = (JSpinner.DefaultEditor) spinOPh.getEditor();
editorHP.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripOPFocusLost(evt);
}
});
JSpinner.DefaultEditor editorMP = (JSpinner.DefaultEditor) spinOPm.getEditor();
editorMP.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripOPFocusLost(evt);
}
});
JSpinner.DefaultEditor editorHA = (JSpinner.DefaultEditor) spinOAh.getEditor();
editorHA.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripOAFocusLost(evt);
}
});
JSpinner.DefaultEditor editorMA = (JSpinner.DefaultEditor) spinOAm.getEditor();
editorMA.getTextField().addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
spinTripOAFocusLost(evt);
}
});
jButton1.setText("Aggiungi Percorso");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Annulla");
jButton3.setText("Clear");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap())
);
pack();
}// </editor-fold>
private String makeid(){
Random r = new Random();
String token = Long.toString(Math.abs(r.nextLong()), 36);
return token;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
checkDate = checkDate();
checkOP = checkOP();
checkOA = checkOA();
System.out.println(makeid());
if( checkDate && checkOP && checkOA ){
try {
Tratta.addTratta(makeid(),
jTextPartenza.getText(), //Partenza
jTextArrivo.getText(), //Arrivo
spinTripY.getValue() + "-" + spinTripM.getValue() + "-" + spinTripD.getValue(), //Data
spinOPh.getValue().toString(), //Ora Partenza
spinOPm.getValue().toString(), //Min Partenza
spinOAh.getValue().toString(), //Ora arrivo
spinOAm.getValue().toString(), //Min arrivo
jTextCosto.getText(), //Costo
spinPosti.getValue().toString(), //Posti disponibili
Login.logged.getUsers(),
jTextInfo.getText()
);
} catch ( NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException | TimeoutException ex) {
Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Tratta AGGIUNTA");
try {
Carpooling2.mainPage2.tripRepaint();
} catch (MalformedURLException ex) {
Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(Addtrip3.class.getName()).log(Level.SEVERE, null, ex);
}
setVisible(false);
return;
}
if (checkDate == false){
OkLabelDate.setVisible(false);
ErrorLabelDate.setVisible(true);
}
if (checkOP == false){
OkLabelHour1.setVisible(false);
ErrorLabelHour1.setVisible(true);
}
if(checkOA == false){
OkLabelHour2.setVisible(false);
ErrorLabelHour2.setVisible(true);
}
JOptionPane.showMessageDialog(null,
"Ricontrolla i valori inseriti",
"Inane error",
JOptionPane.ERROR_MESSAGE);
}
private void spinTripDFocusLost(java.awt.event.FocusEvent evt){
if ( (Integer)spinTripY.getValue() < year ){
checkDate = false;
ErrorLabelDate.setVisible(true);
OkLabelDate.setVisible(false);
}
else if ( (Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() < month){
checkDate = false;
ErrorLabelDate.setVisible(true);
OkLabelDate.setVisible(false);
}
else if ( (Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() == month && (Integer)spinTripD.getValue() < day ){
checkDate = false;
ErrorLabelDate.setVisible(true);
OkLabelDate.setVisible(false);
}
else{
checkDate = true;
ErrorLabelDate.setVisible(false);
OkLabelDate.setVisible(true);
}
}
private void spinTripOPFocusLost(java.awt.event.FocusEvent evt){
if ( (Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() < hour){
checkOP = false;
ErrorLabelHour1.setVisible(true);
OkLabelHour1.setVisible(false);
}
else if ((Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() == hour &&
(Integer)spinOPm.getValue() < minutes){
checkOP = false;
ErrorLabelHour1.setVisible(true);
OkLabelHour1.setVisible(false);
}
else {
checkOP = true;
ErrorLabelHour1.setVisible(false);
OkLabelHour1.setVisible(true);
}
}
private void spinTripOAFocusLost(java.awt.event.FocusEvent evt){
if ( (Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() > (Integer)spinOAh.getValue()){
checkOA = false;
ErrorLabelHour2.setVisible(true);
OkLabelHour2.setVisible(false);
}
else if ( (Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() == (Integer)spinOAh.getValue() &&
(Integer)spinOPm.getValue() >= (Integer)spinOAm.getValue()){
checkOA = false;
ErrorLabelHour2.setVisible(true);
OkLabelHour2.setVisible(false);
}
else {
checkOA = true;
ErrorLabelHour2.setVisible(false);
OkLabelHour2.setVisible(true);
}
}
private boolean checkDate(){
if (((Integer)spinTripY.getValue() < year) ||
((Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() < month) ||
(Integer)spinTripY.getValue() == year && (Integer)spinTripM.getValue() == month && (Integer)spinTripD.getValue() < day )
return false;
else
return true;
}
private boolean checkOP(){
if ( ((Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() < hour ) ||
( (Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() == hour &&
(Integer)spinOPm.getValue() < minutes) )
return false;
else
return true;
}
private boolean checkOA(){
if ( ((Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() > (Integer)spinOAh.getValue()) ||
( (Integer)spinTripY.getValue() == year &&
(Integer)spinTripM.getValue() == month &&
(Integer)spinTripD.getValue() == day &&
(Integer)spinOPh.getValue() == (Integer)spinOAh.getValue() &&
(Integer)spinOPm.getValue() >= (Integer)spinOAm.getValue()))
return false;
else
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Addtrip3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Addtrip3().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel ErrorLabelDate;
private javax.swing.JLabel ErrorLabelHour1;
private javax.swing.JLabel ErrorLabelHour2;
private javax.swing.JLabel HoursPrevContainer;
private javax.swing.JLabel OkLabelDate;
private javax.swing.JLabel OkLabelHour1;
private javax.swing.JLabel OkLabelHour2;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextArrivo;
private javax.swing.JTextField jTextCosto;
private javax.swing.JTextField jTextInfo;
private javax.swing.JTextField jTextPartenza;
private javax.swing.JSpinner spinOAh;
private javax.swing.JSpinner spinOAm;
private javax.swing.JSpinner spinOPh;
private javax.swing.JSpinner spinOPm;
private javax.swing.JSpinner spinPosti;
private javax.swing.JSpinner spinTripD;
private javax.swing.JSpinner spinTripM;
private javax.swing.JSpinner spinTripY;
// End of variables declaration
}