Help with getWidth() method!!!

Hi,

I am trying to find my x,y coordintes with getWidth() and getHieght() methods.

My getWidth() is giving 200 as the width.

Is this the actual width of the screen?

I need to build a pyramid with 14 brinks at the botton and each brick is 30 pixels wide.The pyramid should be centered .

To find x coordinate I used the formula

x=( (getWidth() - (number of bricks * width of brick))/2

this gives me -110. I dont understand!!!

Re: Help with getWidth() method!!!

The getWidth() is returning the width of your panel or frame, not the screen. If you post your code between [code][/code] tags it will be easier to help you.

Regards,

Jim

Re: Help with getWidth() method!!!

Thanks for the quick reply...How do I find center of the screen?

I am trying to create a pyramid...can you guide me please.

This is the code I came up with

/** Number of bricks in the base of the pyramid */

private static int BRICKS_IN_BASE = 30;

/**Number of rows in the pyramid*/

private static final int NUMBER_OF_ROWS = 14;

public void run() {

/** formula for calcualting x coordintes (x=getWidth()-figureWidth))*/

double x = (getWidth() - (BRICK_WIDTH *BRICKS_IN_BASE)) /2;

println( "first pixel = " + x);

double y =getHeight() ;

println("second =" + y);

for(int j=0;j<=NUMBER_OF_ROWS;j++){

for(int i =0;i<=BRICKS_IN_BASE;i++){

x= i*BRICK_WIDTH;

y=j*BRICK_HEIGHT;

GRect rect = new GRect(x,y,BRICK_WIDTH,BRICK_HEIGHT);

add(rect);

}

BRICKS_IN_BASE = BRICKS_IN_BASE - 1;

}

}

}

Re: Help with getWidth() method!!!

To find the center of the screen, use the Toolkit.getDefaultToolkit().getScreenSize() method.

The center coordinate would be width/2, height/2,

And please remember to use code tags (see earlier post).

Regards,

Jim