如何同时打开两个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
我有两个对象 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