1

I have been trying to attach event handlers to abstract list model. didn't work out so I switched to default list model. now I need help debugging. why do I have so many errors? im working with windowbuilder so I recon it shouldn't be this hard.

    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.LayoutManager;

    import javax.swing.JFrame;
    import javax.swing.JPanel;

    import java.awt.BorderLayout;

    import javax.swing.JButton;

    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.DefaultListModel;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JList;
    import javax.swing.AbstractListModel;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;

     public class Window {



 private JFrame frame;

 /**
  * Launch the application. The main method is the entry point to a Java application. 
  * For this assessment, you shouldn't have to add anything to this.
  */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Window window = new Window();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
       }

     /**
     * Create the application. This is the constructor for this Window class.
     * All of the code here will be executed as soon as a Window object is made.
     */
      public Window() {
    initialize();
      }

      /**
      * Initialize the contents of the frame. This is where Window Builder
      * will generate its code.
      * @return 
      */
      public JPanel initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);

    JMenu File = new JMenu("File");
    menuBar.add(File);

    JMenuItem mntmSave = new JMenuItem("Save");
    File.add(mntmSave);

    JMenuItem mntmLoad = new JMenuItem("Load");
    File.add(mntmLoad);

    JMenuItem mntmExit = new JMenuItem("Exit");
    File.add(mntmExit);
    frame.getContentPane().setLayout(null);

    JList Left_list = new JList();
     Left_list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
        }
     });
     Left_list.setFont(new Font("Tahoma", Font.PLAIN, 14));
    Left_list.setModel(new AbstractListModel() {
        String[] values = new String[] {"Case", "Motherboard", "CPU", "RAM", "GPU", "HDD", "PSU"};
        public int getSize() {
            return values.length;
        }
        public Object getElementAt(int index) {
            return values[index];
        }
    });
    Left_list.setBorder(new LineBorder(new Color(0, 0, 0), 2, true));
    Left_list.setBounds(10, 11, 146, 218);
    frame.getContentPane().add(Left_list);

    JList Right_list = new JList();
    Right_list.setModel(new AbstractListModel() {
        String[] values = new String[] {};
        public int getSize() {
            return values.length;
        }
        public Object getElementAt(int index) {
            return values[index];
        }
    });
    Right_list.setBorder(new LineBorder(new Color(0, 0, 0), 2, true));
    Right_list.setBounds(278, 16, 146, 213);
    frame.getContentPane().add(Right_list);

    JButton btnNewButton = new JButton("Add>>");
    btnNewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        }
    });
    btnNewButton.setBounds(166, 91, 102, 23);
    frame.getContentPane().add(btnNewButton);

    JButton btnNewButton_1 = new JButton("<<Remove");
    btnNewButton_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
        }
    });
    btnNewButton_1.setBounds(166, 125, 102, 23);
    frame.getContentPane().add(btnNewButton_1);
     }
      }
     }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Variable names should NOT start with an upper case character. Some of your name are correct and some are not. Be consistent! – camickr Mar 04 '15 at 20:45
  • `frame.getContentPane().setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). *"why do I have so many errors?"* Always copy/paste error and exception output! – Andrew Thompson Mar 05 '15 at 01:59

0 Answers0