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