Hey guys I was trying to run a Applet from netbeans 6.9.1
My code has no error when i compile, but when i run the file I received an error which says "start applet not initialized".
what does that mean? thanks
There are 4 classes in my code, which is "Ball", "BallWorld", "Direction" and "Position". Class "Direction" and "Position" has no other implementation except integer variables only, the "Ball" class contains the method and attribute for the Ball object in the "BallWorld" class. The Applet i run is on "BallWorld" class.Below is my code:
//Ball class
import java.awt.*;
public class Ball{
private Color c;
private int s; //size
// private int x, y; //Position
// private int dx, dy; //Direction
Direction d;
BallWorld bw;
Position p;
public Ball(Color col, int posx, int posy, int size, int movx, int movy)
{
c = col;
p.x = posx;
p.y = posy;
s = size;
d.dx = movx;
d.dy = movy;
}
public void move()
{
// x+= dx; //Update x, y
// y+= dy;
bw.Bounce(p, s, d);
// if(x < BallWorld.left)//Hit the left boundary
// {
// x = BallWorld.left;
// dx = -dx;
// }
//complete the code including checks for other boundaries
// if(x > BallWorld.right - s)
// {
// x = BallWorld.right - s;
// dx = -dx;
// }
// if(y > BallWorld.bottom - s)
// {
// y = BallWorld.bottom - s;
// dy = -dy;
// }
// if(y < BallWorld.top)
// {
// y = BallWorld.top;
// dy = -dy;
// }
}
public void draw(Graphics g)
{
move();
g.setColor(c);
g.fillOval(p.x, p.y, s, s);
}
}
//BallWorld class
import java.awt.*;
import java.applet.*;
public class BallWorld extends Applet {
public static int left = 50, right = 450, top = 50, bottom = 550;
Ball b1 = new Ball(Color.BLUE, 50, 70, 10, 10, 10);
Ball b = new Ball(Color.RED, 50, 80, 10, 11, 11);
Ball b2 = new Ball(Color.BLUE, 55, 105, 15, 13, 13);
public void paint(Graphics g)
{
g.setColor(Color.GREEN);
g.drawRect(left, top, right - left, bottom - top);
b.draw(g); //draw ball
b1.draw(g);
b2.draw(g);
slow(100); //slow the display
repaint();
}
public void Bounce(Position p, int s, Direction d){
p.x+= d.dx; //Update x, y
p.y+= d.dy;
if(p.x < BallWorld.left)//Hit the left boundary
{
p.x = BallWorld.left;
d.dx = -d.dx;
}
// complete the code including checks for other boundaries
if(p.x > BallWorld.right - s)
{
p.x = BallWorld.right - s;
d.dx = -d.dx;
}
if(p.y > BallWorld.bottom - s)
{
p.y = BallWorld.bottom - s;
d.dy = -d.dy;
}
if(p.y < top)
{
p.y = BallWorld.top;
d.dy = -d.dy;
}
}
public void slow(int t)
{
try{
Thread.sleep(t);
}catch(Exception e){}
}
}
//Position class
public class Position {
int x;
int y;
}
//Direction class
public class Direction {
int dx;
int dy;
}