Skip to content

Instantly share code, notes, and snippets.

public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Basic memory leakage test");
Container mainContainer = hi.getContentPane();
BorderLayout layout = new BorderLayout();
mainContainer.setLayout(layout);
/*mainContainer.setScrollableX(false);
@codenameone
codenameone / BGLocationTest.java
Last active April 17, 2016 16:22 — forked from shannah/BGLocationTest.java
Geofence Example
public void showForm() {
Form hi = new Form("Hi World");
hi.addComponent(new Label("Hi World"));
Location loc = new Location();
loc.setLatitude(51.5033630);
loc.setLongitude(-0.1276250);
Geofence gf = new Geofence("test", loc, 100, 100000);
@codenameone
codenameone / Sample.java
Last active January 15, 2016 17:21 — forked from shannah/Sample.java
A background painter that puts a circle in the background of a component.
Painter p = new Painter(cmp) {
public void paint(Graphics g, Rectangle rect) {
boolean antiAliased = g.isAntiAliased();
g.setAntiAliased(true);
int r = Math.min(rect.getWidth(), rect.getHeight())/2;
int x = rect.getX() + rect.getWidth()/2 - r;
int y = rect.getY() + rect.getHeight()/2 - r;
switch (style) {
case CircleButtonStrokedDark:
case CircleButtonStrokedLight: {
myContainer.add(new InfiniteProgress());
Dialog ip = new InfiniteProgress().showInifiniteBlocking();
// do some long operation here using invokeAndBlock or do something in a separate thread and callback later
// when you are done just call
ip.dispose();
@codenameone
codenameone / ShowDialogAtBottomOfScreen.java
Created January 20, 2016 13:13
Code to show the Dialog dlg at the bottom 1/8th of the screen, it will dispose when clicking out of bounds
Dialog dlg = new Dialog("At Bottom");
dlg.setLayout(new BorderLayout());
// span label accepts the text and the UIID for the dialog body
dlg.add(new SpanLabel("Dialog Body text", "DialogBody"));
int h = Display.getInstance().getDisplayHeight();
dlg.setDisposeWhenPointerOutOfBounds(true);
dlg.show(h /8 * 7, 0, 0, 0);
@codenameone
codenameone / DialogUsage.java
Created January 20, 2016 13:19
Sample usage of the Codename One Dialog class taken from the kitchen sink demo
final Button show = new Button("Show Dialog");
final Button showPopup = new Button("Show Popup");
cnt.add(show).add(showPopup);
show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Dialog.show("Dialog Title", "This is the dialog body, it can contain anything...", "OK", "Cancel");
}
});
showPopup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
@codenameone
codenameone / BorderLayoutSample.java
Created January 25, 2016 19:54
Sample of using the BorderLayout class in Codename One
Form hi = new Form("Border Layout", new BorderLayout());
hi.add(BorderLayout.CENTER, new Label("Center")).
add(BorderLayout.SOUTH, new Label("South")).
add(BorderLayout.NORTH, new Label("North")).
add(BorderLayout.EAST, new Label("East")).
add(BorderLayout.WEST, new Label("West"));
hi.show();
@codenameone
codenameone / BorderLayoutCenterSample.java
Created January 25, 2016 20:12
A border layout sample that demonstrates the center behavior option
Form hi = new Form("Border Layout", new BorderLayout());
((BorderLayout)hi.getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
hi.add(BorderLayout.CENTER, new Label("Center")).
add(BorderLayout.SOUTH, new Label("South")).
add(BorderLayout.NORTH, new Label("North")).
add(BorderLayout.EAST, new Label("East")).
add(BorderLayout.WEST, new Label("West"));
hi.show();
@codenameone
codenameone / FlowLayoutSample.java
Created January 25, 2016 20:39
A usage sample for the Codename One FlowLayout layout manager
Form hi = new Form("Flow Layout", new FlowLayout());
hi.add(new Label("First")).
add(new Label("Second")).
add(new Label("Third")).
add(new Label("Fourth")).
add(new Label("Fifth"));
hi.show();