Facebook
From Violet Tamarin, 5 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 218
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package mobileapplication7;
  7.  
  8. import javax.microedition.lcdui.*;
  9. import javax.microedition.midlet.*;
  10.  
  11. /**
  12.  * @author Bartosz
  13.  */
  14. public class Midlet extends MIDlet implements CommandListener {
  15.  
  16.     private boolean midletPaused = false;
  17.     private Plotno plotno;
  18.     private Command cmd;
  19.     private Command cmdCheck;
  20.     private Display ekran;
  21.  
  22. //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
  23.     private Command exitCommand;
  24.     private Form form;
  25.     private StringItem stringItem;
  26. //</editor-fold>//GEN-END:|fields|0|
  27.  
  28.     /**
  29.      * The HelloMIDlet constructor.
  30.      */
  31.     public Midlet() {
  32.         plotno = new Plotno();
  33.  
  34.         cmdCheck = new Command("Sprawdź", Command.ITEM, 0);
  35.         cmd = new Command("Koniec", Command.EXIT, 0);
  36.         plotno.addCommand(cmdCheck);
  37.         plotno.addCommand(cmd);
  38.  
  39.         plotno.setCommandListener(this);
  40.     }
  41.  
  42. //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
  43. //</editor-fold>//GEN-END:|methods|0|
  44. //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
  45.     /**
  46.      * Initializes the application. It is called only once when the MIDlet is
  47.      * started. The method is called before the <code>startMIDlet</code> method.
  48.      */
  49.     private void initialize() {
  50. //GEN-END:|0-initialize|0|0-preInitialize
  51.         // write pre-initialize user code here
  52. //GEN-LINE:|0-initialize|1|0-postInitialize
  53.         // write post-initialize user code here
  54. }//GEN-BEGIN:|0-initialize|2|
  55. //</editor-fold>//GEN-END:|0-initialize|2|
  56.  
  57. //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
  58.     /**
  59.      * Performs an action assigned to the Mobile Device - MIDlet Started point.
  60.      */
  61.     public void startMIDlet() {
  62. //GEN-END:|3-startMIDlet|0|3-preAction
  63.         // write pre-action user code here
  64. switchDisplayable(null, getForm());//GEN-LINE:|3-startMIDlet|1|3-postAction
  65.         // write post-action user code here
  66. }//GEN-BEGIN:|3-startMIDlet|2|
  67. //</editor-fold>//GEN-END:|3-startMIDlet|2|
  68.  
  69. //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
  70.     /**
  71.      * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
  72.      */
  73.     public void resumeMIDlet() {
  74. //GEN-END:|4-resumeMIDlet|0|4-preAction
  75.         // write pre-action user code here
  76. //GEN-LINE:|4-resumeMIDlet|1|4-postAction
  77.         // write post-action user code here
  78. }//GEN-BEGIN:|4-resumeMIDlet|2|
  79. //</editor-fold>//GEN-END:|4-resumeMIDlet|2|
  80.  
  81. //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
  82.     /**
  83.      * Switches a current displayable in a display. The <code>display</code>
  84.      * instance is taken from <code>getDisplay</code> method. This method is
  85.      * used by all actions in the design for switching displayable.
  86.      *
  87.      * @param alert the Alert which is temporarily set to the display; if
  88.      * <code>null</code>, then <code>nextDisplayable</code> is set immediately
  89.      * @param nextDisplayable the Displayable to be set
  90.      */
  91.     public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
  92. //GEN-END:|5-switchDisplayable|0|5-preSwitch
  93.         // write pre-switch user code here
  94. Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
  95.         if (alert == null) {
  96.             display.setCurrent(nextDisplayable);
  97.         } else {
  98.             display.setCurrent(alert, nextDisplayable);
  99.         }//GEN-END:|5-switchDisplayable|1|5-postSwitch
  100.         // write post-switch user code here
  101. }//GEN-BEGIN:|5-switchDisplayable|2|
  102. //</editor-fold>//GEN-END:|5-switchDisplayable|2|
  103.  
  104. //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
  105.     /**
  106.      * Called by a system to indicated that a command has been invoked on a
  107.      * particular displayable.
  108.      *
  109.      * @param command the Command that was invoked
  110.      * @param displayable the Displayable where the command was invoked
  111.      */
  112.     public void commandAction(Command command, Displayable displayable) {
  113. //GEN-END:|7-commandAction|0|7-preCommandAction
  114.         if (command == cmd) {
  115.             notifyDestroyed();
  116.         }
  117.         if (command == this.cmdCheck) {
  118.             //System.out.println("cos");
  119.             //startMIDlet();
  120.             //startApp();
  121.             getDisplay();
  122.         }
  123.  
  124.         if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|19-preAction
  125.             if (command == exitCommand) {//GEN-END:|7-commandAction|1|19-preAction
  126.                 // write pre-action user code here
  127. exitMIDlet();//GEN-LINE:|7-commandAction|2|19-postAction
  128.                 // write post-action user code here
  129. }//GEN-BEGIN:|7-commandAction|3|7-postCommandAction
  130.         }//GEN-END:|7-commandAction|3|7-postCommandAction
  131.         // write post-action user code here
  132. }//GEN-BEGIN:|7-commandAction|4|
  133. //</editor-fold>//GEN-END:|7-commandAction|4|
  134.  
  135. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
  136.     /**
  137.      * Returns an initialized instance of exitCommand component.
  138.      *
  139.      * @return the initialized component instance
  140.      */
  141.     public Command getExitCommand() {
  142.         if (exitCommand == null) {
  143. //GEN-END:|18-getter|0|18-preInit
  144.             // write pre-init user code here
  145. exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
  146.             // write post-init user code here
  147. }//GEN-BEGIN:|18-getter|2|
  148.         return exitCommand;
  149.     }
  150. //</editor-fold>//GEN-END:|18-getter|2|
  151.  
  152. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|14-getter|0|14-preInit
  153.     /**
  154.      * Returns an initialized instance of form component.
  155.      *
  156.      * @return the initialized component instance
  157.      */
  158.     public Form getForm() {
  159.         if (form == null) {
  160. //GEN-END:|14-getter|0|14-preInit
  161.             // write pre-init user code here
  162. form = new Form("Welcome", new Item[]{getStringItem()});//GEN-BEGIN:|14-getter|1|14-postInit
  163.             form.addCommand(getExitCommand());
  164.             form.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
  165.             // write post-init user code here
  166. }//GEN-BEGIN:|14-getter|2|
  167.         return form;
  168.     }
  169. //</editor-fold>//GEN-END:|14-getter|2|
  170.  
  171. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|16-getter|0|16-preInit
  172.     /**
  173.      * Returns an initialized instance of stringItem component.
  174.      *
  175.      * @return the initialized component instance
  176.      */
  177.     public StringItem getStringItem() {
  178.         if (stringItem == null) {
  179. //GEN-END:|16-getter|0|16-preInit
  180.             // write pre-init user code here
  181. stringItem = new StringItem("Hello", "Hello, World!");//GEN-LINE:|16-getter|1|16-postInit
  182.             // write post-init user code here
  183. }//GEN-BEGIN:|16-getter|2|
  184.         return stringItem;
  185.     }
  186. //</editor-fold>//GEN-END:|16-getter|2|
  187.  
  188.     /**
  189.      * Returns a display instance.
  190.      *
  191.      * @return the display instance.
  192.      */
  193.     public Display getDisplay() {
  194.         return Display.getDisplay(this);
  195.     }
  196.  
  197.     /**
  198.      * Exits MIDlet.
  199.      */
  200.     public void exitMIDlet() {
  201.         switchDisplayable(null, null);
  202.         destroyApp(true);
  203.         notifyDestroyed();
  204.     }
  205.  
  206.     /**
  207.      * Called when MIDlet is started. Checks whether the MIDlet have been
  208.      * already started and initialize/starts or resumes the MIDlet.
  209.      */
  210.     public void startApp() {
  211.  
  212.         ekran = Display.getDisplay(this);
  213.         ekran.setCurrent(plotno);
  214.  
  215.     }
  216.  
  217.     /**
  218.      * Called when MIDlet is paused.
  219.      */
  220.     public void pauseApp() {
  221.         midletPaused = true;
  222.     }
  223.  
  224.     /**
  225.      * Called to signal the MIDlet to terminate.
  226.      *
  227.      * @param unconditional if true, then the MIDlet has to be unconditionally
  228.      * terminated and all resources has to be released.
  229.      */
  230.     public void destroyApp(boolean unconditional) {
  231.     }
  232.  
  233. }
  234.