import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;

import javax.swing.*;

public class MVCExample  {
  
  static int count=0;
  
  public static void main(String[] args) {
    final DefaultListModel model=new DefaultListModel();
    final JList list=new JList(model);
    JButton newButton=new JButton("new");
    newButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        model.addElement("element "+count++);
      }
    });
    JButton removeButton=new JButton("remove");
    removeButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int index=list.getSelectedIndex();
        if (index!=-1)
          model.remove(index);
      }
    });
    
    
    JPanel panel=new JPanel();
    panel.add(newButton);
    panel.add(removeButton);
    
    JFrame frame=new JFrame();
    Container c=frame.getContentPane();
    c.add(new JScrollPane(list));
    c.add(panel,BorderLayout.SOUTH);
    
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400,300);
    frame.show();
  }
}