使用另一种方法中的数组元素

时间:2015-05-01 00:27:55

标签: java arrays jbutton

我对使用数组有疑问 我有一个为JPanel创建JButton的方法。我用JButton []来存储7个按钮。

问题是这些按钮最初必须是setEnable(false)。它们仅在单击openButton时启用。

我想创建另一个方法,只需从JButton []获取所有元素并将它们设置为Enable。我怎样才能做到这一点?

private JButton filterButtons() {
    //set layout for buttons
    setLayout(new BorderLayout());

    //Array to store description of buttons
    final String[] filterNames = {myEdgeDetect.getDescription(), 
                                    myEdgeHighlight.getDescription(),
                                    myFlipHorizontal.getDescription(),
                                    myFlipVeritcal.getDescription(),
                                    myGrayscale.getDescription(),
                                    mySharpen.getDescription(),
                                    mySoften.getDescription()};

    final JButton[] filterButtons = new JButton[filterNames.length];

    //This panel store buttons on north
    final JPanel buttonPanel = new JPanel();

    //Start to print buttons
    for (int i = 0; i < filterNames.length; i++) {
        filterButtons[i] = new JButton(filterNames[i]);
        filterButtons[i].setEnabled(false);
        filterButtons[i].addActionListener(null);
        filterButtons[i].setActionCommand(" " + i);
        buttonPanel.add(filterButtons[i]);

    }

0 个答案:

没有答案