This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Resize objects from an ArrayList  RSS feed

 
bobby town
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a problem with my program. My aim is to display in a JPanel, 2 rectangles from an arraylist, and resize them by clicking. I want to give the user the ability to change the height of the rectangles (independently) by moving the top and/or bottom edges. There is errors in my code but where ? Netbeans underlines 2 lines (in bold). I can not find the solution.
Someone could help me fix my program ? Thank you very much.

My code:

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bobby town wrote:There is errors in my code but where ? Netbeans underlines 2 lines (in bold). I can not find the solution.


It always helps if you tell us what the error is. I'm guessing it's something to do with incompatible types.
r is a Rectangle, component.paths is an ArrayList. You can't assign one to the other.
I can't tell you how to fix it because I don't what you are expecting that piece of code to do.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bobby town wrote:My aim is to display in a JPanel, 2 rectangles from an arraylist, and resize them by clicking. I want to give the user the ability to change the height of the rectangles (independently) by moving the top and/or bottom edges. There is errors in my code but where ? Netbeans underlines 2 lines (in bold). I can not find the solution.

I suspect you're taking on too much at once. The ArrayList is almost certainly a distraction, so I'd eliminate it from your thoughts for the moment.

Write a program that can do exactly what you want with ONE rectangle; and only start thinking about collections of them once you've got it working.

Isolate the problem - that's how the pro's do it.

Winston
 
bobby town
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here is the code to resize one rectangle.
I would like to display several rectangles and resize them independantly, so the best way is to create an arraylist, right ? I have modified the code (see at the bottom), but it displays only the rectangles. No error messages when I test the program, but impossible to resize them.



MODIFIED CODE

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!