Membuat Layout Sendiri di J2ME

Author: al-farouq

wehe

Sekarang kita coba membuat layout di j2me, layout mempunyai beberapa macam yaitu
1) BoxLayoutY
2) BoxLayoutX
3) BorderLayout
4) FlowLayout
5) GridLayout

sekarang kita coba membuat ke 5 layout tersebut

Buatlah sebuah file java class dengan nama LayoutDemo.java
kemudian tuliskan cource code seperti dibawah ini

--------------------------------------------------------------------------------------------------

import com.sun.lwuit.Button;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.layouts.FlowLayout;
import com.sun.lwuit.layouts.GridLayout;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class LayoutDemo extends MIDlet {

private Button border;

private Button boxY;

private Button boxX;

private Button flow;

private Button grid;

public void cleanup() {
border = null;
boxY = null;
flow = null;
grid = null;
boxX = null;
}

public String getName() {
return "Layouts";
}


protected void execute(final Form f) {
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
border = new Button("BorderLayout");
border.getStyle().setBgTransparency(100);

border.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
f.setLayout(new BorderLayout());
f.removeAll();
f.setScrollable(false);
f.addComponent(BorderLayout.NORTH, border);
f.addComponent(BorderLayout.EAST, boxY);
f.addComponent(BorderLayout.CENTER, grid);
f.addComponent(BorderLayout.WEST, flow);
f.addComponent(BorderLayout.SOUTH, boxX);
f.show();
}
});
boxY = new Button("BoxLayout-Y");
boxY.getStyle().setBgTransparency(100);
boxY.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
f.setScrollable(false);
addComponents(f);
f.show();
}
});
flow = new Button("FlowLayout");
flow.getStyle().setBgTransparency(100);
flow.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
f.setLayout(new FlowLayout());
f.setScrollable(false);
addComponents(f);
f.show();
}
});

grid = new Button("GridLayout");
grid.getStyle().setBgTransparency(100);
grid.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
f.setLayout(new GridLayout(3, 2));
f.setScrollable(false);
addComponents(f);
f.show();
}
});

boxX = new Button("BoxLayout-X");
boxX.getStyle().setBgTransparency(100);
boxX.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
f.setLayout(new BoxLayout(BoxLayout.X_AXIS));
f.setScrollable(true);
addComponents(f);
f.show();
}
});


addComponents(f);
f.show();
}

private void addComponents(final Form f){
f.removeAll();
f.addComponent(boxY);
f.addComponent(boxX);
f.addComponent(border);
f.addComponent(flow);
f.addComponent(grid);
}

protected void startApp() throws MIDletStateChangeException {
throw new UnsupportedOperationException("Not supported yet.");
}

protected void pauseApp() {
throw new UnsupportedOperationException("Not supported yet.");
}

protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
throw new UnsupportedOperationException("Not supported yet.");
}
}

---------------------------------------------------------------------------------------------------

oh iya sampek lupa copy kan file LWUIT.jar di folder lib
Sekarang telah selesai lah membuat layout, heheheee!
silahkan mencoba ^_^ .

 

0 Response to “Membuat Layout Sendiri di J2ME”

Leave a Reply