@Override public void setAIChoices(String[] value) { java.util.List<String> choiceList = new ArrayList<String>(); for (String v : value) { choiceList.add(v); } aiModel.setList(choiceList); if (value.length > 0) { aiChoices.setValue(value[0]); } }
public PlayerWaitingView() { this.setOpaque(true); this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH)); // set the heading at the top of the pane label = new JLabel("Player Waiting View"); FontUtils.setFont(label, LABEL_TEXT_SIZE); this.add(label, BorderLayout.NORTH); // create the center panel that displays player info center = new JPanel(); center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS)); this.add(center, BorderLayout.CENTER); // create the AI panel for the bottom of the pane aiPanel = new JPanel(); aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS)); // create the AI type panel JPanel aiTypePanel = new JPanel(); aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS)); aiTypePanel.add(Box.createHorizontalGlue()); JLabel aiTypeLabel = new JLabel("Select AI Type:"); FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE); aiTypePanel.add(aiTypeLabel); aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0))); aiModel = new SpinnerListModel(); aiChoices = new JSpinner(aiModel); ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false); FontUtils.setFont(aiChoices, AI_TEXT_SIZE); aiTypePanel.add(aiChoices); aiTypePanel.add(Box.createHorizontalGlue()); aiPanel.add(aiTypePanel); aiPanel.add(Box.createRigidArea(new Dimension(0, 10))); // create the AI button panel JPanel aiButtonPanel = new JPanel(); aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS)); aiButtonPanel.add(Box.createHorizontalGlue()); addAiButton = new JButton("Add a computer player"); addAiButton.addActionListener(actionListener); FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE); aiButtonPanel.add(addAiButton); aiButtonPanel.add(Box.createHorizontalGlue()); aiPanel.add(aiButtonPanel); aiPanel.add(Box.createRigidArea(new Dimension(0, 10))); // add the AI panel this.add(aiPanel, BorderLayout.SOUTH); }
@Override public String getSelectedAI() { return (String) aiChoices.getValue(); }