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
输入对话框。
我在做什么错?
请通过在代码中使用一些缩进开始,所以我们可以很容易地阅读。 –