aspose file tools*
The moose likes Beginning Java and the fly likes Need help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help with code" Watch "Need help with code" New topic
Author

Need help with code

Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Task : Write a GraphicsProgram subclass that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

But all I have been able to generate is right angled pyramid.
Below is the code I wrote.
Any help will be greatly appreciated.




Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
It's hard to understand your code as I have no idea what the GCompound class is. Also please don't use all upper case letters for variables, they are only for constants ie those declared as final static.

If you are successfully generating a right angle triangle then your problem is when you draw the next row your offset is wrong. You need to offset each new rows start position by half the width of a single brick. This is because each row has one less brick than the row below it, so to centre a row relative to the previous one you need to take off half a brick width at each end .
Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Thanks for the suggestion will try to do that.

The GCompound is part of acm package that belongs to GObject .
Taiwo Sokunbi
Greenhorn

Joined: Feb 01, 2012
Posts: 9
Thanks a lot it worked
@Tony
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
My pleasure
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with code
 
Similar Threads
my own classes, get var from other class
BreakOut Java Bug
trouble with mouseEvents
For Loops making me loopy
The pyramid attacks!