wood burning stoves 2.0*
The moose likes Java in General and the fly likes how to make multiple rectangles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to make multiple rectangles" Watch "how to make multiple rectangles" New topic
Author

how to make multiple rectangles

vaishnavi Mukundhan
Greenhorn

Joined: Apr 14, 2013
Posts: 16
i have an array list.I want to print the contents of the array list in rectangles. as in each element should be in different rectangles. please help my code as of nowbut this doesn't work)

Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Hi vaishnavi.

You have problems at Lines 37, 39, and 46. Also, you have a sneaky problem in Line 41.

At Line 37: If classlist.size() returns 5, how many times will your loop execute? If you said "5," use a debugger and find out for sure.
At Line 39: What happens when you call super.paint(g)? Is this the best place to call it?
At Line 46: Why call super.paint(g) here again?

At Line 41: How big is your frame? Where does this line put your rectangle when you call g.drawRect() at line 47?

Make a few changes based on sensible answers to the above questions, and your program will run fine.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37953
    
  22
Why are you using the paint() method rather than paintComponent()?
vaishnavi Mukundhan
Greenhorn

Joined: Apr 14, 2013
Posts: 16
Stevens Miller wrote:Hi vaishnavi.

You have problems at Lines 37, 39, and 46. Also, you have a sneaky problem in Line 41.

At Line 37: If classlist.size() returns 5, how many times will your loop execute? If you said "5," use a debugger and find out for sure.
At Line 39: What happens when you call super.paint(g)? Is this the best place to call it?
At Line 46: Why call super.paint(g) here again?

At Line 41: How big is your frame? Where does this line put your rectangle when you call g.drawRect() at line 47?

Make a few changes based on sensible answers to the above questions, and your program will run fine.


hey i made the changes as suggested by you.it's working fine.thank you.
but it's still not giving the output i want.
it's printing the last element alone in one rectangle .its not printing 5 rectangles as there are 5 elements in my array list
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Are you sure it's not printing all five? You've got them so close together that they are almost overwriting each other. List your new code and I'll have a look.
vaishnavi Mukundhan
Greenhorn

Joined: Apr 14, 2013
Posts: 16
Stevens Miller wrote:Are you sure it's not printing all five? You've got them so close together that they are almost overwriting each other. List your new code and I'll have a look.


hey i almost fixed it and it's printing in two rows

vaishnavi Mukundhan
Greenhorn

Joined: Apr 14, 2013
Posts: 16
vaishnavi Mukundhan wrote:
Stevens Miller wrote:Are you sure it's not printing all five? You've got them so close together that they are almost overwriting each other. List your new code and I'll have a look.


hey i almost fixed it and it's printing in two rows



just have some problem with the coordinates . because the second row is starts below the first row and where the first row ends.
vaishnavi Mukundhan
Greenhorn

Joined: Apr 14, 2013
Posts: 16
vaishnavi Mukundhan wrote:
vaishnavi Mukundhan wrote:
Stevens Miller wrote:Are you sure it's not printing all five? You've got them so close together that they are almost overwriting each other. List your new code and I'll have a look.


hey i almost fixed it and it's printing in two rows



just have some problem with the coordinates . because the second row is starts below the first row and where the first row ends.


hey i solved it.it was a stupid thing. thanks a lot for your help.
Stevens Miller
Ranch Hand

Joined: Jul 26, 2012
Posts: 523
    
    3

Well done. By the way, Campbell raised a good point: most often, you will want to be dealing with paintComponent(), not paint(). There are valid cases where paint() is the better choice, but those are the exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make multiple rectangles
 
Similar Threads
MouseDragg
Array of objects/ graphics painting help
java swing repaint
Collision detection help please.
Drag and Drop