P:\PROJEKTY\PlanLekcji - Studia (2 semestr)\src\hello\HelloMIDlet.java |
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package hello; //import java.util.Calendar; import java.util.*; import java.util.Date.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import org.netbeans.microedition.lcdui.SplashScreen; //import javax.microedition.io.*; //import org.netbeans.microedition.lcdui.WaitScreen; import org.netbeans.microedition.util.SimpleCancellableTask; /** * @author Dawid */ public class HelloMIDlet extends MIDlet implements CommandListener { private boolean midletPaused = false; //<editor-fold defaultstate="collapsed" desc="główne zmienne programu"> private int dzien=0,//dzien (0...6) h=0, //godzina (0..11) min=0; //minuta (0..59) String sBuffor=""; //zmienna pomocnicza int podlad_dzien_id = 0;//ten dzien wlasnie ogladasz //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Dane programu źródło: UMK"> private int max_day_list = 13;//zakładana maksymalną ilość lekcji + przerw w dniu private String sLekcje[][]= { //0 - poniedziałek { /* 8:00*/"1: Dane 22", /* 9:00*/"2: -", /*10:00*/"3: -", /*11:00*/"4: fiza 26", /*12:00*/"5: fiza 26", /*13:00*/"6: -", /*14:00*/"7: Statystyka 22", /*15:00*/"8: Statystyka 22", /*16:00*/"9: kurs C PK6", /*17:00*/"10:kurs C PK6", /*18:00*/"11:kurs C PK6", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", }, //1 - wtorek { /* 8:00*/"1: Prog. PK4", /* 9:00*/"2: Prog. PK4", /*10:00*/"3: Prog. 20", /*11:00*/"4: Prog. 20", /*12:00*/"5: -", /*13:00*/"6: -", /*14:00*/"7: Dysk. 25", /*15:00*/"8: Dysk. 25", /*16:00*/"9: Dysk. 24", /*17:00*/"10:Dysk. 24", /*18:00*/"11:-", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", }, //2 - środa { /* 8:00*/"1: BHP aula", /* 9:00*/"2: BHP aula", /*10:00*/"3: BHP aula", /*11:00*/"4: Analiza mat (cw) s.23", /*12:00*/"5: Analiza mat (cw) s.23", /*13:00*/"6: Analiza mat (cw) s.23", /*14:00*/"7: Archit.sys.kom.(wyk) s.26", /*15:00*/"8: Archit.sys.kom.(wyk) s.26", /*16:00*/"9: Archit.sys.kom.(wyk) s.26", /*17:00*/"10:-", /*18:00*/"11:-", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", }, //3 - czwartek { /* 8:00*/"1: WWW PK6", /* 9:00*/"2: WWW PK6", /*10:00*/"3: WWW PK6", /*11:00*/"4: -", /*12:00*/"5: WWW 25", /*13:00*/"6: WWW 25", /*14:00*/"7: -", /*15:00*/"8: -", /*16:00*/"9: -", /*17:00*/"10:-", /*18:00*/"11:-", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", }, //4 - piątek { /* 8:00*/"1: Stat. 29", /* 9:00*/"2: Stat. 29", /*10:00*/"3: Dane. 20", /*11:00*/"4: Fiza 26", /*12:00*/"5: Fiza 26", /*13:00*/"6: -", /*14:00*/"7: Projekt PK5", /*15:00*/"8: Projekt PK5", /*16:00*/"9: -", /*17:00*/"10:psych WSP", /*18:00*/"11:psych WSP", /*19:00*/"12:Winsdows PK6", /*20:00*/"13:Winsdows PK6", /*21:00*/"14:-", }, //5 - sobota { /* 8:00*/"1: Fiza PF1", /* 9:00*/"2: Fiza PF1", /*10:00*/"3: Fiza PF1", /*11:00*/"4: -", /*12:00*/"5: -", /*13:00*/"6: Projekt 20", /*14:00*/"7: Projekt 20", /*15:00*/"8: -", /*16:00*/"9: -", /*17:00*/"10:-", /*18:00*/"11:-", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", }, //6 - niedziela { /* 8:00*/"1: -", /* 9:00*/"2: -", /*10:00*/"3: -", /*11:00*/"4: -", /*12:00*/"5: -", /*13:00*/"6: -", /*14:00*/"7: -", /*15:00*/"8: -", /*16:00*/"9: -", /*17:00*/"10:-", /*18:00*/"11:-", /*19:00*/"12:-", /*20:00*/"13:-", /*21:00*/"14:-", } }; //długości przerw (0...max_day_list) int przerwy[] = { /* 0:*/0, /* 1:*/0, /* 2:*/0, /* 3:*/0, /* 4:*/0, /* 5:*/0, /* 6:*/0, /* 7:*/5, /* 8:*/5, /* 9:*/5, /*10:*/0, /*11:*/0, /*12:*/0, /*13:*/0, /*14:*/0 }; //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Fields "> private Command exitCommand; private Command dzisCommand; private Command tydzienCommand; private Command okCommand1; private Command backCommand; private Command okCommand2; private Command forwardCommand; private Command okCommand; private Command backwardCommand1; private Command forwardCommand1; private Form main; private StringItem stringItem; private SplashScreen WelcomeSplashScreen; private SplashScreen ByeByeSplashScreen; private Form tydzien; private StringItem stringItem2; private SimpleCancellableTask task; private SimpleCancellableTask task1; private SimpleCancellableTask task2; private SimpleCancellableTask task3; private Ticker ticker; //</editor-fold> /** * The HelloMIDlet constructor. */ public HelloMIDlet() { } //<editor-fold defaultstate="collapsed" desc=" Generated Methods "> //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize "> /** * Initilizes the application. * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method. */ private void initialize() { // write pre-initialize user code here // //zerowanie danych { dzien=0; h=0; min=0; sBuffor=""; podlad_dzien_id = 0; } // write post-initialize user code here } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet "> /** * Performs an action assigned to the Mobile Device - MIDlet Started point. */ public void startMIDlet() { // write pre-action user code here switchDisplayable(null, getWelcomeSplashScreen()); // write post-action user code here } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet "> /** * Performs an action assigned to the Mobile Device - MIDlet Resumed point. */ public void resumeMIDlet() { // write pre-action user code here // write post-action user code here } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable "> /** * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable. * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately * @param nextDisplayable the Displayable to be set */ public void switchDisplayable(Alert alert, Displayable nextDisplayable) { // write pre-switch user code here Display display = getDisplay(); if (alert == null) { display.setCurrent(nextDisplayable); } else { display.setCurrent(alert, nextDisplayable); } // write post-switch user code here } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables "> /** * Called by a system to indicated that a command has been invoked on a particular displayable. * @param command the Command that was invoked * @param displayable the Displayable where the command was invoked */ public void commandAction(Command command, Displayable displayable) { // write pre-action user code here if (displayable == ByeByeSplashScreen) { if (command == SplashScreen.DISMISS_COMMAND) { // write pre-action user code here exitMIDlet(); // write post-action user code here } } else if (displayable == WelcomeSplashScreen) { if (command == SplashScreen.DISMISS_COMMAND) { // write pre-action user code here switchDisplayable(null, getMain()); // write post-action user code here } } else if (displayable == main) { if (command == exitCommand) { // write pre-action user code here switchDisplayable(null, getByeByeSplashScreen()); // write post-action user code here } else if (command == tydzienCommand) { // write pre-action user code here switchDisplayable(null, getTydzien()); // write post-action user code here } } else if (displayable == tydzien) { if (command == forwardCommand1) { // write pre-action user code here podlad_dzien_id++; if(podlad_dzien_id>6) podlad_dzien_id=0; switchDisplayable(null, getTydzien()); // write post-action user code here } else if (command == okCommand) { // write pre-action user code here switchDisplayable(null, getMain()); // write post-action user code here } } // write post-action user code here } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand "> /** * Returns an initiliazed instance of exitCommand component. * @return the initialized component instance */ public Command getExitCommand() { if (exitCommand == null) { // write pre-init user code here exitCommand = new Command("Exit", Command.OK, 0); // write post-init user code here } return exitCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" UpdateTime : funkcja odświeżająca zmienne czasu"> private void UpdateTime() { Calendar kalendarz = Calendar.getInstance(TimeZone.getTimeZone("GMT+02:00"));//Calendar.getInstance(); //pobranie aktualnej godziny, minuty i sekundy dzien = kalendarz.get(Calendar.DAY_OF_WEEK); h = kalendarz.get(Calendar.HOUR_OF_DAY);//HOUR(12h)//HOUR_OF_DAY(24h) min = kalendarz.get(Calendar.MINUTE); //własna strefa czasowa.. //bardzo niebezpieczne działa tylko na komach z ustawioną strefą czasową GTM+1h... //h += 1;// dzien -= 1; if(dzien<0) dzien=6; dzien -= 1; if(dzien<0) dzien=6; //blokada.. if(dzien>6) dzien=6; //zmiana dnia dla widoku tygodnia podlad_dzien_id = dzien; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" String GetDayString(int day_id,boolean long_name) : funkcja zwraca nazw dnia"> String GetDayString(int day_id,boolean long_name) { if(long_name==true) { switch(day_id) { case 0: return "Poniedziałek"; case 1: return "Wtorek"; case 2: return "Środa"; case 3: return "Czwartek"; case 4: return "Piątek"; case 5: return "Sobota"; case 6: return "Niedziela"; } } else { switch(day_id) { case 0: return "Pon"; case 1: return "Wt"; case 2: return "Śr"; case 3: return "Czw"; case 4: return "Pt"; case 5: return "So"; case 6: return "Nd"; } } //jeśli dzień nie pasuje do listy zwracamy błąd return "error"; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" GetLekcjaStart(int LekcjaID) : funkcja zwraca tekstowo godzienę rozpoczęcia lekcji"> String GetLekcjaStart(int LekcjaID) { switch(LekcjaID) { case 0: return " 7:10"; case 1: return " 8:00"; case 2: return " 8:55"; case 3: return " 9:50"; case 4: return "10:45"; case 5: return "11:45"; case 6: return "12:35"; case 7: return "13:30"; case 8: return "14:20"; case 9: return "15:10"; } return "error"; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" GetLekcjaEnd(int LekcjaID) : funkcja zwraca tekstowo godzienę zakończenia lekcji"> String GetLekcjaEnd(int LekcjaID) { switch(LekcjaID) { case 0: return " 7:55"; case 1: return " 8:45"; case 2: return " 9:40"; case 3: return "10:35"; case 4: return "11:30"; case 5: return "12:25"; case 6: return "13:25"; case 7: return "14:15"; case 8: return "15:05"; case 9: return "15:55"; } return "error"; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: main "> /** * Returns an initiliazed instance of main component. * @return the initialized component instance */ public Form getMain() { if (main == null) { // write pre-init user code here main = new Form("Welcome", new Item[] { getStringItem() }); main.addCommand(getExitCommand()); main.addCommand(getTydzienCommand()); main.setCommandListener(this); // write post-init user code here } { //odświerz czas String stime; { UpdateTime(); if(h<10) stime = "0" + h; else stime = "" + h; stime += ":"; if(min<10) stime += "0" + min; else stime += "" + min; } //jako akapit ustaw dzien i godzine { main.setTitle(GetDayString(dzien,false) + " " + stime); } //tresc { sBuffor = "";//zerowanie bufora(dla bezpieczenstwa) if(dzien>=0 && dzien<=6) { if(dzien==5 || //sobota dzien==6) //lub niedziela { sBuffor = "dzis masz wolne:D\n"; }else { for(int i=0;i<max_day_list;i++) sBuffor += sLekcje[podlad_dzien_id][i] + "\n";// test information: sBuffor += (dzien) + "-" + (i) +"\n"; } stringItem.setLabel(""); //bez naglowka stringItem.setText(sBuffor);//wstaw tekst sBuffor = "";//zerowanie bufora } } } return main; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem "> /** * Returns an initiliazed instance of stringItem component. * @return the initialized component instance */ public StringItem getStringItem() { if (stringItem == null) { // write pre-init user code here stringItem = new StringItem("dzis:", "Hello, World!"); // write post-init user code here //tu zaczynam prace // stringItem.setLabel("aaaa"); // stringItem.setText("bbbb"); } return stringItem; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: WelcomeSplashScreen "> /** * Returns an initiliazed instance of WelcomeSplashScreen component. * @return the initialized component instance */ public SplashScreen getWelcomeSplashScreen() { if (WelcomeSplashScreen == null) { // write pre-init user code here WelcomeSplashScreen = new SplashScreen(getDisplay()); WelcomeSplashScreen.setTitle("splashScreen"); WelcomeSplashScreen.setCommandListener(this); WelcomeSplashScreen.setFullScreenMode(true); WelcomeSplashScreen.setText(""); WelcomeSplashScreen.setTimeout(1500); // write post-init user code here WelcomeSplashScreen.setText("Plan Dnia\nStudia\n1rok 2sem"); } return WelcomeSplashScreen; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: dzisCommand "> /** * Returns an initiliazed instance of dzisCommand component. * @return the initialized component instance */ public Command getDzisCommand() { if (dzisCommand == null) { // write pre-init user code here dzisCommand = new Command("dzi\u015B", Command.STOP, 1); // write post-init user code here } return dzisCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: tydzienCommand "> /** * Returns an initiliazed instance of tydzienCommand component. * @return the initialized component instance */ public Command getTydzienCommand() { if (tydzienCommand == null) { // write pre-init user code here tydzienCommand = new Command("tydzie\u0144", Command.BACK, 2); // write post-init user code here } return tydzienCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 "> /** * Returns an initiliazed instance of okCommand1 component. * @return the initialized component instance */ public Command getOkCommand1() { if (okCommand1 == null) { // write pre-init user code here okCommand1 = new Command("Ok", Command.OK, 0); // write post-init user code here } return okCommand1; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand2 "> /** * Returns an initiliazed instance of okCommand2 component. * @return the initialized component instance */ public Command getOkCommand2() { if (okCommand2 == null) { // write pre-init user code here okCommand2 = new Command("Ok", Command.OK, 0); // write post-init user code here } return okCommand2; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand "> /** * Returns an initiliazed instance of backCommand component. * @return the initialized component instance */ public Command getBackCommand() { if (backCommand == null) { // write pre-init user code here backCommand = new Command("wczoraj", Command.BACK, 2); // write post-init user code here } return backCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: forwardCommand "> /** * Returns an initiliazed instance of forwardCommand component. * @return the initialized component instance */ public Command getForwardCommand() { if (forwardCommand == null) { // write pre-init user code here forwardCommand = new Command("jutro", Command.STOP, 1); // write post-init user code here } return forwardCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ByeByeSplashScreen "> /** * Returns an initiliazed instance of ByeByeSplashScreen component. * @return the initialized component instance */ public SplashScreen getByeByeSplashScreen() { if (ByeByeSplashScreen == null) { // write pre-init user code here ByeByeSplashScreen = new SplashScreen(getDisplay()); ByeByeSplashScreen.setTitle(" "); ByeByeSplashScreen.setCommandListener(this); ByeByeSplashScreen.setText("code: Dawid Urba\u0144ski"); ByeByeSplashScreen.setTimeout(1500); // write post-init user code here } return ByeByeSplashScreen; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task "> /** * Returns an initiliazed instance of task component. * @return the initialized component instance */ public SimpleCancellableTask getTask() { if (task == null) { // write pre-init user code here task = new SimpleCancellableTask(); task.setExecutable(new org.netbeans.microedition.util.Executable() { public void execute() throws Exception { // write task-execution user code here } }); // write post-init user code here } return task; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task1 "> /** * Returns an initiliazed instance of task1 component. * @return the initialized component instance */ public SimpleCancellableTask getTask1() { if (task1 == null) { // write pre-init user code here task1 = new SimpleCancellableTask(); task1.setExecutable(new org.netbeans.microedition.util.Executable() { public void execute() throws Exception { // write task-execution user code here } }); // write post-init user code here } return task1; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand "> /** * Returns an initiliazed instance of okCommand component. * @return the initialized component instance */ public Command getOkCommand() { if (okCommand == null) { // write pre-init user code here okCommand = new Command("Ok", Command.OK, 0); // write post-init user code here } return okCommand; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: tydzien "> /** * Returns an initiliazed instance of tydzien component. * @return the initialized component instance */ public Form getTydzien() { if (tydzien == null) { // write pre-init user code here tydzien = new Form("tydzien", new Item[] { getStringItem2() }); tydzien.addCommand(getOkCommand()); tydzien.addCommand(getForwardCommand1()); tydzien.setCommandListener(this); // write post-init user code here } { stringItem2.setLabel(""); tydzien.setTitle(GetDayString(podlad_dzien_id,true)+":\n"); if(podlad_dzien_id>=0 && podlad_dzien_id<=6) { if(podlad_dzien_id==5) stringItem2.setText("dziś jest sobota\nmasz wolne:)"); else if(podlad_dzien_id==6) stringItem2.setText("dziś jest niedziela\nmasz wolne:)"); else { for(int i=0;i<max_day_list;i++) { sBuffor += sLekcje[podlad_dzien_id][i] + "\n";// test information: sBuffor += (dzien) + "-" + (i) +"\n"; } stringItem2.setText(sBuffor); } sBuffor = ""; //zerowanie bufora } else { stringItem2.setText("ERROR\nprzepraszamy\n(błąd wczytania dnia tygodnia)"); } } return tydzien; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 "> /** * Returns an initiliazed instance of stringItem2 component. * @return the initialized component instance */ public StringItem getStringItem2() { if (stringItem2 == null) { // write pre-init user code here stringItem2 = new StringItem("stringItem2", null); // write post-init user code here } return stringItem2; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backwardCommand1 "> /** * Returns an initiliazed instance of backwardCommand1 component. * @return the initialized component instance */ public Command getBackwardCommand1() { if (backwardCommand1 == null) { // write pre-init user code here backwardCommand1 = new Command("wczoraj", Command.BACK, 2); // write post-init user code here } return backwardCommand1; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: forwardCommand1 "> /** * Returns an initiliazed instance of forwardCommand1 component. * @return the initialized component instance */ public Command getForwardCommand1() { if (forwardCommand1 == null) { // write pre-init user code here forwardCommand1 = new Command(">>", Command.BACK, 1); // write post-init user code here } return forwardCommand1; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task2 "> /** * Returns an initiliazed instance of task2 component. * @return the initialized component instance */ public SimpleCancellableTask getTask2() { if (task2 == null) { // write pre-init user code here task2 = new SimpleCancellableTask(); task2.setExecutable(new org.netbeans.microedition.util.Executable() { public void execute() throws Exception { // write task-execution user code here } }); // write post-init user code here } return task2; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task3 "> /** * Returns an initiliazed instance of task3 component. * @return the initialized component instance */ public SimpleCancellableTask getTask3() { if (task3 == null) { // write pre-init user code here task3 = new SimpleCancellableTask(); task3.setExecutable(new org.netbeans.microedition.util.Executable() { public void execute() throws Exception { // write task-execution user code here } }); // write post-init user code here } return task3; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ticker "> /** * Returns an initiliazed instance of ticker component. * @return the initialized component instance */ public Ticker getTicker() { if (ticker == null) { // write pre-init user code here ticker = new Ticker(""); // write post-init user code here } return ticker; } //</editor-fold> /** * Returns a display instance. * @return the display instance. */ public Display getDisplay () { return Display.getDisplay(this); } /** * Exits MIDlet. */ public void exitMIDlet() { switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } /** * Called when MIDlet is started. * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet. */ public void startApp() { if (midletPaused) { resumeMIDlet (); } else { initialize (); startMIDlet (); } midletPaused = false; } /** * Called when MIDlet is paused. */ public void pauseApp() { midletPaused = true; } /** * Called to signal the MIDlet to terminate. * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released. */ public void destroyApp(boolean unconditional) { } }