
Les cuento que estoy haciendo mis pininos en J2ME, Estoy usando NetBeans, y el WTK de Java en Linux Ubuntu, me gusta ubuntu por que esta basado en Debian y es sencillo de configurar.
Ya estoy probando mis midlets en un celular muy basico, con midp 2.0 los subo con un pequeño adaptador bluetooth usb, la instalacion es 100% plug and play para ubuntu.
El siguiente es un demo que hise:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
//import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import java.util.Random;
public class GraphicsMIDlet extends MIDlet implements CommandListener {
// The MIDlet's Display object
private Display display;
// Flag indicating first call of startApp
protected boolean started;
// Exit command
private Command exitCommand;
// Back to examples list command
private Command backCommand;
// The example selection list
private List examplesList;
// The Canvases used to demonstrate different Items
private Canvas[] canvases;
// The example names. Used to populate the list.
private String[] examples = {
"Lineas","Circulos","Pacmans"
};
protected void startApp() {
if (!started) {
started = true;
display = Display.getDisplay(this);
// Create the common commands
createCommands();
// Create the canvases
createCanvases();
// Create the list of examples
createList();
// Start with the List
display.setCurrent(examplesList);
// Start with lines
// La siguiente llama de inmediato a una de las opcione
//display.setCurrent(canvases[0]);
}
}
protected void pauseApp() {
}
protected void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (d == examplesList) {
// New example selected
int index = examplesList.getSelectedIndex();
display.setCurrent(canvases[index]);
} else if (c == exitCommand) {
// Exit. No need to call destroyApp
// because it is empty.
notifyDestroyed();
} else if (c == backCommand) {
// Go back to main selection list
display.setCurrent(examplesList);
}
}
private void createCommands() {
exitCommand = new Command("Exit", Command.EXIT, 0);
backCommand = new Command("Back", Command.BACK, 1);
}
private void createList() {
examplesList = new List("Select Example", List.IMPLICIT);
for (int i = 0; i < examples.length; i++) {
examplesList.append(examples[i], null);
}
examplesList.setCommandListener(this);
}
private void createCanvases() {
canvases = new Canvas[examples.length];
canvases[0] = createLinesCanvas();
canvases[1] = createCirculosCanvas();
canvases[2] = createPacmansCanvas();
}
private void addCommands(Displayable d) {
d.addCommand(exitCommand);
d.addCommand(backCommand);
d.setCommandListener(this);
}
// Create the Canvas for the line drawing example
private Canvas createLinesCanvas() {
Canvas canvas = new LineCanvas();
addCommands(canvas);
return canvas;
}
// Create the Canvas for the line drawing example
private Canvas createCirculosCanvas() {
Canvas canvas = new CirculosCanvas();
addCommands(canvas);
return canvas;
}
// Create the Canvas for the line drawing example
private Canvas createPacmansCanvas() {
Canvas canvas = new PacmansCanvas();
addCommands(canvas);
return canvas;
}
// A canvas that illustrates line drawing
class LineCanvas extends Canvas {
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
Random random;
random = new Random();
int nred = 0 + Math.abs(random.nextInt()) % 255;
int ngreen = 0 + Math.abs(random.nextInt()) % 255;
int nblue = 0 + Math.abs(random.nextInt()) % 255;
// Yellow dotted horizontal line
g.setStrokeStyle(Graphics.DOTTED);
g.setColor(nred,ngreen,nblue);
// g.drawLine(0, height/4, width - 1, height/4);
for (int loo = 1; loo < height; loo=loo+5) {
nred = 0 + Math.abs(random.nextInt()) % 255;
ngreen = 0 + Math.abs(random.nextInt()) % 255;
nblue = 0 + Math.abs(random.nextInt()) % 255;
g.setColor(nred,ngreen,nblue);
g.drawLine(loo, 0, (width - 1), loo );
g.drawLine(loo, 1, (width - 1), loo+1 );
g.drawLine(loo, 2, (width - 1), loo+2 );
}
}
// A canvas that illustrates line drawing
}
class CirculosCanvas extends Canvas {
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
int Ratwidth = width /100;
int Ratheight = height /100;
Random random;
random = new Random();
int nred = 0 + Math.abs(random.nextInt()) % 255;
int ngreen = 0 + Math.abs(random.nextInt()) % 255;
int nblue = 0 + Math.abs(random.nextInt()) % 255;
int nposx;
int nposy;
int lastp;
int slastp;
// Yellow dotted horizontal line
g.setStrokeStyle(Graphics.DOTTED);
g.setColor(nred,ngreen,nblue);
// g.drawLine(0, height/4, width - 1, height/4);
for (int loo = 1; loo < 1000; loo=loo+5) {
nred = 0 + Math.abs(random.nextInt()) % 255;
ngreen = 0 + Math.abs(random.nextInt()) % 255;
nblue = 0 + Math.abs(random.nextInt()) % 255;
nposx = (Math.abs(random.nextInt()) % 100)*Ratwidth;
nposy = (Math.abs(random.nextInt()) % 100)*Ratheight;
lastp = Math.abs(random.nextInt()) % 360;
slastp = Math.abs(random.nextInt()) % 360;
g.setColor(nred,ngreen,nblue);
g.fillArc(nposx,nposy, Ratwidth*9 , Ratheight *9, slastp, lastp);
}
}
}
class PacmansCanvas extends Canvas {
public void paint(Graphics g) {
int width = getWidth();
int height = getHeight();
int Ratwidth = width /100;
int Ratheight = height /100;
Random random;
random = new Random();
int nred = 0 + Math.abs(random.nextInt()) % 255;
int ngreen = 0 + Math.abs(random.nextInt()) % 255;
int nblue = 0 + Math.abs(random.nextInt()) % 255;
int nposx;
int nposy;
int lastp;
int slastp;
int swaper;
String cadena;
// Yellow dotted horizontal line
g.setStrokeStyle(Graphics.SOLID);
g.setColor(nred,ngreen,nblue);
// g.drawLine(0, height/4, width - 1, height/4);
for (int loo = 1; loo < 500; loo=loo+5) {
nred = 100 + Math.abs(random.nextInt()) % 150;
ngreen = 0 + Math.abs(random.nextInt()) % 150;
nblue = 0 + Math.abs(random.nextInt()) % 25;
nposx = (Math.abs(random.nextInt()) % 100)*Ratwidth;
nposy = (Math.abs(random.nextInt()) % 100)*Ratheight;
lastp = Math.abs(random.nextInt()) % 360;
slastp = lastp+ Math.abs(random.nextInt()) % 60;
// Es un pacman?, si no, asegurate de hacerlo pacmanoide
if (lastp > slastp)
{ swaper = slastp;
slastp = lastp;
lastp = swaper;
}
if (slastp-lastp <90) lastp=lastp+80;
if (slastp-lastp <359) lastp=lastp-20;
g.setColor(0,0,0);
g.fillArc(nposx,nposy, Ratwidth*18 , Ratheight *18, slastp, lastp);
g.setColor(nred,ngreen,nblue);
g.fillArc(nposx,nposy,(Ratwidth*18) -3, (Ratheight *18) -3 ,slastp, lastp);
cadena = String.valueOf(slastp);
// g.drawString(cadena,nposx,nposy,0);
}
}
}
}

No hay comentarios:
Publicar un comentario