Monday, September 6, 2010

Light Weight User Interface Toolkit 1.4 is now available

August 2010
Light Weight User Interface Toolkit 1.4 is now available
both in source and binary form. With the new XHTML component - rendering dynamic web content and embedding rich text locally in the Java ME applications will be easier than ever before. » Key features in the new release




Friday, July 16, 2010

LWUIT: TabbedPane

LWUIT: TabbedPane


import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;

public class LwuitTabbedPane extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Lwuit TabbedPane");
f.setLayout(new BorderLayout());
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);

f.setTitle("Lwuit TabbedPane");

TabbedPane tp = new TabbedPane();

tp.addTab("Tab 1", new Label("LWUIT: TabbedPane"));

Container tabPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));

RadioButton radioButton1 = new RadioButton("Radio Button 1");
RadioButton radioButton2 = new RadioButton("Radio Button 2");
RadioButton radioButton3 = new RadioButton("Radio Button 3");
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(radioButton1);
buttonGroup1.add(radioButton2);
buttonGroup1.add(radioButton3);
tabPanel.addComponent(radioButton1);
tabPanel.addComponent(radioButton2);
tabPanel.addComponent(radioButton3);

RadioButton radioButtonA = new RadioButton("Radio Button A");
RadioButton radioButtonB = new RadioButton("Radio Button B");
ButtonGroup buttonGroup2 = new ButtonGroup();
buttonGroup2.add(radioButtonA);
buttonGroup2.add(radioButtonB);
tabPanel.addComponent(radioButtonA);
tabPanel.addComponent(radioButtonB);

tp.addTab("Tab 2", tabPanel);

f.addComponent(BorderLayout.CENTER, tp);
f.show();

}

public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




LWUIT: ButtonGroup

The ButtonGroup component manages the selected and unselected states for a set of
RadioButtons. For the group, the ButtonGroup instance guarantees that only one
button can be selected at a time.

LWUIT: ButtonGroup


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

public class LwuitButtonGroup extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, MIDlet in LWUIT!");
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);

f.setTitle("ButtonGroup");

RadioButton radioButton1 = new RadioButton("Radio Button 1");
RadioButton radioButton2 = new RadioButton("Radio Button 2");
RadioButton radioButton3 = new RadioButton("Radio Button 3");
ButtonGroup buttonGroup1 = new ButtonGroup();
buttonGroup1.add(radioButton1);
buttonGroup1.add(radioButton2);
buttonGroup1.add(radioButton3);
f.addComponent(radioButton1);
f.addComponent(radioButton2);
f.addComponent(radioButton3);

RadioButton radioButtonA = new RadioButton("Radio Button A");
RadioButton radioButtonB = new RadioButton("Radio Button B");
ButtonGroup buttonGroup2 = new ButtonGroup();
buttonGroup2.add(radioButtonA);
buttonGroup2.add(radioButtonB);
f.addComponent(radioButtonA);
f.addComponent(radioButtonB);

f.show();

}

public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




Monday, July 12, 2010

LWUIT: GridLayout

A GridLayout object places components in a grid of cells. Each component takes all
the available space within its cell, and each cell is exactly the same size.

LWUIT: GridLayout


GridLayout gridLayout = new GridLayout(3, 2);
f.setLayout(gridLayout);
f.setTitle("GridLayout");

f.addComponent(new Button("Button 1"));
f.addComponent(new Button("Button 2"));
f.addComponent(new Button("Button 3"));
f.addComponent(new Label("Label 1"));
f.addComponent(new Button("Button 4"));




LWUIT: FlowLayout

The FlowLayout class provides a very simple layout manager that is the default
layout manager for Container objects.
The FlowLayout class puts components in a row, sized at their preferred size. If the
horizontal space in the container is too small to put all the components in one row,
the FlowLayout class uses multiple rows. To align the row to the left, right, or center,
use a FlowLayout constructor that takes an alignment argument.

LWUIT: FlowLayout


FlowLayout flowLayout = new FlowLayout();
f.setLayout(flowLayout);
f.setTitle("FlowLayout");

f.addComponent(new Button("Button 1"));
f.addComponent(new Button("Button 2"));
f.addComponent(new Button("Button 3"));
f.addComponent(new Label("Label 1"));
f.addComponent(new Button("Button 4"));




LWUIT: BoxLayout

The BoxLayout class puts components either on top of each other or in a row.

LWUIT: BoxLayout.X_AXIS


BoxLayout boxLayout = new BoxLayout(BoxLayout.X_AXIS);
f.setLayout(boxLayout);
f.setTitle("BoxLayout: BoxLayout.X_AXIS");

Button button1 = new Button("Button 1");
Button button2 = new Button("Button 2");
Button button3 = new Button("Button 3");
f.addComponent(button1);
f.addComponent(button2);
f.addComponent(button3);


LWUIT: BoxLayout.Y_AXIS


BoxLayout boxLayout = new BoxLayout(BoxLayout.Y_AXIS);
f.setLayout(boxLayout);
f.setTitle("BoxLayout: BoxLayout.Y_AXIS");

Button button1 = new Button("Button 1");
Button button2 = new Button("Button 2");
Button button3 = new Button("Button 3");
f.addComponent(button1);
f.addComponent(button2);
f.addComponent(button3);




Wednesday, July 7, 2010

LWUIT: BorderLayout

LWUIT: BorderLayout


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

public class LwuitLayout extends MIDlet implements ActionListener {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, MIDlet in LWUIT!");
Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);

BorderLayout borderLayout = new BorderLayout();
f.setLayout(borderLayout);
f.setTitle("BorderLayout");

Label labelCenter = new Label("Center");
Label labelEast = new Label("East");
Label labelSouth = new Label("South");
Label labelWest = new Label("West");
Label labelNorth = new Label("North");
f.addComponent(BorderLayout.CENTER, labelCenter);
f.addComponent(BorderLayout.EAST, labelEast);
f.addComponent(BorderLayout.SOUTH, labelSouth);
f.addComponent(BorderLayout.WEST, labelWest);
f.addComponent(BorderLayout.NORTH, labelNorth);

f.show();
}

public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}

LWUIT: Layout

The form takes care of positioning the components. It uses a layout manager to decide where everything goes. For you AWT and Swing jocks, this should sound familar. Layout managers are great for mobile applications because they are good at adjusting to different screen sizes and filling the available space gracefully.

LWUIT includes five layout managers.

  • FlowLayout places components from left to right in rows, just like English text.
  • BorderLayout has a large center area and four smaller areas around the edges.
  • BoxLayout arranges components in a single row or column.
  • GridLayout places components in a grid.
  • More complex layouts can be accomplished using GroupLayout and its helper class Group.
ref: LWUIT Tutorial - Using Layouts

Tuesday, July 6, 2010

LWUIT: Calendar

LWUIT: Calendar


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!");

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

Calendar calendar = new Calendar();
f.addComponent(calendar);

f.show();

}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




LWUIT: TextArea

LWUIT: TextArea


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);

TextArea textArea1 = new TextArea("A simple TextArea");
f.addComponent(textArea1);

TextArea textArea2 = new TextArea("Another TextArea with rows and columns.", 4, 25);
f.addComponent(textArea2);

}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




Sunday, July 4, 2010

LWUIT: Combo Box

LWUIT: Combo Box

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);

List list = new List();
list.addItem("Sunday");
list.addItem("Monday");
list.addItem("Tuesday");
list.addItem("Wednesday");
list.addItem("Thursday");
list.addItem("Friday");
list.addItem("Saturday");
ComboBox comboBox = new ComboBox(list.getModel());
f.addComponent(comboBox);

}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




LWUIT: Check Box

LWUIT: Check Box


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);

CheckBox checkBox_1 = new CheckBox("CheckBox 1");
CheckBox checkBox_2 = new CheckBox("CheckBox 2");
CheckBox checkBox_3 = new CheckBox("CheckBox 3");

f.addComponent(checkBox_1);
f.addComponent(checkBox_2);
f.addComponent(checkBox_3);

}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}

LWUIT: Radio Button




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);

RadioButton radioButton_1 = new RadioButton("Radio Button 1");
RadioButton radioButton_2 = new RadioButton("Radio Button 2");
RadioButton radioButton_3 = new RadioButton("Radio Button 3");

f.addComponent(radioButton_1);
f.addComponent(radioButton_2);
f.addComponent(radioButton_3);

}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}
}




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.