Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch Display between different classes in Java ME

I am developing a Java ME program. The different forms are located in separate classes. I tried to switch display between main MIDlet and a class and succeeded. How to do the same between two classes? I am just a beginner in Java ME.

like image 338
Sabin Jose Avatar asked Dec 31 '25 01:12

Sabin Jose


2 Answers

I use following code for the same,

  • First display a static Display variable in Midlet

    private static Display display;
    
  • Now initialize the dislplay variable in class Constructor

    public MyMidlet() {
         display = Display.getDisplay(this);
    }
    
  • Now declare a getDisplay() method in Midlet class

    public static Display getDisplay () {
         return display;
    }
    

Now you can use this getDisplay() method to get the current Display's object and then set any class's form

MyMidlet.getDisplay().setCurrent(form);
like image 166
Lucifer Avatar answered Jan 02 '26 15:01

Lucifer


Simplification is:

  Display.getDisplay(this).setCurrent(screen);

Where screen is an instance of LCDUI (Form, Alert...) or intance of Canvas object. The this is an instance of the MIDlet

like image 38
Douglas Frari Avatar answered Jan 02 '26 13:01

Douglas Frari