By: Fazal in J2ME Tutorials on 2022年09月16日 [フレーム]
J2ME is a Java platform for developing mobile applications. It includes various libraries and APIs for creating mobile applications. In J2ME, we can create GUI components and menu-based applications by using the javax.microedition.lcdui package.
Here is an example of a J2ME application that includes GUI components and menus:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class J2meApp extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command exitCommand;
private Command menuCommand;
private Command backCommand;
private List menuList;
public J2meApp() {
display = Display.getDisplay(this);
form = new Form("J2ME Application");
exitCommand = new Command("Exit", Command.EXIT, 0);
menuCommand = new Command("Menu", Command.SCREEN, 1);
backCommand = new Command("Back", Command.BACK, 0);
form.addCommand(exitCommand);
form.addCommand(menuCommand);
form.setCommandListener(this);
menuList = new List("Menu", List.IMPLICIT);
menuList.append("Option 1", null);
menuList.append("Option 2", null);
menuList.addCommand(backCommand);
menuList.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
notifyDestroyed();
} else if (c == menuCommand) {
display.setCurrent(menuList);
} else if (c == backCommand) {
display.setCurrent(form);
} else if (c == List.SELECT_COMMAND) {
int index = menuList.getSelectedIndex();
Alert alert = new Alert("Selected Option", "You selected option " + (index + 1), null, AlertType.INFO);
alert.setTimeout(2000);
display.setCurrent(alert, menuList);
}
}
}
In this example, we create a J2ME application that contains a form with two commands: "Exit" and "Menu". When the user clicks on the "Menu" command, a list of options is displayed. The user can select an option, and an alert message is displayed with the selected option.
The J2ME application is built using the MIDlet class, which provides the basic framework for creating mobile applications. We create the GUI components using the javax.microedition.lcdui package, which provides the necessary classes for building mobile user interfaces.
We also implement the CommandListener interface, which provides the necessary methods for handling user actions, such as button clicks and menu selections.
Overall, this J2ME application demonstrates how to create GUI components and menu-based applications using Java.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in J2ME )
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Client Server in J2ME (Socket Programming sample)
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Datagrams in J2ME (UDP Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
RMSCookieConnector - Using Cookies in J2ME
Using HTTP vs UDP vs Socket in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Latest Articles (in J2ME)
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
Using alerts and tickers in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
GUI components and menu based J2ME Applications.
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
Using alerts and tickers in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate