簡體   English   中英

如何同時打開兩個JFrame?

[英]How to open two JFrame at the same time?

我有兩個對象JFrame,當我從同一個類中調用它們時,第一個對象被打開,當它完成執行時,它將啟動另一個對象。 這是我第一次工作JFrame。

像馬丁提到的那樣嘗試一下。

/**
 * @author iGeeks
 * @date   2015-01-08
 */

package ly.gress.frames;

import javax.swing.JFrame;

public class TestTwoFrames implements Runnable{

    JFrame theFrame;


    public TestTwoFrames(JFrame f) {
        this.theFrame = f;
    }


    // Run two Frames in separate therads
    public static void main(String[] arguments) {
        JFrame f1 = new JFrame("f1 title");
        JFrame f2 = new JFrame("f2 title");

        Thread t1 = new Thread(new TestTwoFrames(f1));
        Thread t2 = new Thread(new TestTwoFrames(f2));

        t1.start();
        t2.start();
    }


    @Override
    public void run() {
        theFrame.setSize(200, 200);
        theFrame.setVisible(true);

        // Attention: This closes the app, and therefore both frames!
        theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

} // end class TestTwoFrames

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM