Wednesday, June 30, 2010

Hello LWUIT 1.3 on Java ME SDK 3.0

Before start coding, we have to download and install LWUIT.
-Download LWUIT and unzip in any folder you want.
http://java.sun.com/javame/technology/lwuit/

- Start Java ME SDK 3.0

- Create a new MIDP Application project in Java ME SDK Category


-
Enter the name and location of your project.
Click to select Set as Main Project/
NOT SELECT create Hello MIDlet.
Click Next


- Accept the default setting; CLDC-1.1 and MIDP-2.0, Click Finish.


- Right Click on the project to create a new MIDlet


- Enter the name of the MIDlet, then click Finish.


- Type in the code, you will see many error, because we haven't include LWUIT into our project.

import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;

public class Hello_LWUIT extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, MIDlet in LWUIT!");
f.show();
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}


- Right CLick on Resources, Add Jar/Zip.


- Browse to select the downloaded LWUIT.jar


After a moment, the errors will be disappear, now you can run the MIDlet by clicking on the Green Arrow.

Thursday, June 24, 2010

About Java ME SDK 3.0



About Java ME SDK 3.0 is a state-of-the-art toolbox for developing mobile applications. It provides device emulation, a standalone development environment, and a set of utilities for rapid development of Java ME applications.

On Windows, Java ME SDK 3.0 is the successor to the popular Java Wireless Toolkit 2.5.2 and Java Toolkit 1.0 for CDC. It integrates CLDC, CDC and Blu-ray Disc Java (BD-J) technology into one SDK.

The Java ME SDK 3.0 is now available for Windows XP and Vista 32-bit, and for the Mac OS. The Mac OS release brings support for CLDC mobile development to Mac users for the first time.


next: Hello LWUIT 1.3 on Java ME SDK 3.0

Sunday, June 20, 2010

LWUIT: Button

Example of using Button of LWUIT.

In order to handle the action trigged by a button, a class(it is "this" in this case) implements actionPerformed() have to be set as listener by the method addActionListener().

LWUIT: Button

import java.io.IOException;
import javax.microedition.midlet.*;

import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.plaf.Border;

public class HelloMIDlet extends MIDlet implements ActionListener {

Form f;
Command exitCommand;
Button buttonTextOnly, buttonImage, buttonTextAndImage;

public void startApp() {
Display.init(this);

f = new Form("Hello, MIDlet in LWUIT!");



buttonTextOnly = new Button("I'm Button");
buttonTextOnly.getStyle().setBorder(Border.createEtchedRaised());
buttonTextOnly.getSelectedStyle().setBgColor(0xC0C0C0);
f.addComponent(buttonTextOnly);

buttonImage = null;
try {
buttonImage = new Button(Image.createImage("/java.png"));
}
catch (IOException ex) {
ex.printStackTrace();
}
buttonImage.getStyle().setBorder(Border.createLineBorder(5, 0xA0A0A0));
buttonImage.getSelectedStyle().setBgColor(0xC0C0C0);
f.addComponent(buttonImage);

buttonTextAndImage = new Button();
buttonTextAndImage.setText("Button with Text and Image");
try {
buttonTextAndImage.setIcon(Image.createImage("/java.png"));
} catch (IOException ex) {
ex.printStackTrace();
}
buttonTextAndImage.getSelectedStyle().setBgColor(0xC0C0C0);
f.addComponent(buttonTextAndImage);

f.show();

exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);

buttonTextOnly.addActionListener(this);
buttonImage.addActionListener(this);
buttonTextAndImage.addActionListener(this);

}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void actionPerformed(ActionEvent ae) {
//notifyDestroyed();

Command aeCommand = ae.getCommand();
Object aeSource = ae.getSource();

if (aeCommand == exitCommand){
notifyDestroyed();
}

if(aeSource == buttonTextOnly){
buttonTextOnly.setText("I have been Pressed");
f.repaint();
}
else if(aeSource == buttonImage){
buttonImage.setText("I have been Pressed");
f.repaint();
}
else if(aeSource == buttonTextAndImage){
buttonTextAndImage.setText("I have been Pressed");
f.repaint();
}
}
}




Friday, June 18, 2010

LWUIT: Label

Some example using label component of LWUIT in JavaME

LWUIT: label

Download the image and save in the package folder.


source code:
import java.io.IOException;
import javax.microedition.midlet.*;

import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.plaf.Border;

public class HelloMIDlet extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);

Form f = new Form("Hello, MIDlet in LWUIT!");

Label labelTextOnly = new Label("I'm Label");
labelTextOnly.getStyle().setBorder(Border.createEtchedRaised());
f.addComponent(labelTextOnly);

Label labelImage = null;
try {
labelImage = new Label(Image.createImage("/java.png"));
}
catch (IOException ex) {
ex.printStackTrace();
}
labelImage.getStyle().setBorder(Border.createLineBorder(5, 0xA0A0A0));
f.addComponent(labelImage);

Label labelTextAndImage = new Label();
labelTextAndImage.setText("Label with Text and Image");
try {
labelTextAndImage.setIcon(Image.createImage("/java.png"));
} catch (IOException ex) {
ex.printStackTrace();
}
f.addComponent(labelTextAndImage);

f.show();

Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




Thursday, June 17, 2010

HelloLWUIT, start coding with LWUIT in NetBeans 6.9

We are going to start the most first MIDlet with LWUIT, using NetBeans 6.9 and LWUIT 1.3

It's supposed that NetBeans 6.9 have been installed correctly.

Before start coding, we have to download and install LWUIT.
-Download LWUIT and unzip in any folder you want.
http://java.sun.com/javame/technology/lwuit/

Create a MIDlet project
- Run NetBeans and start a new Mobile Application.


- Enter name of your project, HelloLWUIT. Un-select Create Hello MIDlet, click Next.


- Accept the default platform selection and configuration selection



Add LWUIT 1.3 in the project.
- In the Projects pane, right click on Resources, click Add Jar/Zip.


- Browse to the location of the downloaded and unzipped LWUIT.jar, click OK.


Start coding
- Right click our project package to New a MIDlet


- Enter the name and click Finish.


- Type in the code:


import javax.microedition.midlet.*;

import com.sun.lwuit.*;
import com.sun.lwuit.events.*;

public class HelloMIDlet extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);

Form f = new Form("Hello, MIDlet in LWUIT!");

f.show();

Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}


Finally, you can run it now.

LWUIT

LWUIT is a UI library that is bundled together with applications and helps content developers in creating compelling and consistent Java ME applications. LWUIT supports visual components and other UI goodies such as theming, transitions, animation and more.



Writing appealing cross device applications today in Java ME is challenging. Due to implementation differences in fonts, layout, menus, etc. the same application may look and behave very differently on different devices. In addition much of the advanced UI functionality is not accessible in LCDUI and requires the developer to write very low level "paint" type code. The Lightweight UI Toolkit was developed to address these issues. The Lightweight UI Toolkit makes it very easy to create compelling UI's that will look and behave the same on all devices using a programming paradigm similar to Swing. This Toolkit is able to run on CLDC1.1 MIDP2.0/CDC PBP/SE.

Wednesday, June 16, 2010

NetBeans IDE 6.9 Now Available for Download!

The NetBeans team announced the availability of NetBeans IDE 6.9!


NetBeans IDE 6.9 introduces the JavaFX Composer, a visual layout tool for building JavaFX GUI applications, similar to the Swing GUI builder for Java SE applications. With the JavaFX Composer, developers can quickly build, visually edit, and debug Rich Internet Applications (RIA) and bind components to various data sources, including Web services.

The NetBeans 6.9 release also features OSGi interoperability for NetBeans Platform applications and support for developing OSGi bundles with Maven. With support for OSGi and Swing standards, the NetBeans Platform now supports the standard UI toolkit and the standard module system, providing a unique combination of standards for modular, rich-client development.

Additional noteworthy features in this release include support for JavaFX SDK 1.3, PHP Zend framework, and Ruby on Rails 3.0; as well as improvements to the Java Editor, Java Debugger, issue tracking, and more.