import javax.swing.*;
public class MainP2 {
public MainP2() {
JOptionPane.showMessageDialog(
null,
"Hi welcome to my square Pyramid calculator." + "\nPress Ok to begin.",
"CIS 2235",
JOptionPane.PLAIN_MESSAGE
);
String[] possibilities = {
"adjust height",
"adjust baselength",
"adjust height and baselength",
"exit"
};
String s = (String)JOptionPane.showInputDialog(
null,
"Choose one",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
possibilities[0]
);
//-----here's the problem with the code, am i calling it wrong?
if(possibilities.equals(possibilities[0])){
String myString = JOptionPane.showInputDialog(null,"Please enter height: ");
}
}
public static void main (String[] args) {
MainP2 app = new MainP2();
}
}
我正在構建一個平方金字塔計算器,並從頭開始編寫所有代碼,但我似乎遇到了我的第一個問題。我給用戶一個歡迎信息,然後給他們一個下拉菜單,詢問他們想爲金字塔「調整」什麼。他們可以調整的四個選項是金字塔的height
,baselength
,height
和baselength
,或者他們可以退出。現在,無論他們選擇什麼選項(除了退出選項),都會彈出一個輸入對話框,要求輸入他們選擇的新值/值。下拉菜單不能按預期工作
我剛剛試過第一個選項只是爲了看看它的工作原理,但沒有運氣。每當我點擊索引爲0的調整高度時,程序就結束並忽略我的if語句,即如果選項索引爲0,則會彈出一個JOptionPane
輸入對話框。
我在做什麼錯?
請通過在代碼中使用一些縮進開始,所以我們可以很容易地閱讀。 –