• 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
  • Paul Clapham
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst
  • Peter Rooke
  • Mikalai Zaikin
Bartenders:
  • Himai Minh

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 ());
}
}
}
 
You can't expect to wield supreme executive power just because
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic