Can JPanel's paint() use different Graphics2D objects?
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I've got NormPanel here :
after I have called DblBuffClass.init() then DblBuffClass is ready to show it's own shapes
is it possible at all for paint() to optionally go over to another class and
have it populate the Graphics2D object with different things and then
have paint() add a few more things?
This thing now doesn't work
after I have called DblBuffClass.init() then DblBuffClass is ready to show it's own shapes
is it possible at all for paint() to optionally go over to another class and
have it populate the Graphics2D object with different things and then
have paint() add a few more things?
This thing now doesn't work
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
for Swing components you should be using paintComponent(..) instead of paint(..)
not sure exactly what you're trying to do, but doing stuff inside paintComponent()
is generally not good, due to the number of times the method is called, unless that's what you want.
to see how often it is called, run this, then drag the frame wider or smaller and watch the counter go.
not sure exactly what you're trying to do, but doing stuff inside paintComponent()
is generally not good, due to the number of times the method is called, unless that's what you want.
to see how often it is called, run this, then drag the frame wider or smaller and watch the counter go.
Dave Elwood
Ranch Hand
Posts: 84
posted 13 years ago
I'm trying to invoke double-buffering on a part-time basis on a JPanel.
I've succeeded in invoking additional painting on a part-time basis by doing this in my NormPanel :
if blPaintBoom is false then I haven't invoked my extra little animation
otherwise I invoke blastPainter.paintBoom(g), where I add some growing concentric circles (an explosion) with a loop
and repaint() routine and when I'm done I put blPaintBoom back to false
using paint() instead of paintComponent() along with the use of an update() override was suggested in a description of double buffering.
doing this hasn't caused any bad things to happen.
I'd like this snippet of code in paintBoom to employ double-buffering in order to
smooth out my animation. However getting it back into NormPanel.paintComponent() is
difficult since I'm not sure of the true nature of Graphics2D, Graphics and Image objects.
I'm afraid the code you showed me doesn't employ double-buffering at all.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
not sure exactly what you're trying to do
I'm trying to invoke double-buffering on a part-time basis on a JPanel.
I've succeeded in invoking additional painting on a part-time basis by doing this in my NormPanel :
if blPaintBoom is false then I haven't invoked my extra little animation
otherwise I invoke blastPainter.paintBoom(g), where I add some growing concentric circles (an explosion) with a loop
and repaint() routine and when I'm done I put blPaintBoom back to false
using paint() instead of paintComponent() along with the use of an update() override was suggested in a description of double buffering.
doing this hasn't caused any bad things to happen.
I'd like this snippet of code in paintBoom to employ double-buffering in order to
smooth out my animation. However getting it back into NormPanel.paintComponent() is
difficult since I'm not sure of the true nature of Graphics2D, Graphics and Image objects.
I'm afraid the code you showed me doesn't employ double-buffering at all.
posted 13 years ago
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
for what it's worth, and without reading your code.
you can have more than one Graphics in your paintComponent()
you can cast the one the method was given to a Graphics2D or create a new Graphics2D
as for double buffering, i am no expert, but i think swing does some of that now for you.
you can have more than one Graphics in your paintComponent()
you can cast the one the method was given to a Graphics2D or create a new Graphics2D
as for double buffering, i am no expert, but i think swing does some of that now for you.
SCJP
Visit my download page
posted 13 years ago
-
2 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Don't override the update() method. That is done in AWT painting, NOT Swing painting.
Dave Elwood
Ranch Hand
Posts: 84
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks Rob Camick, Trying to imagine the difference between AWT and Swing is hard for me. I'm slow.
To Randall : >>you can have more than one Graphics in your paintComponent()
Do you mean I can do this :
and both will show up?
I'll try that out. Thanks for the tip.
To Randall : >>you can have more than one Graphics in your paintComponent()
Do you mean I can do this :
and both will show up?
I'll try that out. Thanks for the tip.
Rob Camick
Rancher
Posts: 3325
32
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'm not sure what you are trying to do. Swing is double buffered by default so there is no need to worry about double buffering.
You can't just create a Graphics objects and do painting with it. Generally you just use the Graphics objects that is passed to a paintCompnent() method. However if you want to change a lot of the properties of the Graphics object you can use the Graphics.create() method to get a copy of the original Graphics, just make sure you dispose of the new Graphics objects when you are finished with it.
You can't just create a Graphics objects and do painting with it. Generally you just use the Graphics objects that is passed to a paintCompnent() method. However if you want to change a lot of the properties of the Graphics object you can use the Graphics.create() method to get a copy of the original Graphics, just make sure you dispose of the new Graphics objects when you are finished with it.
Michael Dunn
Ranch Hand
Posts: 4632
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
if you're just trying to create a 'boom' effect, something like this might be all you need to do.
run it, then click the 'boom' button.
run it, then click the 'boom' button.
Dave Elwood
Ranch Hand
Posts: 84
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That's interesting. I like the idea of the anon inner class for the timer.
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The anonymous inner class is an ActionListener passed to the Timer's constructor.
The Timer is just a javax.swing.Timer --not an anonymous inner class.
The Timer is just a javax.swing.Timer --not an anonymous inner class.
luck, db
There are no new questions, but there may be new answers.
| Paper jam tastes about as you would expect. Try some on this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











