B
Bob
Hi there,
after seeking advice in this group, I wrote a small Swing component
that displays an image, assigned to it by another class.
I was amazed on how easy this was. Below is the simplified code.
Since the Component is automatically an ImageObserver, the picture on
the screen updates, when the image object is changed.
However, I am updating the image quite quickly in a simulation loop and
the update of the screen is not enough (or so fast, that it cannot be
seen). Is there any method that I can call in the simulation loop which
will trigger an update of the screen?
Furthermore, the paint() method doesn't seem to be called often enough.
For example, after the component has been hidden by a menu or
something, it won't be repainted. What's the point of repaint, if there
is no Graphics provided to paint on?
thanks in advance for any help
Bob
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
public class ImageDisplay extends Component
{
public Image image;
@Override
public void paint(Graphics g)
{
// super.paint(g);
if (image!=null)
{
g.drawImage(image, 0, 0, this);
}
} // paint()
} // class
after seeking advice in this group, I wrote a small Swing component
that displays an image, assigned to it by another class.
I was amazed on how easy this was. Below is the simplified code.
Since the Component is automatically an ImageObserver, the picture on
the screen updates, when the image object is changed.
However, I am updating the image quite quickly in a simulation loop and
the update of the screen is not enough (or so fast, that it cannot be
seen). Is there any method that I can call in the simulation loop which
will trigger an update of the screen?
Furthermore, the paint() method doesn't seem to be called often enough.
For example, after the component has been hidden by a menu or
something, it won't be repainted. What's the point of repaint, if there
is no Graphics provided to paint on?
thanks in advance for any help
Bob
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
public class ImageDisplay extends Component
{
public Image image;
@Override
public void paint(Graphics g)
{
// super.paint(g);
if (image!=null)
{
g.drawImage(image, 0, 0, this);
}
} // paint()
} // class