GUI components and menu based J2ME Applications.
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.
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
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:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
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.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
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
Comments