Hello, my name is Keenan, and i want to learn how to make mobile application. In internet, i always find a great tutorials, great resource, and many more. I do love free, my teacher is internet. For now, I cant making any good mobile application using Java with BlueJ. I want too learn how to make good mobile applications ! I made this blog for posting my progress/improvement of making good mobile application !
So lets get started. You need JRE, download
here.
I'm using BlueJ for this. You can download BlueJ
here.
You need Wireless Toolkit 2.5.2 too ! download
here.
That's it, i think that's is what i need.
I'm ready! did you ?
Okay, my first step, is searching in the bluej website for j2me. I got it
here. After done reading that page and try they "command". I now can make simple application.
Now, time to edit the source code, of the Hello MIDlet that I downloaded. After seeking from the javax.microedition.lcdui API (you can see it at WTK 2.5.2 folder(C:\WTK2.5.2_01\docs\api\midp\index.html)). I found an Alert class, maybe i can use it. So, I edited the source code so like this !
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* Class Hello - A simple Hello World MIDlet
*
* @author Ian Utting
* @version 1.0
*/
public class Hello extends MIDlet implements CommandListener
{
private Form screen;
private Alert dor = new Alert("DOR !");/***/
private int a; /***/
public Hello()
{
screen = new Form("Hello Midlet");
dor.setTimeout(1500); /***/
dor.setString(a + " Times.."); /***/
screen.append("Hello small world!");
screen.addCommand(new Command("Exit", Command.EXIT, 0));
screen.setCommandListener(this);
}
..............
.......
Hmm, I think to make application, that every time we click button, the alert will show, and print out many times we click that button ! for that, i make a variable called 'a'. And after that...
...
....
public void commandAction(Command c, Displayable d) {
// If it's our exitCommand, destroy ourselves
if(c.getLabel().equals("Exit")) {
notifyDestroyed();
}
if(c.getLabel().equals("Dor")) { /***/
Display.getDisplay(this).setCurrent(dor);
a += 1;
dor.setString( a + " Times..");
}
}
I compile that, and then deploy. It's Work.
Now, i want display the clicked times in the form. I think, I will use text field.
I add this to the code
...
.....
public class Hello extends MIDlet implements CommandListener
{
private Form screen;
private TextField tf; /***/
private int a = 0;
...
...
and then, in the Hello constructor
...
.....
public Hello()
{
screen = new Form("Hello Midlet");
tf = new TextField("hehe..","Hello small world!",255,TextField.ANY);
screen.append(tf);
screen.addCommand(new Command("Exit", Command.EXIT, 0));
screen.addCommand(new Command("Dor", Command.ITEM, 0));
screen.setCommandListener(this);
}
...
..
After that, in the command listener.
public void commandAction(Command c, Displayable d) {
// If it's our exitCommand, destroy ourselves
if(c.getLabel().equals("Exit")) {
notifyDestroyed();
}
if(c.getLabel().equals("Dor")) {
a += 1;
tf.setString("Hello small world!"+" \n "+ a +" Times :)");
}
}
Compile, Deploy, It's Work ! :D