2017-11-18 9 views
0

私は関与する各チームのパーセンテージと選択肢を与えるワールドカップ2018プログラムを作ろうとしています。私はすべての数学とそれに伴うすべてを考え出しましたが、1つのドロップダウンメニューから選択を得る方法を見つけるのが難しいです。私はこのサイトや他のサイトの情報を探しましたが、私はJavaの新しいものですから、何をすべきか把握するのは簡単ではありません。JAVA - 別のドロップダウンメニューに基づいてメニューアイテムをドロップする

私は以下の4つのドロップダウンメニューを使用して、私のコードを含めました。そして、最初のグループでの選択に応じて2番目のグループなどで適切な選択肢を与える方法を知りたいと思います...

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

    } 
} 

答えて

0

イベントとリスナーを使用する必要があります。

this other postを確認してください。

関連する問題