hi all, i am building a squared pyramid calculator and writing all the code from scratch, but I seem to have run into my first problem though. i am giving the user a welcome message and then giving them a dropdown menu asking them what they want to "adjust" for the pyramid. the four options they can adjust are the height, baselength, height and baselength of the pyramid, or they can just exit. now from here whatever option they choose( except for the exit option) an input dialog will pop up asking to enter the new value/values for whatever they chose. I've just tried the first option just to see if it works but with no luck whenever i click on adjust height which is indexed at 0 the program just ends and ignores my if statement which is if the option is indexed at 0 then a joptionpane input dialog should pop up what am i doing wrong?

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]);

//////////////heres 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();

    }
}

Recommended Answers

All 6 Replies

The code compares two variables that haven't been changed. Where is the data that user selected?

in the possibilities array right?

Where is the data from the user's selection? He did not change the contents of the possibilities array.

I'm sorry but i'm not exactly sure what you're asking me. I'm just trying to get a joptionpane input dialog box to pop up when the user selects any of the options from the dropdown menu and a goodbye if he/she selects the exit option for now.

when the user selects any of the options from the dropdown menu

I was asking: where in the code does it get what the user selected?

you are comparing an array of Strings against a single String. looks like very bad coding.

 if(possibilities.equals(possibilities[0])){
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.