import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Andres extends Applet implements ActionListener, KeyListener{

	TextField txtUsuario, txtPassword;
	Label IbIUsuario, IbIPassword,IbIEspia;
		
	public void init(){
	
		setLayout(null);

		setBackground(new Color(200,200,100));
		
		IbIUsuario=new Label("Usuario");
		IbIUsuario.setBounds(50,185,150,30);
		IbIUsuario.setFont(new Font("Arial",Font.BOLD+Font.ITALIC,20));
		add(IbIUsuario);

		txtUsuario=new TextField();
		txtUsuario.setBounds(210,185,150,30);
		txtUsuario.setFont(new Font("Arial",Font.BOLD+Font.ITALIC,18));
		txtUsuario.addActionListener(this);
		add(txtUsuario);

		IbIPassword=new Label("Password");
		IbIPassword.setBounds(50,220,150,30);
		IbIPassword.setFont(new Font("Arial",Font.BOLD+Font.ITALIC,20));
		add(IbIPassword);

		txtPassword=new TextField();
		txtPassword.setBounds(210,220,150,30);
		txtPassword.setFont(new Font("Arial",Font.BOLD+Font.ITALIC,18));
		txtPassword.setEchoChar('*');
		txtPassword.addKeyListener(this);
		txtPassword.addActionListener(this);
		add(txtPassword);

		IbIEspia=new Label("",Label.CENTER);
		IbIEspia.setBounds(10,200,390,30);
		IbIEspia.setFont(new Font("Arial",Font.BOLD+Font.ITALIC,16));
		IbIEspia.setForeground(Color.red);
		IbIEspia.setVisible(false);
		add(IbIEspia);
		
				setLayout(null);

		
		ibiNombre=new Label("Nombre");
		ibiNombre.setBounds(10,10,50,25);
		add(ibiNombre);

		txtNombre=new TextField();
		txtNombre.setBounds(70,10,120,25);
		add(txtNombre);

		IstAmigos=new List();
		IstAmigos.setBounds(70,45,120,25);
		add(IstAmigos);

		btnAgregar=new Button("Agregar");
		btnAgregar.setBounds(200,45,120,25);
		btnAgregar.addActionListener(this);
		add(btnAgregar);

		btnSacar=new Button("Sacar");
		btnSacar.setBounds(200,80,120,25);
		btnSacar.addActionListener(this);
		add(btnSacar);

		btnMultiple=new Button("Selección Multiple");
		btnMultiple.setBounds(200,115,120,25);
		btnMultiple.addActionListener(this);
		add(btnMultiple);

		btnUnico=new Button("Selección Simple");
		btnUnico.setBounds(200,150,120,25);
		btnUnico.addActionListener(this);
		add(btnUnico);

	}

	public void actionPerformed(ActionEvent e){
		if(e.getSource().equals(txtUsuario))
			txtPassword.requestFocus();

		if(e.getSource().equals(txtPassword))
			IbIEspia.setVisible(true);
			
			
					if(e.getSource().equals(btnAgregar))
		{
			String nombre=txtNombre.getText();
			if(nombre.length()==0)
				txtNombre.setText("ingrese Nombre");
			else
			{
				IstAmigos.add(nombre);
				txtNombre.setText("");
				txtNombre.requestFocus();
			}
		}

		if(e.getSource().equals(btnSacar))
		{
			if(IstAmigos.isMultipleMode())
			{
				int indices[]=IstAmigos.getSelectedIndexes();
				if(indices.length>0)
				{
					int items=IstAmigos.getItemCount();
					int indice=0;
					do{
						while(IstAmigos.isIndexSelected(indice))
						{
							txtNombre.setText(IstAmigos.getItem(indice));
							IstAmigos.remove(indice);
							items--;
						}
						indice++;
					}while(items>indice);
				}
				else
					txtNombre.setText("Falta Seleccionar");
			}
			else
				{
					int indice=IstAmigos.getSelectedIndex();
					if(indice>0)
					{
						String nombre=IstAmigos.getSelectedItem();
						txtNombre.setText(nombre);
						IstAmigos.remove(indice);
					}
					else
						txtNombre.setText("Falta Seleccionar");
				}
			}

			if(e.getSource().equals(btnMultiple))
			{
				btnMultiple.setEnabled(false);
				btnUnico.setEnabled(true);
				IstAmigos.setMultipleMode(true);
			}
			if(e.getSource().equals(btnUnico))
			{
				btnUnico.setEnabled(false);
				btnMultiple.setEnabled(true);
				IstAmigos.setMultipleMode(false);
			}

	}

	public void keyTyped(KeyEvent e){
		IbIEspia.setVisible(false);
	}

	public void keyPressed(KeyEvent e){
		if(e.getSource().equals(txtPassword))
		{
			IbIEspia.setText("Hola"+txtUsuario.getText()+",tu password es:"+txtPassword.getText());
		}
	}

	public void keyReleased(KeyEvent e){
		IbIEspia.setVisible(false);
	}
	
		Button btnAgregar,btnSacar,btnMultiple,btnUnico;
	Label ibiNombre;
	TextField txtNombre;
	List IstAmigos;





}

