• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help!please - something to with canvas. .

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ());
}
}
}
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic