Reputation: 263723
I am a .Net Developer and currently migrating to java. What am I missing here? There is no display when I run the program?
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Date;
import java.util.TimeZone;
public class CalenderMIDlet extends MIDlet{
private Form form = null;
private DateField calender = null;
private static final int DATE = 0;
public CalenderMIDlet(){
calender = new DateField("Date In:", DateField.DATE, TimeZone.getTimeZone("GMT"));
}
public void startApp(){
display = Display.getDisplay(this);
Form form = new Form("Calender");
form.append(calender);
}
public void pauseApp(){}
public void destroyApp(boolean destroy){
notifyDestroyed();
}
}
Upvotes: 1
Views: 381
Reputation: 5680
Don't set the private Form form = null;
Try this code
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Date;
import java.util.TimeZone;
public class CalenderMIDlet extends MIDlet{
private Form form;
private Display display;
private DateField calender;
private static final int DATE = 0;
public CalenderMIDlet(){
calender = new DateField("Date In:", DateField.DATE, TimeZone.getTimeZone("GMT"));
}
public void startApp(){
display = Display.getDisplay(this);
Form form = new Form("Calender");
form.append(calender);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean destroy){
notifyDestroyed();
}
}
Upvotes: 3
Reputation: 7251
Just use one following line of code in startApp() method
public void startApp(){
display = Display.getDisplay(this);
Form form = new Form("Calender");
form.append(calender);
display.setCurrent(form);
}
Upvotes: 2
Reputation: 6225
What am I missing here?
Well as far as I can tell your code misses to invoke Display.setCurrent(Displayable), that would request "...that a different Displayable object be made visible on the display..." (quoting API documentation).
There is no display when I run the program?
This is expected behavior, taking into account above. Most likely if you invoke display.setCurrent(form)
in startApp method, you'll see the form.
side note. I would also consider moving initialization of calender DateField from constructor into startApp. Per my recollection this way would be more reliable.
Form form = new Form("Calender"); /* why is 'Form' here? */
Form
would make much more senseUpvotes: 2