Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] How to do the fatest redraws in applets ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 GeertPoels   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 September 2000 - 08:17 PM

Hi, I''ve seen lots of different implementations on the drawing side of a (demo)-applet. Going from the usual override of the paint and repaint methods to defining an extra thread, some using a sleep, some putting all drawing code in the repaint, ... . I believe calling repaint() "en masse" doesn''t work with an applet since the browser''s repaintthread has a lower priority and may in some cases never reach the repaint. What''s the safest way to implement an applet that requires fast redrawing ? Are some optimisations recommended depending on the case (much maths) ? Tnx Geert

Sponsor:

#2 bobbin   Members   -  Reputation: 122

Like
Likes
Like

Posted 28 September 2000 - 11:30 PM


Well you can set a image up to act like a buffer screen (like the good old days of chain-x in 68 asm), then you can opt. & refine to your hart''s content..

take a look @ this code, it may give you some ideas (well it compiles with _my_ jdk 1.6

import java.applet.*;
import java.awt.image.*;
import java.awt.*;

public class DirectDraw extends Applet implements Runnable {
private DirectImage bitmap;
private Image bitImg;
private int xs, ys;
private int width, height;
private Thread ticker;
private boolean running = false;

public void init () {
width = getSize().width;
height = getSize().height;
bitmap = new DirectImage(width, height);
bitImg = createImage(bitmap);
}
public void paint (Graphics g) {
bitImg.flush();
g.drawImage(bitImg, 0, 0, null);
}
public void run () {
int off = 0;
while (running) {
waveForm(off += 4);
repaint();
try {
ticker.sleep(1000 / 30);
} catch (InterruptedException e) { ; }
}
}
public void start () {
if (ticker == null || !ticker.isAlive()) {
running = true;
ticker = new Thread(this);
ticker.setPriority(Thread.MIN_PRIORITY + 1);
ticker.start();
}
}
public void stop () {
running = false;
}
public void update (Graphics g) {
paint(g);
}
public void waveForm (int off) {
for (int ii = 0; ii < bitmap.pixels.length; ii++)
bitmap.pixels[ii] = 0xFF000000;
int base = (height >> 1);
double twoPI = Math.PI * 2;
double scale = (double) height * 0.75;
for (int x = 0; x < width; x++) {
double rad = ((x + off) * twoPI) / width;
int y = ((int) (Math.sin(rad) * scale) / 2) + base;
bitmap.pixels[y * bitmap.width + x] = 0xFFFFFFFF;
}
}
}




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS