[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Speedup some java code
Hi!
There are three links which can be useful:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/doublebuf.html
http://java.sun.com/docs/books/tutorial/2d/images/doublebuffering.html
And maybe the code example from here will help:
http://www.yourek.org/grafika/doubleBuffering.html
Best of luck
Jerzy Puchala
On 5 Nov 2002, cfowler wrote:
> Hello. I have some awt 2D code that is blinking in the JPanel. I need
> to speed it up if possible.
>
> Can someone who knows see an ability in this code to speed up the
> repaint? This is coming from a class that extends JPanel and at one
> time extended Canvas from awt.
>
>
>
> public void update(Graphics g) {
> int j,beg; boolean ok;
> g.setFont(PTFont);
> //draw lines
> for (int i=0;i<lines;i++) {
> if (lineRedraw[i] == true) {
> lineRedraw[i] = false;
> j=0;
> Color fg,bg;
> while (j < columns-1) {
> fg=screenfg[i][j];
> bg=screenbg[i][j];
> beg=j;ok=true;
> while (++j < columns && ok)
> if (fg!=screenfg[i][j] || bg!=screenbg[i][j]) ok = false;
> if (ok==false) j--;
> g.setColor(bg);
> g.fillRect(3+beg*charOffset, 2+i*lineOffset, charOffset*(j-beg),
> lineOffset);
> g.setColor(fg);
> g.drawChars(screen[i], beg, j-beg, 3+beg*charOffset,
> topOffset+i*lineOffset);
> }
> }
> }
> //draw cursor
> g.setColor(new Color(screenbg[yloc][xloc].getRGB() ^ 0xFFFFFF));
> g.fillRect(3+xloc*charOffset, 2+yloc*lineOffset, charOffset,
> lineOffset);
> g.setColor(new Color(screenfg[yloc][xloc].getRGB() ^ 0xFFFFFF));
> g.drawChars(screen[yloc], xloc, 1, 3+xloc*charOffset,
> topOffset+yloc*lineOffset);
> lineRedraw[yloc]=true;
> }
>
> public void paint(Graphics g) {
> for (int i=0;i<lines;i++) lineRedraw[i] = true;
> g.setColor(d_bgcolor);
> g.fillRect(1,1,PTWidth-1,PTHeight-1);
> g.setColor(d_fgcolor);
> g.drawRect(0,0,PTWidth,PTHeight);
> update (g);
> }
>
>
--
+--------------------------------+
| Jerzy Puchala |
+--------------------------------+
| jerzypuc@scdi.com |
+--------------------------------+