Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java.awt.Frame - How to repaint without background update

Reply
Thread Tools

java.awt.Frame - How to repaint without background update

 
 
MaciekL
Guest
Posts: n/a
 
      08-05-2011
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

--
Maciek
 
Reply With Quote
 
 
 
 
supercalifragilisticexpialadiamaticonormalizeringelimatisticantations
Guest
Posts: n/a
 
      08-05-2011
On 05/08/2011 7:15 AM, MaciekL wrote:
> 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".


You're getting bitten by java.awt.Frame's lack of double buffering. I'm
not sure there's any remotely easy solution other than using JFrame.

What is your reason for wanting to avoid JFrame?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: java.awt.Frame - How to repaint without background update MaciekL Java 2 08-05-2011 07:48 PM
repaint without flickering Georg Andersson Java 6 05-17-2004 07:30 PM
Need help: How to Repaint a User Control with Dynamic ASP Link Buttons RSB ASP .Net 0 04-28-2004 02:15 PM
treeview causes screen repaint every node clicked :( Jason Shohet ASP .Net 2 11-19-2003 02:42 PM



Advertisments