M
MaciekL
Hi,
I'm trying to create simple application with BufferedImage that already
contains some graphical content.
During "repaint" operation, created image should be
redrawn on the screen (without additional graphics functions).
It seems to be easy, but there is something wrong.
During "repaint" operation the window "blinks". It seems that
'background' is displayed before image is drawn.
"javax.swing.JFrame" solves the issue, but I would like to
solve this with basic "java.awt.Frame".
Following application demonstartes the issue.
What should be added to this program to avoid backround repainting ?
/*--::BEG::--[TestApp.java]-------------------------------------------------*/
import java.awt.*;
import java.awt.image.*;
public class TestApp extends Frame implements Runnable
{
BufferedImage img = new BufferedImage(640, 480,
BufferedImage.TYPE_INT_RGB);
public TestApp()
{
Graphics g = img.getGraphics();
g.setColor(Color.RED);
g.drawRect(0, 0, img.getWidth() - 1, img.getHeight() - 1);
g.setColor(Color.BLUE);
g.fillRect(1, 1, img.getWidth() - 2, img.getHeight() - 2);
(new Thread(this)).start();
}
public void run()
{
while (true)
{
try { Thread.sleep(100); }
catch (Exception e) { }
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(img, 50, 50, this);
}
public static void main(String [] args)
{
Frame frame = new TestApp();
frame.setSize(740, 580);
frame.setLocation(50, 50);
frame.setVisible(true);
}
}
/*--::EOF::--[TestApp.java]-------------------------------------------------*/
Regards
I'm trying to create simple application with BufferedImage that already
contains some graphical content.
During "repaint" operation, created image should be
redrawn on the screen (without additional graphics functions).
It seems to be easy, but there is something wrong.
During "repaint" operation the window "blinks". It seems that
'background' is displayed before image is drawn.
"javax.swing.JFrame" solves the issue, but I would like to
solve this with basic "java.awt.Frame".
Following application demonstartes the issue.
What should be added to this program to avoid backround repainting ?
/*--::BEG::--[TestApp.java]-------------------------------------------------*/
import java.awt.*;
import java.awt.image.*;
public class TestApp extends Frame implements Runnable
{
BufferedImage img = new BufferedImage(640, 480,
BufferedImage.TYPE_INT_RGB);
public TestApp()
{
Graphics g = img.getGraphics();
g.setColor(Color.RED);
g.drawRect(0, 0, img.getWidth() - 1, img.getHeight() - 1);
g.setColor(Color.BLUE);
g.fillRect(1, 1, img.getWidth() - 2, img.getHeight() - 2);
(new Thread(this)).start();
}
public void run()
{
while (true)
{
try { Thread.sleep(100); }
catch (Exception e) { }
repaint();
}
}
public void paint(Graphics g)
{
g.drawImage(img, 50, 50, this);
}
public static void main(String [] args)
{
Frame frame = new TestApp();
frame.setSize(740, 580);
frame.setLocation(50, 50);
frame.setVisible(true);
}
}
/*--::EOF::--[TestApp.java]-------------------------------------------------*/
Regards