Utilisation de la methode doClick()

/*

 * Main.java
 *
 * Created on April 10, 2008, 10:05 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package doclickexemple;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

/**

 *
 * @author gmonard
 */
public class Main extends JFrame implements ActionListener
{
    JComboBox choisir;
    JButton bouton;
    JButton quitter;

    public Main()
    {
        super("doClick()");
        this.setSize(300,300);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        BorderLayout agencement = new BorderLayout();
        this.setLayout(agencement);

        JPanel panneaumilieu = new JPanel();
        JPanel panneaubas = new JPanel();

        String[] compte = new String[] {"1", "2", "3", "4"};
        choisir = new JComboBox(new DefaultComboBoxModel(compte));
        choisir.addActionListener(this);


        bouton = new JButton("Compter");

        panneaumilieu.add(choisir);
        panneaumilieu.add(bouton);

        quitter = new JButton("Quitter");
        quitter.addActionListener(this);
        panneaubas.add(quitter);

        this.add(panneaumilieu, BorderLayout.CENTER);
        this.add(panneaubas, BorderLayout.SOUTH);
        this.setVisible(true);
    }

    void allume(JButton bouton)
    {
        //Color couleur = bouton.getBackground();
        bouton.doClick(500);
        bouton.setEnabled(false);
        //bouton.setBackground(couleur);
        bouton.doClick();
        bouton.setEnabled(true);
    }



    public void actionPerformed(ActionEvent evenement)
    {
        Object source = evenement.getSource();
        if (source == quitter)
        {
            this.dispose();
        }
        else if (source == choisir)
        {
            String valeur = (String)choisir.getSelectedItem();
            int compte = Integer.valueOf(valeur);
            for (int i = 0; i < compte; i++)
            {
                Dimension size = bouton.getSize();
                bouton.setText(String.valueOf(i+1));
                bouton.setSize(size);
                allume(bouton);
                //bouton.setText("");
                bouton.setSize(size);

            }
        }
    }

    public static void main(String[] args)
    {
        new Main();
    }

}