1

私のプログラムには 2 つのボタンがあり、システムの印刷を行うには両方をクリックする必要があります。私はこれを達成しようとして苦労しています。

button[0].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            button[0].setEnabled( false );
            if( button[1].isEnabled( false) );
                System.out.println("you clicked both buttons");
        }
    });
    button[1].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            button[1].setBackground(Color.YELLOW);
            button[1].setEnabled( false );
            if( buttons[0].isEnabled( false) );
            System.out.println("you clicked both buttons");
        }
    });

次の行でエラーが発生します。

if( buttons[0].isEnabled( false) );

言って

The method isEnabled() in the type Component is not applicable for the arguments (boolean)

私はこれに関して初心者にすぎないので、誰かがこれを行うのを助けたり、別の方法を教えてくれたりするのは素晴らしいことです.

4

3 に答える 3

3

例外は非常に明確です。isEnabled()パラメータを持っていないので、このように使用する必要がありますbuttons[0].isEnabled()

于 2013-03-20T07:35:07.330 に答える
2

isEnabled引数は必要ありません。

これを行う:

if( buttons[0].isEnabled() )
于 2013-03-20T07:36:30.847 に答える
1

これがあなたの答えです:

button1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent arg0) {

        button1.setEnabled(false);
        if (!button1.isEnabled() && !button2.isEnabled()) {
            System.out.println("you clicked both buttons");
        }
    }
});

button2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

        button2.setBackground(Color.YELLOW);
        button2.setEnabled(false);
        if (!button2.isEnabled() && !button1.isEnabled()) {
            System.out.println("you clicked both buttons");
        }
    }
});
于 2013-03-20T07:40:20.330 に答える