-2

setVisible メソッドを宣言する JFrame クラスがどのクラスを継承するかについて、Java API を調査するという宿題に取り組んでいます。次に、そのクラスをインポートし、main メソッドのコードを変更して、frame 変数が JFrame 型ではなくその型として宣言されるようにします。

setVisible メソッド JWindow を宣言しているクラスを見つけましたが、コードを変更しようとすると実行されないので、助けていただければ幸いです。

import javax.swing.JFrame;
import javax.swing.JWindow;


//JFrame is inherited from java.awt.Frame class
//setVisible is declared by the java.awt.Window class
public class ProductFrame extends JWindow
{
    public ProductFrame()
    {
        // all of these methods are available because
        // they are inherited from the JFrame class
        // and its superclasses

        this.setTitle("Product");
        this.setSize(200, 200);
        this.setLocation(10, 10);
        this.setResizable(false);

        // this method uses a field that's available
        // because it's inherited
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public static void main(String[] args)
    {
        // this creates an instance of the ProductFrame
        JWindow frame = new ProductFrame();

        // this displays the frame
        frame.setVisible(true);
    }
}
4

2 に答える 2

1

あなたのクラスProductFrameJFrame直接拡張されるので、あなたは言うことができません

JWindow frame = new ProductFrame();

が拡張されないため、JWindow参照を aに設定することは無効です。そのようにクラス宣言を変更する必要があります。ProductFrameProductFrameJWindow

于 2014-12-11T23:33:58.523 に答える