rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*;
public class Opdracht14_11 extends Applet {
Lichtkrant lichtkrant;
public void start() {
if ( lichtkrant == null ) {
lichtkrant = new Lichtkrant(this);
lichtkrant.start();
}
}
}
class Lichtkrant extends Thread {
private int x = 0;
private int y = 10;
private String s = new String("Lichtkrant");
private Image buffer;
private Applet applet;
private int appletBreedte, appletHoogte;
private Graphics g, gB;
public Lichtkrant(Applet applet) {
this.applet = applet;
g = applet.getGraphics();
appletBreedte = applet.getSize().width;
appletHoogte = applet.getSize().height;
buffer = applet.createImage(appletBreedte, appletHoogte);
gB = buffer.getGraphics();
}
public void run() {
while(true) {
gB.drawString(s, x, y);
g.drawImage(buffer,0,0,applet);
slaap(2000);
x += 10;
if ( x == appletBreedte) {
x = 0;
}
gB.setColor(applet.getBackground());
gB.fillRect(0,0,appletBreedte, appletHoogte);
}
}
private void slaap(int millisec) {
try {
Thread.sleep(millisec);
}
catch (Exception e) {
// TODO: handle exception
}
}
}