0

I am trying to make a world cup 2018 program that gives the percentages and choices for each team involved. I have figured out all the math and everything that goes with it, but i am having trouble finding out how to get the selection from one drop down menu change the choices for the next one and so on for the 4 groups. I have looked for information on this site and others, but because I am sorta new to java it isn't very easy for me to figure out what to do.

I have included my code below, with the four drop down menus, and would like to know how depending on the choice you make in the first group will give the proper choices in the 2nd group and so on...

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.BoxLayout; 
import java.awt.Component; 

public class  Worldcup {

public static void main(String[] args) {

    JFrame frame = new JFrame("A Simple GUI");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setLocation(430, 100);

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    frame.add(panel);

    //POT 1

    JLabel lbl = new JLabel("Select one of the possible choices and click OK");
    lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(lbl);

    String[] choices = { "Russia", "Germany", "France", "Portugal",
                         "Belgium", "Poland","Brazil", "Argentina"};

    final JComboBox<String> cb = new JComboBox<String>(choices);

    cb.setMaximumSize(cb.getPreferredSize());
    cb.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(cb);

    JButton btn = new JButton("OK");
    btn.setAlignmentX(Component.CENTER_ALIGNMENT); 
    panel.add(btn);
  frame.setVisible(true); 


// POT 2

JLabel lbl2 = new JLabel("Select one of the possible choices and click OK");
    lbl2.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(lbl2);

    String[] choices2 = { "Spain", "Switzerland", "England", "Croatia",
                         "Peru", "Colombia","Uruguay", "Mexico"};

    final JComboBox<String> cb2 = new JComboBox<String>(choices2);

    cb2.setMaximumSize(cb2.getPreferredSize()); 
    cb2.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(cb2);

    JButton btn2 = new JButton("OK");
    btn2.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(btn2);
  frame.setVisible(true); 

// POT 3

JLabel lbl3 = new JLabel("Select one of the possible choices and click OK");
    lbl3.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(lbl3);

    String[] choices3 = { "Denmark", "Iceland", "Sweden", "Costa Rica",
                         "Senegal", "Egypt","Tunisia", "IRAN"};

    final JComboBox<String> cb3 = new JComboBox<String>(choices3);

    cb3.setMaximumSize(cb3.getPreferredSize());
    cb3.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(cb3);

    JButton btn3 = new JButton("OK");
    btn3.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(btn3);
  frame.setVisible(true); 

// POT 4

JLabel lbl4 = new JLabel("Select one of the possible choices and click OK");
    lbl4.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(lbl4);

    String[] choices4 = { "Serbia", "Nigeria", "Morocco", "Australia",
                         "Japan", "South Korea","Crappy Arabia", "Panama"};

    final JComboBox<String> cb4 = new JComboBox<String>(choices4);

    cb4.setMaximumSize(cb4.getPreferredSize()); 
    cb4.setAlignmentX(Component.CENTER_ALIGNMENT);
    panel.add(cb4);

    JButton btn4 = new JButton("OK");
    btn4.setAlignmentX(Component.CENTER_ALIGNMENT); 
    panel.add(btn4);
  frame.setVisible(true); 

    }
}
Brow
  • 73
  • 1
  • 12

1 Answers1

0

You'll need to use events and listeners.

Check this other post it might help.

Fidyle
  • 1
  • 3