CanvasSC



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package paket;

import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* @author sertac
*/
public class Main extends MIDlet implements CommandListener {

Display d;
Form f;
Command cmdDisplay;
TextField tfWord;
Canvas canvasSC;
Displayable curr;
String s;

public Main() {


f = new Form("CanvasSC");
tfWord = new TextField("Yazdırmak istediğiniz yazıyı girin ", null, 10, TextField.ANY);
cmdDisplay = new Command("Display", Command.OK, 1);

f.addCommand(cmdDisplay);
f.append(tfWord);
f.setCommandListener(this);
}

public void startApp() {

d = Display.getDisplay(this);
if (curr != null) {
d.setCurrent(curr);
} else {
d.setCurrent(f);
curr = f;
}
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command arg0, Displayable arg1) {

if (arg0 == cmdDisplay) {

if (canvasSC == null) {

canvasSC = new CanvasSC();
}

curr = canvasSC;
d.setCurrent(curr);

}

}

class CanvasSC extends Canvas implements CommandListener, Runnable {

Command cmdBackToForm;
int w, h;
int gx = -999;
int x, y;
int nx = 10;
int ny = 10;
boolean r; //repaint indicator

public CanvasSC() {

cmdBackToForm = new Command("Back", Command.BACK, 0);
this.addCommand(cmdBackToForm);
this.setCommandListener(this);
w = this.getWidth();
h = this.getHeight();

x = w / 2;
y = h / 2;

s = tfWord.getString();

new Thread(this).start();

}

protected void paint(Graphics g) {
try {

//Temizlik
g.setGrayScale(255);
g.fillRect(0, 0, w, h);
//
Image resim = Image.createImage("/aquaticgarden.jpg");
g.drawImage(resim, resim.getWidth(), resim.getWidth(), Graphics.HCENTER|Graphics.VCENTER);

g.setGrayScale(0);

g.drawString(s, x, y, Graphics.BASELINE | Graphics.HCENTER);

} catch (IOException ex) {
ex.printStackTrace();
}

}

public void commandAction(Command arg0, Displayable arg1) {
curr = f;
d.setCurrent(curr);
}

public void run() {

while (true) {

switch (gx) {
case UP:
if (controlUpBound(y - ny)) {
y = y - ny;
}
break;
case DOWN:
if (controlDownBound(y + ny)) {
y = y + ny;
}
break;
case LEFT:
if (controlLeftBound(x - nx)) {
x = x - nx;
}
break;
case RIGHT:

if (controlRightBound(x + nx)) {
x = x + nx;
}
break;
case FIRE:



}


repaint();





try {
Thread.sleep(40);
} catch (InterruptedException e) {
}



}



}

protected void keyPressed(int arg0) {

gx = getGameAction(arg0);

}

public void keyReleased(int key) {
gx = -999;
}

private boolean controlLeftBound(int x) {
if (x < 0) {
return false;
} else {
return true;
}
}

private boolean controlRightBound(int x) {
if (x > w) {

return false;
} else {
return true;
}
}

private boolean controlUpBound(int y) {

if (y < 0) {
return false;
} else {
return true;
}
}

private boolean controlDownBound(int y) {
if (y > h) {

return false;
} else {
return true;
}
}
}
}

Comments

Popular posts from this blog

Pyppeteer fix for BrowserError: Browser closed unexpectedly

overlay filesystem and containers

How to add pagination to django comments for your model