-
blank space over applet
Hi! ok so im making an applet and there is a blank space i didnt even put there! can u guys help??
Code:
import java.awt.*;
import java.applet.Applet;
public class Project2 extends Applet {
private int disfromfinh = 50;
private int disfromfint = 50;
private int xh = 5;
private int xt = 5;
private int a1 = 5;
private int a2 = 5;
private Image hare;
private Image tortoise;
public void init() {
hare = getImage( getDocumentBase(), "hare.gif" );
tortoise = getImage( getDocumentBase(), "tortoise.gif" );
}
public void paint(Graphics screen) {
setBackground( Color.green );
screen.drawLine( 0, 115, 1133, 115);
screen.drawLine( 1133, 0, 1133, 215);
Font f = new Font( "Tahoma", Font.BOLD, 30 );
screen.setFont( f );
screen.setColor( new Color( 240, 15, 179 ));
screen.drawString( "F", 1150, 40);
screen.drawString( "I", 1150, 70);
screen.drawString( "N", 1150, 100);
screen.drawString( "I", 1150, 130);
screen.drawString( "S", 1150, 160);
screen.drawString( "H", 1150, 190);
int yh = xh + 101;
int yt = xt + 121;
screen.clearRect(xh, 5, yh, 106);
screen.drawImage( hare, a1 , 5, this);
screen.clearRect(xt, 120, yt, 195);
screen.drawImage( tortoise, a2 , 120, this);
}
public void start() {
new Thread (
new Runnable() {
public void run() {
race();
}
}
).start();
}
public void race() {
while ( disfromfinh > 0 & disfromfint > 0 ) {
int moveh = (int)(Math.random() * 10) + 1;
int movet = (int)(Math.random() * 10) + 1;
//For the turtle
if (movet == 1 | movet == 2 | movet == 3 | movet == 4 | movet == 5) {
a2 = xt + 60;
disfromfint -= 3;
}
else if (movet == 6 | movet == 7 | movet == 8) {
a2 = xt + 20;
disfromfint -= 1;
}
else {
a2 = xt - 120;
disfromfint += 6;
if (disfromfint > 50) {
a2 = 5;
disfromfint = 50;
}
}
// For the hare
if (moveh == 1 | moveh == 2) {
a1 = xh + 180;
disfromfinh -= 9;
}
else if (moveh == 3 | moveh == 4 | moveh == 5) {
a1 = xh + 20;
disfromfinh -= 1;
}
else if (moveh == 6) {
a1 = xh - 240;
disfromfinh += 12;
if (disfromfinh > 50) {
a1 = 5;
disfromfinh = 50;
}
}
else if (moveh == 7 | moveh == 8) {
a1 = xh - 40;
disfromfinh += 2;
if (disfromfinh > 50) {
a1 = 5;
disfromfinh = 50;
}
}
else {
a1 = a1;
disfromfinh = disfromfinh;
}
delay(500);
repaint();
xh = a1;
xt = a2;
}
}
public void delay (int milliseconds){
try{
Thread.sleep(milliseconds);
}
catch (InterruptedException e){
System.out.println("Problem in thread sleep");
}
}
}