0
我正在製作格鬥遊戲,玩家將選擇其類。我怎麼說如果(玩家選擇戰士)然後(等等)與我的代碼?如果語句和垂直按鈕
import java.awt.GridLayout;
import javax.swing.*;
public class ButtonTest {
static JDialog dialog;
public static void main(String[] args) {
JDialog dialog = null;
JOptionPane optionPane = new JOptionPane();
optionPane.setMessage("Choose Your Class!");
optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(3,1));
String[] buttonTxt = {"Warrior","Battlemage","Tank","Archer","Kitty"};
JButton[] buttons = new JButton[buttonTxt.length];
for (int i = 0; i < buttonTxt.length; i++)
{
buttons[i] = new JButton(buttonTxt[i]);
panel.add(buttons[i]);
}
optionPane.setOptionType(JOptionPane.DEFAULT_OPTION);
optionPane.add(panel);
dialog = optionPane.createDialog(null, "Icon/Text Button");
dialog.setVisible(true);
}
}
什麼實際上是你的問題? – Tony