Choix dans une liste (JComboBox)

/*

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

package jcomboboxexemple;

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

 *
 * @author gmonard
 */
public class Main extends JFrame implements ActionListener
{

    JComboBox choisir;
    JTextField voir;

    /** Creates a new instance of Main */
    public Main()
    {
        super("Exemple d'utilisation de JComboBox");
        this.setSize(300,100);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        FlowLayout agencement = new FlowLayout(FlowLayout.LEFT);
        this.setLayout(agencement);

        String[] choix = new String[] {"chaine1", "chaine2", "3", "quitter"};
        choisir = new JComboBox(new DefaultComboBoxModel(choix));
        choisir.addActionListener(this);

        voir = new JTextField("",10);
        voir.setEditable(false);


        this.add(choisir);
        this.add(voir);

        this.setVisible(true);
    }

    public void actionPerformed(ActionEvent evenement)
    {
        Object source = evenement.getSource();
        if (source == choisir)
        {
            String vue = (String) choisir.getSelectedItem();
            voir.setText(vue);
            if (vue == "quitter")
            {
                this.dispose();
            }
        }
    }

    /**

     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        new Main();
    }

}