TvQuran
Showing posts with label J2ME. Show all posts
Showing posts with label J2ME. Show all posts

Thursday, December 17, 2009

J2ME By Example, How to make simple GUI

In this lesson we will talk about

1. Form
2. Command – like button in j2se
3. Radiobutton
4. Checkbox
5. Combobox
6. TextField
7. passwordField
8. commandAction Function


now we will discuss each one in detail :-

1. Form

The form is the container that hold our component .

To create the form
  • Form frmMain = new Form("Title of the form ");
to display it
  • Display display = Display.getDisplay(this);
  • display.setCurrent(frmMain);
2. Command

The command is the button that hold the action we will do it
To create button
  • Command ok = new Command("ok", Command.OK, 1);
  1. First attribute : is the command label
  2. Seconed attribute : command type (ok – cancel – exit …..etc)
  3. Third attribute : is the priority of the button
To add the command to the form
  • frmMain.addCommand(ok);
to assign action to the button
  • we refer it to the form but first we must implements the class from CommandListener then override commandAction function to do the action inside it .
we implements the class like this
  • public class Welcome extends MIDlet implements CommandListener {
the header of the function
  • public void commandAction(Command c, Displayable d) {}

3. Radiobutton

Allow us to choose one and only one item from two or more items

To create it
  • Create array hold the items
  • String[] radio = {"Rock", "paper"};
Declare it
  • ChoiceGroup radiobutton = new ChoiceGroup("Your choice1:", ChoiceGroup.EXCLUSIVE, radio, null);
  1. Attribute 1 :- radio label
  2. Attribute 2 :- tell the radio to choose only on item .
  3. Attribute 3 :- assign the items using the array
  4. value instead of imageElements.
Add to form
  • frmMain.append(radiobutton);

4. CheckBox

Allow us to choose multiple items

To create it
  • Create array hold the items
  • String[] check = {"Python", "Symbian", "J2ME"};
Declare it
  • ChoiceGroup checkbox = new ChoiceGroup("Your choice2:", ChoiceGroup.MULTIPLE, check, null);
  1. Attribute 1 :- checkbox label
  2. Attribute 2 :- tell the checkbox to choose multiple item .
  3. Attribute 3 :- assign the items using the array
  4. Null value instead of imageElements.
Add to form
  • frmMain.append(checkbox);

5. ComboBox

Allow us to choose one item from compact lits

To create it
  • Create array hold the itemsString[] combo = {"Red", "Green", "blue"};
Declare it
  • ChoiceGroup combobox = new ChoiceGroup("choose color:", ChoiceGroup.POPUP, combo, null);
  1. Attribute 1 :- combox label
  2. Attribute 2 :- tell the combo to choose one item from compact list .
  3. Attribute 3 :- assign the items using the array
  4. Null value instead of imageElements.
Add to form
  • frmMain.append(combobox);

6. TextField

An area in which the user input data from the keyboard.the are can also display information

To Declare it
  • TextField txt = new TextField("Name", "", 15, TextField.ANY);
Add To The Form
  • • frmMain.append(txt);

7.PasswordField

like TextField put display information in encrypted form

To Declare it
  • password = new TextField("Pasword", "", 15, TextField.PASSWORD);
Add To The Form
  • frmMain.append(password);

8. CommandAction Function

the function that hold our action .
after declare it .

  • public void commandAction(Command c, Displayable d) {}
we check which command make this action like

if(c==ok)
{
//now we wil remove all form item
frmMain.deleteAll();
//now will remove ok command
frmMain.removeCommand(ok);

// now will set title to the form
frmMain.setTitle("your output");

//will display our name and password
frmMain.append("your ouput here \n");
frmMain.append(txt.getString() + "\n");
frmMain.append(password.getString() + "\n");
//then go to the source code to show more and more
}

The run of the code





Conclusion

We have learned how to make gui example in to Java 2 Micro Edition.
This example is very simple example. It can be executed using editors like NetBeans IDE or J2ME Wireless Toolkit(KToolBar). Using API's like JSR 135 etc.. try to create more programs and try them in these tools. I will get back to you with more articles on J2ME.

Project Source Code : Click Here
read more...

Sunday, December 13, 2009

J2ME By Example, How to enter Mobile World

We will start in this series simple easy tutorials to start from zero in J2ME track, so stay with us.


1)J2ME Architecture
There are 5 layers in J2ME Architecture.Those are:
  • MIDP (TopMost Layer): Which contains Java APIs for user network connections, persistence storage, and the user interface. It also has access to CLDC libraries and MIDP libraries.
  • J2ME API’s(Profiles): Which consists of the minimum set of application programming interfaces for the small computing device
  • Configurations: Which handles interactions between the profile and the JVM.
  • JVM
  • Operating System(Bottom Layer).

2)Simple Example Program
This section shows a simple application. The MIDlet will display the message “ Hi This is My First Program” on the screen. The application consists of the MIDlet subclass called welcome.





To create midlet .
Right-click on project name --> new --> MIDlet

The code .

The run of the project


3) Limitations with J2ME
Some of the limitations of J2ME compared with Core JAVA
  • Some J2SE applications require classes that are not available in J2ME.
  • Java applications won’t run in the J2ME environment without requiring modification to the code.
  • Devices that use the CDC configuration use the full Java Virtual Machine implementation, while devices that use the CLDC configuration use the Kjava Virtual Machine implementation.
  • MIDlets are controlled by application management software (AMS). So we cant invoke a MIDLET like a J2SE Application.

4)Conclusion
Here with we have an introduction to Java 2 Micro Edition. This example is very simple example. It can be executed using editors like NetBeans IDE or J2ME Wireless Toolkit(KToolBar). Using API's like JSR 135 etc.. try to create more programs and try them in these tools. I will get back to you with more articles on J2ME.

Project Source Code : Click Here
read more...

Saturday, December 12, 2009

Java Editing in NetBeans IDE 6.8, Video Tutorial

One of the most powerful feature in NetBeans IDE is it's Editor. The language-aware NetBeans editor detects errors while you type and assists you with documentation pop-ups and smart code completion-all with the speed and simplicity of your favorite text editor.








read more...

Saturday, December 5, 2009

Why Java From Egypt in 2.5 minutes

For most of us, the term tutorial is nothing but boring long files that contain lots of information, we often not need to meet our need,We just need a small hack of how it work. We thought to introduce the boring long tutorials in a simple form for most of us.

Here, from Egypt where one of the oldest civilizations, We provide Mini-Tutorials in one of the newest technologies.

We hope to enjoy your journey with our Mini-Tutorials. If you have an interesting tutorial want to share, please feel free to contact us at : javafromegyptblog[AT]gmail[DOT]com
read more...