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();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在构建一个平方金字塔计算器并从头开始编写所有代码,但我似乎遇到了我的第一个问题.我正在给用户一个欢迎信息,然后给他们一个下拉菜单,询问他们想要"调整"金字塔的内容.他们可以调整的四个选项是height,baselength,height和baselength金字塔,或者他们可以退出.现在,无论他们选择哪种选项(退出选项除外),都会弹出一个输入对话框,要求输入他们选择的新值/值.
我刚刚尝试了第一个选项,看它是否有效,但没有运气.每当我点击调整高度时,索引为0,程序就会结束并忽略我的if语句,如果该选项被索引为0,那么JOptionPane就会弹出一个输入对话框.
我究竟做错了什么?