Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown menu not working as expected

Tags:

java

swing

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();
}
}

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?

like image 860
John Acosta Avatar asked Aug 28 '26 00:08

John Acosta


2 Answers

I think you mean:

if(s.equals(possibilities[0]))
like image 69
Russell Zahniser Avatar answered Aug 30 '26 14:08

Russell Zahniser


Replace the following:

if(possibilities.equals(possibilities[0])){

With:

if(s.equals(possibilities[0])){
like image 27
David Mathias Avatar answered Aug 30 '26 14:08

David Mathias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!