MarcGerrish
Programmer
Hopefully someone will know why I can't get this to work properly, as I've been trying to suss it outy myself for the last four hours and am not getting anywhere.
It's a simple program to display two balls and a 'passage' (three rectangles at this stage) on a 'playingfield'
I know that the commands causing the runtine errors are the "blueball.paint(g)" "redball.paint(g)" and "thepassage.paint(g)" Everything else works fine.
Any ideas anyone?
It's a simple program to display two balls and a 'passage' (three rectangles at this stage) on a 'playingfield'
I know that the commands causing the runtine errors are the "blueball.paint(g)" "redball.paint(g)" and "thepassage.paint(g)" Everything else works fine.
Any ideas anyone?
Code:
*snip*
class ball
{
Rectangle location;
Color ballcolor=Color.blue;
ball(int x, int y, int wh)
{
location=new Rectangle(x,y,wh,wh);
}
public void paint(Graphics g)
{
g.setColor(ballcolor);
g.fillOval(location.x,location.y,location.width,location.height);
}
}
*snip 'class passage' - same as 'class ball'
class field extends Frame implements Runnable
{
Thread runner;
ball blueball,redball;
passage thepassage;
int screenx=600;
int screeny=400;
int divx=20;
int passagey=100;
Color bgcolor=new Color(255,128,0);
Color divcolor=Color.black;
field()
{
super("Demon Balls");
setSize(screenx,screeny);
setBackground(bgcolor);
ball blueball=new ball(100,175,50);
ball redball=new ball(250,175,50);
passage thepassage=new passage(((screenx-divx)/2),((screeny-passagey)/2),divx,passagey);
show();
runner=new Thread(this);
runner.start();
}
public void drawbg(Graphics g)
{
g.setColor(bgcolor);
g.drawRect(0,0,screenx,screeny);
g.setColor(divcolor);
g.fillRect(((screenx-divx)/2),0,divx,screeny);
}
public void paint(Graphics g)
{
drawbg(g);
blueball.paint(g);
redball.paint(g);
thepassage.paint(g);
}
public void run()
{
repaint();
try{Thread.sleep(500);}
catch(InterruptedException e){}
}
}
public class demonballs
{
public static void main(String args[])
{
field playingfield;
playingfield=new field();
playingfield.show();
}
}