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();
}
}
四角錐計算機を作成し、すべてのコードを最初から作成していますが、最初の問題が発生したようです。ユーザーにウェルカムメッセージを表示してから、ピラミッドに合わせて「調整」する内容を尋ねるドロップダウンメニューを表示します。調整できる4つのオプションはheight
、ピラミッドの、、、およびです。または、そのまま終了することもできbaselength
ますheight
。baselength
ここから、選択したオプション(終了オプションを除く)を選択すると、入力ダイアログがポップアップ表示され、選択したオプションの新しい値を入力するように求められます。
最初のオプションを試してみましたが、うまくいくかどうかを確認しましたが、うまくいきませんでした。0でインデックス付けされている高さ調整をクリックすると、プログラムは終了し、オプションが0でインデックス付けされている場合のifステートメントを無視し、JOptionPane
入力ダイアログがポップアップ表示されます。
私は何が間違っているのですか?