MAKING CLASS FORM AND CLASS TEXTFIELD ON MIDLETS IN JAVA ME

in #utopian-io9 years ago (edited)

Understanding MIDlet
Applications that are created using J2ME with the MIDP standard are called MIDlet.To create a MIDlet it takes one class that becomes a derivative of the java.microedition.midlet.MIDlet class.
MIDlet has life cycle. A MIDlet once created will be in one of the states (active, paused, destroyed). As soon as the object of a MIDlet is created it will enter the paused state waiting for the next command. MIDlet enters active status when after method startApp () is called. The MIDlet will return to the pause state if the pauseApp () method is invoked. After all the processes in the MIDlet are done and the MIDlet is turned off then the MIDlet is in the destroyed state. This destroyed status is entered by the MIDlet on the method call destroyApp (boolean).
Interface in J2ME
J2ME, in MIDP, like any other java category (J2SE) defines a series of libraries to create user interface interface. In MIDP there are two types of user interface libraries:
a. High-level User Interface interface
b. Interface level / Low-level interface
The display is a representation of the mobile device display screen. This display can not be created and there is only one (singleton). To get this object can be used static method from Display that is as follows.
static Display getDisplay (Midlet m)
Objects that can be displayed through this Display object are Displayable objects and their derivatives and Alert objects. If you want to display Alert then Displayable object that will be displayed next must also be defined.
Form is a Screen derived component that serves as a place to hold (container) for other components.
TextField is a derivative component of Item that holds text and edits the text.
Command is an object that is used as user response interface of mobile device.
steps to create project
create a new project on netbeans Click File - New Project.
1.png
Then select Java Me - Select Mobile Application - and Click Next
2.png
After that will appear Name and Location, then fill in Project Name with "Prak21" or in accordance with the desired and select Project Location to select where the project will be created in save (Uncheck the "Create Hello MIDlet", we will make our MIDlet itself later). Next Click Next.
3.png
And then it will also appear Form Default Platfrom Selection on Divice select one of the existing objects on ComboBox, Divice Configuration select CLDC - 1.1 and on Divice Profile select MIDP - 2.0 then Click - Finish.
4.png
Then the main screen will appear on netbeans in Source Packages in "Prak21" or on the object that was created earlier Right Click - Select New - and Select MIDlet and fill MIDlet Name with name "Demoform" or as desired then Click Finish
5.png
And then the Form appears from the MIDlet then input the program listing as follows
Listing program using Form Object

import javax.microedition.midlet.;
import javax.microedition.lcdui.
;
public class DemoForm extends MIDlet implements CommandListener{
private Display display;
private Form form;
private TextField tf;

 private Command cmdKeluar;
 private Command cmdOk;
 public DemoForm (){
     display = Display.getDisplay(this);
     cmdKeluar = new Command("Keluar", Command.EXIT, 1);
    cmdOk = new Command ("OK", Command.OK,1);
      }
public void startApp() {
    form = new Form("Demo Form");
    tf = new TextField ("Masukan Nomor Telepon ","", 15 ,TextField.PHONENUMBER);
    form.append((Item) tf);
    form.addCommand(cmdKeluar);
    form.addCommand(cmdOk);
    form.setCommandListener(this);
    display.setCurrent(form);}
    public void pauseApp() {

}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == cmdKeluar){
destroyApp(true);
notifyDestroyed();
}
else if (c == cmdOk){
Alert info = new Alert ("Informasi");
info.setType(AlertType.INFO);
String text = tf.getString();
info.setString("Nomor Telepon: ""+
text + """);
info.setTimeout(Alert.FOREVER);
display.setCurrent(info,form);
}
}
}

Listing Program uses a textfield object

import javax.microedition.midlet.;
import javax.microedition.lcdui.
;
public class DemoTextField extends MIDlet implements CommandListener{
private Display display;
private Form form;
private TextField nama, password, telp, email, URL;
private final Command cmdKeluar = new Command ("Keluar", Command.EXIT,1);
public DemoTextField(){
display = Display.getDisplay(this);

}
public void startApp() {
    form = new Form("Demo TextField");
    nama = new TextField("Nama :",null,25,TextField.ANY);
    password = new TextField("Password :",null,50,TextField.PASSWORD);
    email = new TextField("Email :",null,50,TextField.EMAILADDR);
    URL = new TextField("URL :",null,50,TextField.URL);
    form.append(nama);
    form.append(password);
    form.append(email);
    form.append(URL);
    form.addCommand(cmdKeluar);
    form.setCommandListener(this);
    display.setCurrent(form);
    
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable d) {
  if (c == cmdKeluar){
        destroyApp(true);
        notifyDestroyed();
        
    }
}

}

results of the project
11.jpg
12.jpg
13.jpg



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules the wrong GitHub repository .

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

done editing

Your contribution cannot be approved because it does not follow the Utopian Rules the wrong GitHub repository .
If you are working on your own project, then you could have created a repository for it. but random selecting is nonsense and should not be accepted.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.05
TRX 0.33
JST 0.080
BTC 63782.23
ETH 1706.19
USDT 1.00
SBD 0.41