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();
}
}
Friday, July 16, 2010
LWUIT: TabbedPane
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.
RadioButtons. For the group, the ButtonGroup instance guarantees that only one
button can be selected at a time.
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.
the available space within its cell, and each cell is exactly the same size.
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.
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.
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.
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);
Wednesday, July 7, 2010
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.
Tuesday, July 6, 2010
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
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
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
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();
}
}
Subscribe to:
Posts (Atom)