我正在为我的11年级计算机科学编写一个简单的程序,并且我的代码中不断出现失衡异常。 (见下面的代码)
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();
}
如果需要更多细节,请告诉我,是的,我确实删除了一些方法