我只是想知道这里是否有一个 JButton 选项:
if(RandomNrJeden <= 50)
{
JOptionPane.showMessageDialog(frameKontrastGame, "Eggs are not supposed to be green.");
JButton dialogOdp = new JButton();
}
else
{
JOptionPane.showMessageDialog(frameKontrastGame, "Eggs are not supposed to be red.");
}
然后只需输入: panel.add(dialogOdp); 外部?
这是整个代码:
final JButton continueGame = new JButton();
continueGame.setPreferredSize(new Dimension(1000, 30));
continueGame.setLocation(95, 45);
continueGame.setText("<html>Continue</html>");
continueGame.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent ev) {
panel.remove(continueGame);
SwingUtilities.updateComponentTreeUI(frameKontrastGame);
if(RandomNrJeden <= 50)
{
JOptionPane.showMessageDialog(frameKontrastGame, "Eggs are not supposed to be green.");
JButton dialogOdp = new JButton();
}
else
{
JOptionPane.showMessageDialog(frameKontrastGame, "Eggs are not supposed to be red.");
}
}});
//final JLabel im = new JLabel(new ImageIcon("kontrast_logo_2.png"));
//panel.add(im);
panel.add(dialogOdp);
panel.add(continueGame);
frameKontrastGame.getContentPane().add(panel);
frameKontrastGame.setLocationByPlatform(true);
}});