wood burning stoves*
The moose likes Java Micro Edition and the fly likes need help!please - something to with canvas. . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "need help!please - something to with canvas. ." Watch "need help!please - something to with canvas. ." New topic
Author

need help!please - something to with canvas. .

nico reyes
Greenhorn

Joined: Feb 18, 2011
Posts: 1
trying to make a program that let's user input x and y coordinates for may object a fillrect in a canvas,but i can't set the input number by the user to the x and y coordinates for my rect.


here is my code::

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

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* @author Nico
*/
public class emp extends MIDlet implements CommandListener {
Display display;
Form frm = new Form ("Main");
TextField tfX = new TextField ("X Axis"," ",40,TextField.ANY);
TextField tfY = new TextField ("Y Axis"," ",40,TextField.ANY);
Command OK;

public emp () {
OK = new Command ("OK",Command.OK,1);


frm.append(tfX);
frm.append(tfY);
frm.addCommand(OK);

frm.setCommandListener(this);
}
int x1=0,y1=0;
public void calc (){

try {
x1=Integer.parseInt(tfX.getString());
y1=Integer.parseInt(tfY.getString());

}
catch (NumberFormatException aa){};
}


public void startApp () {
display = Display.getDisplay(this);
display.setCurrent(frm);
}

public void pauseApp () {}

public void destroyApp (boolean forced) {}




class DrawingCanvas extends Canvas implements CommandListener {
Command Bk;


public DrawingCanvas (){
this.addCommand(Bk= new Command("Back", Command.BACK, 0 ) );
this.setCommandListener(this);
}
public void paint (Graphics g) {
tfY.setString(String.valueOf(y1));
tfX.setString(String.valueOf(x1));

g.setColor (0, 0, 255);
g.fillRect(x1,y1, 50, 50);



}

public void commandAction(Command c, Displayable d) {
if (c==Bk){
display.setCurrent(frm);
}
}
}
public void commandAction(Command c, Displayable d) {

if (c==OK) {

display.setCurrent (new DrawingCanvas ());
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help!please - something to with canvas. .