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.
Asked
Active
Viewed 602 times
3

gnat
- 6,213
- 108
- 53
- 73

Sabin Jose
- 658
- 9
- 19
2 Answers
4
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);

Lucifer
- 29,392
- 25
- 90
- 143
-
I am getting a nullopinter exception. Can you please elaborate the getDisplay() method. – Sabin Jose Jul 19 '12 at 04:52
-
@SabinJose, sorry, it was mistake from my side, please check the updated answer. – Lucifer Jul 19 '12 at 04:55
3
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

Douglas Frari
- 4,167
- 2
- 22
- 23