I am writing a simple program for my grade 11 computer science and i keep getting an out of balance exception in my code. (see below for code)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class project10 extends Applet
implements ActionListener,KeyListener
{
int width=1000, height=800; // screen size
Image backbuffer;
Graphics backg;
Timer timer1;
int degrees = 0;
int shipx=40,shipy=800;
int difficulty=10;
int[] blockx =new int[9];
int[] blocky =new int[9];
int i;
for(i=0;i<=9;i++)
{
blockx[i]= (int)(Math.random()*1000+1);
blocky[i]= (int)(Math.random()*150+1);
}
public void init()
{
addKeyListener(this);
setSize(1000,800);
backbuffer = createImage( width, height );
backg = backbuffer.getGraphics();
backg.setColor( Color.white );
timer1 = new Timer(5, this);
}
public void start()
{
timer1.start();
}
public void stop()
{
timer1.stop();
}
public void destroy()
{
//System.exit(0);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == timer1)
{
backg.setColor(Color.white);
backg.drawRect(0,0,1000,1000);
backg.setColor(Color.black);
backg.fillRect(shipx,shipy,20,20);
for( i=0;i<=9;i++)
{
backg.drawRect(blockx[i],blocky[i],20,20);
}
repaint();
}
if anymore details are necessary just let me know and yes I did remove some methods