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

why wont this graphics respond?  RSS feed

 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I call repaint all that happens is that page is set back to green


thanks for any help!
[ April 03, 2008: Message edited by: colton peterson ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, setting the background to green is all this code does. Are any of the Rabbit.draw methods called? Do they perform any additional drawing?
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, they do.

here is my Rabbit's drawing method
the first part is a little long because it is finding an empty point where there are no rabbits.

 
Brian Cole
Author
Ranch Hand
Posts: 935
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by colton peterson:
yes, they do.

here is my Rabbit's drawing method


Well this method doesn't actually do anything with the Graphics object except pass it to the photo.paintIcon(), and we can't tell what that method does.

Even if Rabbit.draw() did call something like davinci.drawLine(), the line would be drawn in green (on the green background, so invisible) unless it called something like davinci.setColor() first.

btw, the "G = g" line in Paper.paintComponent() is suspect. What's it for?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are lots of println()s in this code. Do you see any of the outputs? If not, then the first thing to do is find out why none of the rabbit.draw() calls are being made. If you *do* see them, then check out what Brian said.
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the G = g line is to set a class wide graphics variable so that other methods may call draw() on rabbits and other objects and it is disposed when it is done. I do see all the println() methods in fact it sometimes gets caught in a infinite loop and just endlessly prints out "rabbit drawn"

I will try what he said. just call

g.setColor();

before calling draw() right?

and paintIcon(); does nothing more than pass the graphics object up to the paintIcon() found in ImageIcon
[ April 04, 2008: Message edited by: colton peterson ]
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
didn't work
 
Brian Cole
Author
Ranch Hand
Posts: 935
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by colton peterson:
the G = g line is to set a class wide graphics variable so that other methods may call draw() on rabbits and other objects and it is disposed when it is done.


Don't do that. Instead, keep track of what needs to be painted using
variables (or by drawing onto a BufferedImage) and do the actual
painting in the paintComponent() method.

Drawing with G outside of paintComponent() may be working for you,
but there's no guarantee it will work in other environments. Also, you
won't be able to repaint the content asynchronously when it is needed
(such as when an obscuring window vanishes).

I will try what he said. just call

g.setColor();

before calling draw() right?


Yes, but specify a (non-green) color, for example: g.setColor(Color.BLACK)

and paintIcon(); does nothing more than pass the graphics object up to the paintIcon() found in ImageIcon
If that's true then g.setColor() won't do anything. Are you sure that
the ImageIcon exists and has non-green non-transparent regions?
[ April 05, 2008: Message edited by: Brian Cole ]
 
colton peterson
Ranch Hand
Posts: 97
Linux Python VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes. I changed it a little bit and some of the graphics code half-works. This program was sort of a rush job and I will probably start over on it anyway just because it is not done very well.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!