0

这是我的主要课程:

public class Table extends java.applet.Applet implements Runnable
{
    public void init()
    {
        Balla.addBall();
    }
}

这是巴拉方法:

public static void addBall()throws IOException
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }

现在我的问题来自我遵守它的时候。它告诉我在 init 方法中有一个未报告的 IOException,但是当我在该方法上添加 throws IOException 时它告诉我:
错误:Table 中的 init() 无法覆盖 Applet 中的 init()

我怎样才能解决这个问题和/或如何在不修改大部分内容的情况下解决这个问题?

4

1 回答 1

0

改变这个

public static void addBall()throws IOException
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }

public static void addBall()
    {
        Random generator = new Random();
        Ball b = new Ball(100,100,8,Color.blue,generator.nextInt(4)+1,generator.nextInt(4)+1);
        try
{
        FileWriter fw = new FileWriter("C:\\temp_Jon\\BallData.ballz",true);
        PrintWriter pw = new PrintWriter(fw,true);
        pw.print(b.getX()+" "+b.getY()+" "+b.getRadius()+" "+b.color+" "+b.speedX+" "+b.speedY);
        fw.close();
        pw.close();
    }
catch(Exception e)
{
}
}

看看它是否有效

于 2014-05-11T04:13:23.383 回答