-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
http://snk.to/f-ctm2u2y8
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR IMAGE MOVE
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.amplify.canvas;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.*;
import java.lang.*;
import javax.microedition.lcdui.Font;
/**
* @author P.HINDUJA
*/
public class MyImageCanvas extends MIDlet {
Display disp;
Image im;
MyImageView miv;
public MyImageCanvas() {
disp = Display.getDisplay(this);
try {
im = Image.createImage("/splashScreen.png");
} catch (Exception e) {
System.out.println(e.toString());
}
miv = new MyImageView(im);
}
public void startApp() {
disp.setCurrent(miv);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class MyImageView extends Canvas {
Image img;
String str;
int px, py;
public MyImageView(Image i) {
img = i;
str = "PRESS ANY ACTION KEY";
// getGameAction(UP);
px = getWidth()/2;
py = getHeight()/2;
}
protected void paint(Graphics g) {
// g.setGrayScale(255);
g.setColor(255, 0, 0);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img, px,
py, g.HCENTER | g.VCENTER);
System.out.println("WIDTH >>> " + getWidth());
System.out.println("HEIGHT >>> " + getHeight());
g.setColor(255, 255, 255);
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD, Font.SIZE_LARGE));
g.drawString(str, getWidth() / 2, 0,
Graphics.TOP | Graphics.HCENTER);
// throw new UnsupportedOperationException("Not supported yet.");
}
protected void keyPressed(int keyCode) {
int gameAction = getGameAction(keyCode);
switch (gameAction) {
case UP:
str = "UP PRESSED";
py-=10;
repaint();
break;
case DOWN:
str = "DOWN PRESSED";
py+=10;
repaint();
break;
case LEFT:
str = "LEFT PRESSED";
px-=10;
repaint();
break;
case RIGHT:
str = "RIGHT PRESSED";
px+=10;
repaint();
break;
case FIRE:
str = "FIRE PRESSED";
px=getWidth()/2;
py=getHeight()/2;
repaint();
break;
case KEY_POUND:
str = "HASH KEY PRESSED";
repaint();
break;
case KEY_STAR:
str = "STAR KEY PRESSED";
repaint();
break;
}
super.keyPressed(keyCode);
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR RANDOM IMAGES
package hello;
import java.util.Random;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Display display; // The display for this MIDlet
private MyImageCanvas ic;
public HelloMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
}
public void startApp() {
ic = new MyImageCanvas(/*20, 20*/);
ic.addCommand(exitCommand);
ic.setCommandListener(this);
display.setCurrent(ic);
for(int i=0; i<20; i++){
try{
Thread.sleep(2000);
} catch(Exception e){}
// ic = new MyImageCanvas(100, 100);
// display.setCurrent(ic);
ic.repaint();
}
// try{
// Thread.sleep(3000);
// } catch(Exception e){}
// ic = new MyImageCanvas(200, 200);
// display.setCurrent(ic);
// ic.repaint();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class MyImageCanvas extends Canvas {
Image img;
// int xp, yp;
public MyImageCanvas(/*int x, int y*/) {
try{
img = Image.createImage("/Duke.png");
// xp = x;
// yp = y;
} catch(Exception e){
System.out.println(e.toString());
}
}
protected void paint(Graphics g) {
int Xstart = img.getWidth()/2;
Random rx = new Random();
int Xmax = getWidth()-(img.getWidth()/2);
int xr = rx.nextInt(Xmax);
if (xr < Xstart)
xr=Xstart;
int Ystart = img.getHeight()/2;
Random ry = new Random();
int Ymax = getHeight()-(img.getHeight()/2);
int yr = ry.nextInt(Ymax);
if (yr < Ystart)
yr=Ystart;
Random rcolor = new Random();
int rc = rcolor.nextInt(255);
int gc = rcolor.nextInt(255);
int bc = rcolor.nextInt(255);
g.setColor(rc, gc, bc);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img, xr,
yr, g.HCENTER|g.VCENTER);
// for(int i=0; i<20; i++){
// g.drawImage(img, getWidth()/4,
// (getHeight()/4)+(i*50),
// g.HCENTER|g.VCENTER);
// g.drawImage(img, (getWidth()/4)+(i*70),
// 3*(getHeight()/4),
// g.HCENTER|g.VCENTER);
// }
// throw new UnsupportedOperationException("Not " +
// "supported yet.");
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR RECORD MANAGEMENT
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand,save; // The exit command
private Display display; // The display for this MIDlet
TextField txtname,txtage,txtemail;
Form register;
Form blank;
RecordStore rs;
public HelloMIDlet() {
display = Display.getDisplay(this);
register=new Form("Register Form");
blank=new Form("Welcome");
save=new Command("Save", Command.SCREEN, 1);
exitCommand = new Command("Exit", Command.EXIT, 0);
txtname=new TextField("Name", "", 20, TextField.ANY);
txtage=new TextField("Age", "", 20, TextField.NUMERIC);
txtemail=new TextField("Email", "", 20, TextField.ANY);
try {
rs=RecordStore.openRecordStore("reg", true);
} catch (Exception e) {
}
}
public void startApp() {
display.setCurrent(register);
register.append(txtname);
register.append(txtage);
register.append(txtemail);
register.setCommandListener(this);
register.addCommand(save);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if(c == save)
{
display.setCurrent(blank);
try {
rs.addRecord(txtname.getString().getBytes(), 0, txtname.getString().length());
rs.addRecord(txtage.getString().getBytes(), 0, txtage.getString().length());
rs.addRecord(txtemail.getString().getBytes(), 0, txtemail.getString().length());
for(int i=1;i<=rs.getNumRecords();i++)
{
byte[] text=rs.getRecord(i);
String name= new String(text);
blank.append("\n"+name);
}
} catch (Exception e) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
http://snk.to/f-ctm2u2y8
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR IMAGE MOVE
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.amplify.canvas;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.*;
import java.lang.*;
import javax.microedition.lcdui.Font;
/**
* @author P.HINDUJA
*/
public class MyImageCanvas extends MIDlet {
Display disp;
Image im;
MyImageView miv;
public MyImageCanvas() {
disp = Display.getDisplay(this);
try {
im = Image.createImage("/splashScreen.png");
} catch (Exception e) {
System.out.println(e.toString());
}
miv = new MyImageView(im);
}
public void startApp() {
disp.setCurrent(miv);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class MyImageView extends Canvas {
Image img;
String str;
int px, py;
public MyImageView(Image i) {
img = i;
str = "PRESS ANY ACTION KEY";
// getGameAction(UP);
px = getWidth()/2;
py = getHeight()/2;
}
protected void paint(Graphics g) {
// g.setGrayScale(255);
g.setColor(255, 0, 0);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img, px,
py, g.HCENTER | g.VCENTER);
System.out.println("WIDTH >>> " + getWidth());
System.out.println("HEIGHT >>> " + getHeight());
g.setColor(255, 255, 255);
g.setFont(Font.getFont(Font.FACE_SYSTEM,
Font.STYLE_BOLD, Font.SIZE_LARGE));
g.drawString(str, getWidth() / 2, 0,
Graphics.TOP | Graphics.HCENTER);
// throw new UnsupportedOperationException("Not supported yet.");
}
protected void keyPressed(int keyCode) {
int gameAction = getGameAction(keyCode);
switch (gameAction) {
case UP:
str = "UP PRESSED";
py-=10;
repaint();
break;
case DOWN:
str = "DOWN PRESSED";
py+=10;
repaint();
break;
case LEFT:
str = "LEFT PRESSED";
px-=10;
repaint();
break;
case RIGHT:
str = "RIGHT PRESSED";
px+=10;
repaint();
break;
case FIRE:
str = "FIRE PRESSED";
px=getWidth()/2;
py=getHeight()/2;
repaint();
break;
case KEY_POUND:
str = "HASH KEY PRESSED";
repaint();
break;
case KEY_STAR:
str = "STAR KEY PRESSED";
repaint();
break;
}
super.keyPressed(keyCode);
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR RANDOM IMAGES
package hello;
import java.util.Random;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand; // The exit command
private Display display; // The display for this MIDlet
private MyImageCanvas ic;
public HelloMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
}
public void startApp() {
ic = new MyImageCanvas(/*20, 20*/);
ic.addCommand(exitCommand);
ic.setCommandListener(this);
display.setCurrent(ic);
for(int i=0; i<20; i++){
try{
Thread.sleep(2000);
} catch(Exception e){}
// ic = new MyImageCanvas(100, 100);
// display.setCurrent(ic);
ic.repaint();
}
// try{
// Thread.sleep(3000);
// } catch(Exception e){}
// ic = new MyImageCanvas(200, 200);
// display.setCurrent(ic);
// ic.repaint();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class MyImageCanvas extends Canvas {
Image img;
// int xp, yp;
public MyImageCanvas(/*int x, int y*/) {
try{
img = Image.createImage("/Duke.png");
// xp = x;
// yp = y;
} catch(Exception e){
System.out.println(e.toString());
}
}
protected void paint(Graphics g) {
int Xstart = img.getWidth()/2;
Random rx = new Random();
int Xmax = getWidth()-(img.getWidth()/2);
int xr = rx.nextInt(Xmax);
if (xr < Xstart)
xr=Xstart;
int Ystart = img.getHeight()/2;
Random ry = new Random();
int Ymax = getHeight()-(img.getHeight()/2);
int yr = ry.nextInt(Ymax);
if (yr < Ystart)
yr=Ystart;
Random rcolor = new Random();
int rc = rcolor.nextInt(255);
int gc = rcolor.nextInt(255);
int bc = rcolor.nextInt(255);
g.setColor(rc, gc, bc);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(img, xr,
yr, g.HCENTER|g.VCENTER);
// for(int i=0; i<20; i++){
// g.drawImage(img, getWidth()/4,
// (getHeight()/4)+(i*50),
// g.HCENTER|g.VCENTER);
// g.drawImage(img, (getWidth()/4)+(i*70),
// 3*(getHeight()/4),
// g.HCENTER|g.VCENTER);
// }
// throw new UnsupportedOperationException("Not " +
// "supported yet.");
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR RECORD MANAGEMENT
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordStore;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand,save; // The exit command
private Display display; // The display for this MIDlet
TextField txtname,txtage,txtemail;
Form register;
Form blank;
RecordStore rs;
public HelloMIDlet() {
display = Display.getDisplay(this);
register=new Form("Register Form");
blank=new Form("Welcome");
save=new Command("Save", Command.SCREEN, 1);
exitCommand = new Command("Exit", Command.EXIT, 0);
txtname=new TextField("Name", "", 20, TextField.ANY);
txtage=new TextField("Age", "", 20, TextField.NUMERIC);
txtemail=new TextField("Email", "", 20, TextField.ANY);
try {
rs=RecordStore.openRecordStore("reg", true);
} catch (Exception e) {
}
}
public void startApp() {
display.setCurrent(register);
register.append(txtname);
register.append(txtage);
register.append(txtemail);
register.setCommandListener(this);
register.addCommand(save);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if(c == save)
{
display.setCurrent(blank);
try {
rs.addRecord(txtname.getString().getBytes(), 0, txtname.getString().length());
rs.addRecord(txtage.getString().getBytes(), 0, txtage.getString().length());
rs.addRecord(txtemail.getString().getBytes(), 0, txtemail.getString().length());
for(int i=1;i<=rs.getNumRecords();i++)
{
byte[] text=rs.getRecord(i);
String name= new String(text);
blank.append("\n"+name);
}
} catch (Exception e) {
}
}
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR TEXT PROG.
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand, mm; // The exit command
private Display display; // The display for this MIDlet
Form page1;
TextField txt;
Alert a1;
public HelloMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
mm = new Command("SHOW", Command.SCREEN, 0);
txt = new TextField("write", null, 20, TextField.ANY);
page1 = new Form("welcome");
//a1 = new Alert("" + txt.getString().toString());
}
public void startApp() {
display.setCurrent(page1);
page1.append(txt);
page1.setCommandListener(this);
page1.addCommand(mm);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if (c == mm){
a1 = new Alert("" + txt.getString().toString());
display.setCurrent(a1);
}
}
}
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
FOR PREVIOUS NEXT
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener {
private Command exitCommand, prev, next; // The exit command
private Display display; // The display for this MIDlet
Form page1, page2;
public HelloMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
prev = new Command("PREV", Command.SCREEN, 0);
next = new Command("NEXT", Command.SCREEN, 0);
page1=new Form("Welcome");
page2=new Form("GO BACK...!");
}
public void startApp() {
display.setCurrent(page1);
page1.setCommandListener(this);
page1.addCommand(prev);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if(c == next){
page2.setCommandListener(this);
page2.addCommand(prev);
display.setCurrent(page2);
} else if (c == prev){
page1.setCommandListener(this);
page1.addCommand(next);
display.setCurrent(page1);
}
}
}
-----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------