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