Thread View: pl.comp.lang.java
4 messages
4 total messages
Started by MaciekL
Thu, 04 Aug 2011 19:08
java.awt.Frame - How to repaint without background update
Author: MaciekL
Date: Thu, 04 Aug 2011 19:08
Date: Thu, 04 Aug 2011 19:08
62 lines
2410 bytes
2410 bytes
Witam,
probuje zrobic bardzo prosta rzecz, miec BufferedImage, ktory
ma w sobie juz narysowany obrazek.
Podczas operacji repaint, ten obrazek powinien sie rysowac bezposrednio
w oknie (juz bez dodatkowego renderingu).
Rzecz wygladajaca na banalna, ale nie do konca dziala.
Otoz podczas "repaint" mruga mi okno, tak jakby przed wywolaniem
paint(...) bylo rysowane tlo.
Zastosowanie javax.swing.JFrame rozwiazuje problem,
przy czym ja chce uzyskac ten efekt bez swinga.
Czego brakuje ponizszemu programowi, zeby to przerysowawanie
bylo plynne (bez rysowania tla) ?
/*--::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]-------------------------------------------------*/
Pozdrawiam
--
Maciek
Re: java.awt.Frame - How to repaint without background update
Author: Mariusz Pieniążek
Date: Tue, 09 Aug 2011 14:11
Date: Tue, 09 Aug 2011 14:11
1 lines
925 bytes
925 bytes
A nie możesz skorzystać z Javy 2D?
Re: java.awt.Frame - How to repaint without background update
Author: Mariusz Pieniążek
Date: Tue, 09 Aug 2011 14:13
Date: Tue, 09 Aug 2011 14:13
3 lines
1067 bytes
1067 bytes
Albo z BufferStrategy (jak zostało już wspomniane kilka postów wyżej) and BufferCapabilities http://download.oracle.com/javase/tutorial/extra/fullscreen/bufferstrategy.html
Re: java.awt.Frame - How to repaint without background update
Author: MaciekL
Date: Tue, 09 Aug 2011 15:03
Date: Tue, 09 Aug 2011 15:03
9 lines
1011 bytes
1011 bytes
Znalezione rozwiazanie:
Dodanie metody 'update' powoduje, ze Backround nie jest przerysowywane
/***/
public void update(Graphics g) { paint(g); }
/***/
Maciek
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads