Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help!please - something to with canvas. .

 
nico reyes
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ());
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic