Io ho il seguente pezzo di codice:
----------------------------------------------------------------
//Se l'utente clicca su new
if ( (e.getSource() == button_new) || (e.getSource() == file_new)) {
list_rec = new Node[1];
String giorno = null;
giorno = (JOptionPane.showInputDialog(this, "Inserisci il giorno"));
try {
int new_day = Integer.parseInt(giorno);
String mese = null;
mese = (JOptionPane.showInputDialog(this, "Inserisci il mese"));
int new_month = Integer.parseInt(mese);
String anno = null;
anno = (JOptionPane.showInputDialog(this, "Inserisci l'anno"));
int new_year = Integer.parseInt(anno);
String new_ora = JOptionPane.showInputDialog(this, "Inserisci l'ora");
SimpleDateFormat shf = new SimpleDateFormat("hh:mm");
Date ora = shf.parse(new_ora);
String new_luogo = JOptionPane.showInputDialog(this,
"Inserisci il luogo");
String new_object = JOptionPane.showInputDialog(this,
"Inserisci l'oggetto ");
String new_note = JOptionPane.showInputDialog(this,
"Inserisci delle note particolari riferite all'appuntamento");
list_rec[list_rec.length -
1] = new Node(new_day, new_month, new_year, ora, new_luogo,
new_object, new_note);
count = list_rec.length - 1;
set_text();
button_new.setEnabled(false);
set();
}
catch (ParseException pe) {
JOptionPane.showMessageDialog(this, "Formato dati non valido");
}
}
--------------------------------------------------------------------
E voglio che nei campi new_day, new_year, new_month avessi dei numeri che si, inserisco con le InputDialog, ma che siano anche racchiusi in un certo intervallo (Ad esempio i giorni voglio che l'utente dia un numero da 1 a 31 altrimenti viene segnalato errore).
Ho provato a mettere degli if ma non vanno.Come posos fare?
tnx a tutti![]()