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

public class EsempioComboBoxEditabile implements ActionListener{
	JComboBox combo;
	JLabel etichetta;
	
	public EsempioComboBoxEditabile(JComboBox combo,JLabel etichetta) {
		this.combo=combo;
		this.etichetta=etichetta;
	}
	
	public static void main(String[] args) {
		
		JFrame f = new JFrame("Questa è la mia finestra");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel pannello = new JPanel();
		f.setContentPane(pannello);
		
		JLabel etichetta = new JLabel();
		
		String[] lista={"rosso","verde","blue"};
		JComboBox combo=new JComboBox(lista);

		combo.addActionListener(new EsempioComboBoxEditabile(combo,etichetta));
		combo.setEditable(true);
		pannello.add(combo);
		pannello.add(etichetta);
		
		f.pack();
		f.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e) {
        String nuovoItem = (String) combo.getSelectedItem();
        etichetta.setText(nuovoItem);
	}
}
