📄 mainclass.java
字号:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
/* This class is the first class to be invoked.This class internally calls three different MIDlets
depending on the item selected
*/
public class MainClass extends MIDlet implements CommandListener
{
/* This list object will contains the Services */
private List menu = null;
/* Display object declared */
private Display displaymenu = null;
/* MovieList object declared. The movielist class is a MIDlet which will make the user book movie
tickets */
MoviesList bookmovie = null;
/* News object declared. The News class is a MIDlet which will make the user read news */
News readnews = null;
/* Weather object declared. This class is also a MIDlet which will give the user weather
details based on the city selected */
Weather seeweather = null;
/* Command object declared */
Command exit;
/* MainClass constructor declared */
public MainClass()
{
/* This will get the display object */
displaymenu = Display.getDisplay(this);
/* Exit command initialized */
exit = new Command("EXIT",Command.EXIT,1);
}
/* The startApp method declared */
public void startApp()
{
/* Initializing List */
menu = new List("Menu",List.IMPLICIT);
/* This will add three items in the list which are the services provided */
menu.append("Weather",null);
menu.append("Movies",null);
menu.append("News",null);
/* This will register the list for events handling */
menu.setCommandListener(this);
/* The list will be displayed to the user */
displaymenu.setCurrent(menu);
/* Exit command added to the list */
menu.addCommand(exit);
}
/* The pauseApp() method declared */
public void pauseApp()
{
System.out.println("pause app called");
}
/* The destroyApp() method declared */
public void destroyApp(boolean b)
{
menu = null;
displaymenu = null;
bookmovie = null;
readnews = null;
seeweather = null;
}
/* This method handles user events */
public void commandAction(Command c, Displayable d)
{
/* This if condition is true if any item in the list is selected */
if(c == List.SELECT_COMMAND)
{
/* This String will contain the string representation of the item selected */
String menuselect = menu.getString(menu.getSelectedIndex());
/* The if condition is executed if the user selects "Weather". The weather MIDlet is
initialized and its startApp() method is called
*/
if(menuselect.equals("Weather"))
{
/* Weather MIDlet initialized two arguments passed to the constructor Display object
and the object of MainClass */
seeweather = new Weather(displaymenu,this);
/* startApp() method called */
seeweather.startApp();
}
/* This if condition is executed if the user selects "Movies". The MovieList MIDlet is
initialized and its startApp() method is called
*/
if(menuselect.equals("Movies"))
{
/* MovieList MIDlet initialized two arguments passed to the constructor Display object
and the object of MainClass */
bookmovie = new MoviesList(displaymenu,this);
/* startApp() method called */
bookmovie.startApp();
}
/* This if condition is executed if the user selects "News". The MovieList MIDlet is
initialized and its startApp() method is called
*/
if(menuselect.equals("News"))
{
/* News MIDlet initialized two arguments passed to the constructor Display object
and the object of MainClass */
readnews = new News(displaymenu,this);
/* startApp() method called */
readnews.startApp();
}
}
/* This if condition is true if the user press the button indicating "EXIT" */
if(c == exit)
{
/* destroyApp() method called */
destroyApp(true);
notifyDestroyed();
}
}
/* This method is to get the Display object back */
public void getDisplayObject(Display dis)
{
displaymenu = dis;
displaymenu.setCurrent(menu);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -