Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Sauber - Sauber.java

Sauber.java

Caricato da: Netarrow
Scarica il programma completo

  1. import javax.microedition.lcdui.*;
  2. import javax.microedition.midlet.*;
  3.  
  4. import java.util.*;
  5.  
  6. public class Sauber extends MIDlet implements CommandListener {
  7.   private Display display;
  8.   private Form form;
  9.   private TextField data1;
  10.   private TextField data2;
  11.   private ChoiceGroup opzioni;
  12.   private Command ok;
  13.   private Command okAlert;
  14.   private Command exit;
  15.   private DateField aDateField, bDateField;
  16.  
  17.   public void commandAction(Command c, Displayable s){
  18.     if(c == ok) {
  19.        Data begin = new Data(aDateField.getDate());
  20.        Data end = new Data(bDateField.getDate());
  21.  
  22.      if(opzioni.getSelectedIndex() == 0) {
  23.        long days = begin.getDays(end);
  24.        display.setCurrent(createResultMsg("Fra le due date " + (days == 1 ? "passa ":"passano ") + days + (days == 1 ? " giorno.":" giorni.")));
  25. } else if(opzioni.getSelectedIndex() == 1) {
  26. long mesi = begin.getMonth(end);
  27.        display.setCurrent(createResultMsg("Fra le due date passano: " + mesi/10 + "," + (mesi - (mesi/10)*10) + " mesi."));
  28. }
  29.  
  30.         } else if(c == exit) {
  31.        destroyApp(true);
  32.       }
  33.   }
  34.  
  35.   public void destroyApp(boolean unconditional) {
  36.     notifyDestroyed();
  37.   }
  38.  
  39.   private Alert createResultMsg(String res) {
  40.   Alert result = new Alert("Risultato", res, null, AlertType.INFO);
  41.   result.setTimeout(Alert.FOREVER);
  42.   return result;
  43. }
  44.  
  45.   private Alert createErrorMessage(String msg) {
  46.    return new Alert("Errore", msg, null, AlertType.ERROR);
  47.   }
  48.  
  49.   public void pauseApp() {
  50.          
  51.   }
  52.  
  53.   private void init() {
  54.     display = Display.getDisplay(this);
  55.     form = new Form("Sauber - il contagiorni by Matteo");
  56.     aDateField = new DateField("Inserire data di partenza", DateField.DATE);
  57.     bDateField = new DateField("Inserire data di arrivo", DateField.DATE);
  58.     opzioni = new ChoiceGroup("Inserire formato uscita", ChoiceGroup.EXCLUSIVE, new String[] {"Giorni", "Mesi"}, null);
  59.     ok = new Command("Calcola!", Command.OK, 1);
  60.     exit = new Command("Exit", Command.EXIT, 1);
  61.     form.setCommandListener(this);
  62.     okAlert = new Command("Ok", Command.OK, 1);
  63.   }
  64.  
  65.   public void startApp() {
  66.     init();
  67.     form.append(aDateField);
  68.     form.append(bDateField);
  69.     form.append(opzioni);
  70.     form.addCommand(ok);
  71.     form.addCommand(exit);
  72.     display.setCurrent(form);
  73.   }
  74. }