0
我有一個遊戲應用程序,我需要輸入一個文件,並在文件解析後,我可以點擊一個按鈕開始和遊戲(定位在中心面板)開始。我有一個頂部面板(fileBrowserPanel,我瀏覽該文件的文件系統),該面板上有Browse,Start按鈕。當我點擊開始時,遊戲應該開始運行。這裏是我的代碼:GUI Panel ActionListener
public BallWorld()
{
setLayout(new BorderLayout());
//File browser for INI file
JPanel fileBrowserPanel = new fileBrowserPanel();
add(fileBrowserPanel,BorderLayout.NORTH);
fileBrowserPanel.add(jbtStart);
//Ball container
if(filePathField.getText().equals(" "))
{
JOptionPane.showMessageDialog(null, "Please input the XML file","Information", JOptionPane.INFORMATION_MESSAGE);
}
jbtStart.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent e)
{
if(filePathField.getText().equals(" "))
{
JOptionPane.showMessageDialog(null, "Please input the XML file","Information", JOptionPane.INFORMATION_MESSAGE);
}
else
{
JPanel ballContainer = new BallContainer(filePathField.getText());
add(ballContainer,BorderLayout.CENTER);
}
}
});
}
的問題是,只有當我調整,在中央面板遊戲顯示的窗口。我無法弄清楚。有什麼建議麼?
嘿,謝謝,這是訣竅!你能解釋validate()函數嗎?謝謝〜 – user1719821
據我所知,它就像是一個網頁的刷新。它迫使面板再次佈局本身及其子組件 – eytanfb
Alrite,非常感謝!我會在谷歌上多一點。 – user1719821