import java.awt.*;
import java.awt.event.*;

public
class HelloApp extends Frame implements WindowListener, ActionListener
{
   List list;
   Button buttonAdd, buttonRemove;
   TextField textField;
   public HelloApp ()
   {
      super();
      addWindowListener(this);
      setSize(340, 200);
      setTitle("Moja aplikacja w Javie");
      setLayout(null);
      
      list = new List(20, true);
      list.setBounds(10, 30, 200, 150);
      textField = new TextField();
      textField.setBounds (220, 30, 110, 20);

      buttonAdd = new Button("Dodaj");
      buttonAdd.setBounds(220, 60, 50, 20);
      buttonAdd.addActionListener(this);

      buttonRemove = new Button("Usu");
      buttonRemove.setBounds(220, 90, 50, 20);
      buttonRemove.addActionListener(this);
      
      add(list);
      add(buttonAdd);
      add(buttonRemove);
      add(textField);
      setVisible(true);
      list.setVisible(true);
   }
   public void actionPerformed(ActionEvent e){
      String command = e.getActionCommand();
      if (command.equals("Dodaj")){
         String item = textField.getText();
         if (!item.equals(""))
            list.add(item);
      }
      else if (command.equals("Usu")){
         String tab[] = list.getSelectedItems();
         for(int i = 0; i < tab.length; i++){
            list.remove(tab[i]);
         }
      }
   }
   public void paint(Graphics gDC)
   {
   }
   public static void main(String args[])
   {
      new HelloApp();
   }
   public void windowClosing(WindowEvent e){
      System.exit(0);
   }
   public void windowClosed(WindowEvent e){
   }
   public void windowOpened(WindowEvent e){
   }
   public void windowIconified(WindowEvent e){
   }
   public void windowDeiconified(WindowEvent e){
   }
   public void windowActivated(WindowEvent e){
   }
   public void windowDeactivated(WindowEvent e){
   }
}



