
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import java.util.EventListener;
import java.util.HashMap;
import javax.swing.JComboBox;

/**
 *
 * @author David Rodriguez A.
 */
public class ComboBoxListener implements ItemListener{
    private HashMap<String,DataListener> mapa;
    private JComboBox combo;
    private ClientFrame frame;
    DataListener data;
    Thread hebra;

    ComboBoxListener(HashMap<String,DataListener> mapa, ClientFrame frame) {
        this.mapa=mapa;
        this.frame=frame;
    }

    public void itemStateChanged(ItemEvent e){
        if(e.getStateChange()==ItemEvent.SELECTED){
            data = mapa.get((String)e.getItem()); //obtiene el listener seleccionado
            if(!data.isRunning()){ new Thread(data,"data").start(); data.setRunning();}
            data.changeStatus();
            //si no esta corriendo, lo corre
           
            //System.out.println(data.getName()+": "+data.getTemp());
        }else{
            if(data!=null) data.changeStatus();
        }
    }
}
