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.
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();
}
}
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();
}
}
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"));
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"));
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);
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);
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();
}
}
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.
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
}
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();
}
}
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();
}
}
The NetBeans team announced the availability of NetBeans IDE 6.9!