0

私は最近 Java の学習を始めましたが、現在問題に直面しています。if ステートメントが完了すると、別のクラスの JFrame がポップアップするようにします。

だから私はこのようなものが欲しい:

if(...)
{
    //open the JFrame from the other class  
}

私の JFrame クラスは次のようになります。

import javax.swing.*;

public class Game {

    public static Display f = new Display();
    public static int w = 600;
    public static int h = 400;

    public static void main(String args[])
    {
        f.setSize(w, h);
        f.setResizable(true);
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setTitle("Frame Test");
    }
}

class Display extends JFrame
{

}
4

1 に答える 1

3

次のようなものが機能します。

if(...)
{
    //open the JFrame from the other class  
    OtherClass otherClass = new OtherClass();
    otherClass.setVisible(true);
}

また、コンストラクターで JFrames を初期化する必要があります。そうしないと、メイン メソッドが乱雑になります。

于 2013-11-13T17:50:25.960 に答える