我不知道爲什麼我的代碼無法正常工作。當我試圖打開窗口(BazaDanych)時,只有window2(ZmienBaze)出現,我不知道爲什麼。 Window(BazaDanych)根本不開放。也許你能幫助我嗎?Jframe的東西壞了[我嘗試打開窗口1,但打開窗口2]
class GlowneMenu extends JFrame implements ActionListener
{
public GlowneMenu()
{
setTitle("Menu");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
...<not important just Menu stuff>
JMenu info = new JMenu("Info");
...<not important just JMenu and label stuff>
}
public void actionPerformed(ActionEvent e){
new BazaDanych().setVisible(true);
this.dispose();
new ZmienBaza().setVisible(true);
this.dispose();
}
public static void main(String[] args){new GlowneMenu().setVisible(true);}
}
class BazaDanych extends JFrame{
public BazaDanych()
{
setTitle("Baza danych");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(400,100);
...<not importent just this window stuff>
}
}
class ZmienBaza extends JFrame{
public ZmienBaza()
{
setTitle("Zmiana Bazy");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(400,100);
...<not importent just this window stuff>
}
}
我想通了,當我刪除這個:*我的代碼將正常工作,但只能到一個窗口。我怎樣才能以這種方式添加更多的窗口?
*new ZmienBaza().setVisible(true);
this.dispose();
1)爲了更好地幫助越早,張貼[SSCCE(http://sscce.org/)。 2)請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/a/9554657/418556) –