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 があることがわかりますが、メソッドにスロー IOException を追加すると、次のように表示されます:
エラー: テーブルの init() はアプレットの 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 に答える