Link to home
Create AccountLog in
Avatar of drewmore44
drewmore44

asked on

Transferring collections between classes in java

I have a GUI class with 2 collections of Employee objects. The first collection contains an object for every employee working at the firm, and is represented as a JList in the GUI. The user selects certain employees that list (those that are working on a particular shift) and clicks a button below the JFrame, which populates the second collection with the Employee objects that were selected. This all works fine within the GUI class.

There is another button that, when pushed, should send the second collection to another "logic" class . I have put a mouseListener for that button in the logic class, and this works fine as well  - the logic class recognizes when that button is clicked, and everything works fine if I tell the listener to do something simple like print a String when the button is clicked.

My problem, and I've been pulling my hair out for several hours trying to work it out, is that, when the button is clicked, I want to add all of the objects that have been moved into that second collection in the GUI class into a collection in the logic class (which is initially empty). I've tried a dozen different ways to get this to work, and every time I get a null pointer exception. From looking into these errors, I have determined that what is happening is that the logic class thinks the second collection is empty, when in fact objects have been moved into it.

I'm thinking this is because the collection is empty initially, and somehow its contents don't "update" as the GUI class runs. I have tried implementing ListDataListeners and so far they have not helped, but perhaps I've been using them wrong. That being said, this is just a suspicion. I'm a new programming student, so its entirely possible that my logic is flawed somewhere else and I'm more than open to having it corrected. Please help, I don't think I'm going to sleep very well tonight unless I get this thing working.

*note to CEHJ: I'm using the CollectionsNiceListModel for the collections.
Avatar of ksivananth
ksivananth
Flag of United States of America image

can post the code and metion which part you aren't be able to do?
Avatar of drewmore44
drewmore44

ASKER

=============This is the logic class: ===============
public class ShiftRunner {
    public CollectionsNiceListModel<Emp> servers;
    private CollectionsNiceListModel<Emp> bartenders;
    private CollectionsNiceListModel<Emp> cocktailers;
    private CollectionsNiceListModel<Emp> SAs;
    private CollectionsNiceListModel<Emp> runners;
    private CollectionsNiceListModel<Emp> hosts;
    private CollectionsNiceListModel<Emp> kitchen;
    public CollectionsNiceListModel<Emp> serverSched;
    private Schedule schedulee;
    int hold = 0;
    setSched sched;
   

    public ShiftRunner(){      
       
    servers = new CollectionsNiceListModel<Emp>();
       
    setSched sched = new setSched();
    sched.setVisible(true);
   
    launchListener LL = new launchListener();
    sched.launchShiftButton.addMouseListener(LL);
    sched.serversOn.addListDataListener(null);
   
        }
   
   
  /*  ListDataListener listL = new ListDataListener() {
        public void contentsChanged (ListDataEvent listdataevent) {
        System.out.println("CHANGED");
                }
        public void intervalRemoved (ListDataEvent listdataevent){}
        public void intervalAdded (ListDataEvent listdataevent){}
    }
    */
   
        class launchListener implements MouseListener {
            public void mouseClicked (MouseEvent event) {
                servers.addAll(sched.serversOn);
                                 }
               
        public void mousePressed (MouseEvent event) {}
        public void mouseReleased (MouseEvent event) {}
        public void mouseEntered (MouseEvent event) {}
        public void mouseExited (MouseEvent event) {}
====================================
I'm getting the null pointer error on the mouseClicked method of the mouseListener. Specifically, it's telling me that serversOn (which is a collection in the GUI class (sched is the object of that class). The GUI class is below. I should warn you that I've kindof made a mess of it trying to get this thing to work... I'll also point out that the program is slightly more complicated than i originally stated - for simplicity I said there were only two collections (the one holds everybody and the one into which some from the first are moved), but in reality there are several of each type (servers, bartenders...)


=================================================
public class setSched extends javax.swing.JFrame {
        private Roster roster = new Roster();
        public CollectionsNiceListModel<Emp> serversOn;
        private CollectionsNiceListModel<Emp> bartendersOn = new CollectionsNiceListModel();
        private CollectionsNiceListModel<Emp> cocktailersOn = new CollectionsNiceListModel();
        private CollectionsNiceListModel<Emp> SAsOn = new CollectionsNiceListModel();
        private CollectionsNiceListModel<Emp> runnersOn = new CollectionsNiceListModel();
        private CollectionsNiceListModel<Emp> hostsOn = new CollectionsNiceListModel();
        private CollectionsNiceListModel<Emp> kitchenOn = new CollectionsNiceListModel();
        public CollectionsNiceListModel<CollectionsNiceListModel<Emp>> scheduleFin = new CollectionsNiceListModel();
        private ListTableModel serverTable = new ListTableModel(15, 5);
        public Schedule schedule;
        public boolean isSet;
        CollectionsNiceListModel<Emp>finSched = new CollectionsNiceListModel();
    /**
     * Creates new form setSchedule
     */
    public setSched() {
        serversOn = new CollectionsNiceListModel<Emp>();
        initComponents();
        serversOn.addListDataListener(null);
       
       
      //   JList serverList = new JList(roster.getServers());
      //   JList bartenderList = new JList(roster.getBartenders());
      //   JList cocktailersList = new JList(roster.getCocktailers());

         
     //JTable serverTable = new JTable(tm);
         
    }
   

    public CollectionsNiceListModel<Emp> getServersOn() {
        return serversOn;        
    }
    public CollectionsNiceListModel<Emp> getBartendersOn() {
        return bartendersOn;        
    }
    public CollectionsNiceListModel<Emp> getCocktailersOn() {
        return cocktailersOn;    
    }
    public CollectionsNiceListModel<Emp> getSAsOn() {
        return SAsOn;    
    }
    public CollectionsNiceListModel<CollectionsNiceListModel<Emp>> getSchedule() {
        return scheduleFin;    
}
    public Schedule getSchedule() {
        return schedule;
    }
   


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        serverList = new javax.swing.JList();
        serversSet = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        bartenderList = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        cocktailersList = new javax.swing.JList();
        serversLabel = new javax.swing.JLabel();
        cocktailersLabel = new javax.swing.JLabel();
        bartendersLabel = new javax.swing.JLabel();
        bartendersSet = new javax.swing.JButton();
        cocktailersSet = new javax.swing.JButton();
        launchShiftButton = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jScrollPane7 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList();
        jScrollPane9 = new javax.swing.JScrollPane();
        SAsList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        SAsSet = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList4 = new javax.swing.JList();
        jScrollPane10 = new javax.swing.JScrollPane();
        runnersList = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        runnersSet = new javax.swing.JButton();
        jScrollPane11 = new javax.swing.JScrollPane();
        jList6 = new javax.swing.JList();
        jScrollPane12 = new javax.swing.JScrollPane();
        hostsList = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        hostsSet = new javax.swing.JButton();
        jScrollPane13 = new javax.swing.JScrollPane();
        jList5 = new javax.swing.JList();
        jScrollPane14 = new javax.swing.JScrollPane();
        kitchenList = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        kitchenSet = new javax.swing.JButton();
        jScrollPane15 = new javax.swing.JScrollPane();
        jList7 = new javax.swing.JList();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        serverList.setModel(roster.getServers());
        jScrollPane1.setViewportView(serverList);

        serversSet.setText("set");
        serversSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                serverSetClicked(evt);
            }
        });

        bartenderList.setModel(roster.getBartenders());
        jScrollPane3.setViewportView(bartenderList);

        cocktailersList.setModel(roster.getCocktailers());
        jScrollPane4.setViewportView(cocktailersList);

        serversLabel.setText("servers");

        cocktailersLabel.setText("cocktailers");

        bartendersLabel.setText("bartenders");

        bartendersSet.setText("set");
        bartendersSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bartendersSetClicked(evt);
            }
        });

        cocktailersSet.setText("set");
        cocktailersSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cocktailersSetMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(serversLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bartendersLabel)
                .addGap(64, 64, 64)
                .addComponent(cocktailersLabel)
                .addGap(113, 113, 113))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(serversSet)
                        .addGap(66, 66, 66)
                        .addComponent(bartendersSet)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(82, 82, 82))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(cocktailersSet)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(serversLabel)
                            .addComponent(cocktailersLabel)
                            .addComponent(bartendersLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(serversSet)
                    .addComponent(bartendersSet)
                    .addComponent(cocktailersSet)))
        );

        launchShiftButton.setFont(new java.awt.Font("Candara", 0, 24)); // NOI18N
        launchShiftButton.setText("LAUNCH SHIFT");
        launchShiftButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                launchShiftButtonMouseClicked(evt);
            }
        });

        jList1.setModel(serversOn);
        jScrollPane6.setViewportView(jList1);

        jList2.setModel(bartendersOn);
        jScrollPane5.setViewportView(jList2);

        jList3.setModel(cocktailersOn);
        jScrollPane7.setViewportView(jList3);

        SAsList.setModel(roster.getSAs());
        jScrollPane9.setViewportView(SAsList);

        jLabel1.setText("SA's");

        SAsSet.setText("set");
        SAsSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SAsSetMouseClicked(evt);
            }
        });

        jList4.setModel(SAsOn);
        jScrollPane8.setViewportView(jList4);

        runnersList.setModel(roster.getRunners());
        jScrollPane10.setViewportView(runnersList);

        jLabel2.setText("Expo/Runners");

        runnersSet.setText("set");
        runnersSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                runnersSetMouseClicked(evt);
            }
        });

        jList6.setModel(runnersOn);
        jScrollPane11.setViewportView(jList6);

        hostsList.setModel(roster.getHosts());
        jScrollPane12.setViewportView(hostsList);

        jLabel3.setText("hosts");

        hostsSet.setText("set");
        hostsSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                hostsSetMouseClicked(evt);
            }
        });

        jList5.setModel(hostsOn);
        jScrollPane13.setViewportView(jList5);

        kitchenList.setModel(roster.getKitchen());
        jScrollPane14.setViewportView(kitchenList);

        jLabel4.setText("kitchen");

        kitchenSet.setText("set");
        kitchenSet.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                kitchenSetMouseClicked(evt);
            }
        });

        jList7.setModel(kitchenOn);
        jScrollPane15.setViewportView(jList7);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                        .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                        .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                        .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane14, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                        .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(46, 46, 46)
                                    .addComponent(jLabel1)
                                    .addGap(73, 73, 73)
                                    .addComponent(jLabel2)
                                    .addGap(59, 59, 59)
                                    .addComponent(jLabel3)
                                    .addGap(91, 91, 91)
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(36, 36, 36)
                                    .addComponent(SAsSet)
                                    .addGap(69, 69, 69)
                                    .addComponent(runnersSet)
                                    .addGap(66, 66, 66)
                                    .addComponent(hostsSet)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(kitchenSet)
                                    .addGap(29, 29, 29))))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 467, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(297, 297, 297)
                        .addComponent(launchShiftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(302, 302, 302)))
                .addGap(34, 34, 34))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane14, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                            .addComponent(jScrollPane12)
                            .addComponent(jScrollPane10)
                            .addComponent(jScrollPane9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(SAsSet)
                            .addComponent(runnersSet)
                            .addComponent(hostsSet)
                            .addComponent(kitchenSet)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(launchShiftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void serverSetClicked(java.awt.event.MouseEvent evt) {                                  
       serversOn.addAll(serverList.getSelectedValuesList());
    }                                
    private void bartendersSetClicked(java.awt.event.MouseEvent evt) {                                      
        bartendersOn.addAll(bartenderList.getSelectedValuesList());
    }                                    
    private void cocktailersSetMouseClicked(java.awt.event.MouseEvent evt) {                                            
        cocktailersOn.addAll(cocktailersList.getSelectedValuesList());
    }                                          

    private void SAsSetMouseClicked(java.awt.event.MouseEvent evt) {                                    
        SAsOn.addAll(SAsList.getSelectedValuesList());
    }                                  
    private void runnersSetMouseClicked(java.awt.event.MouseEvent evt) {                                        
        runnersOn.addAll(runnersList.getSelectedValuesList());
    }                                      
    private void hostsSetMouseClicked(java.awt.event.MouseEvent evt) {                                      
        hostsOn.addAll(hostsList.getSelectedValuesList());
    }                                    
    private void kitchenSetMouseClicked(java.awt.event.MouseEvent evt) {                                        
        kitchenOn.addAll(kitchenList.getSelectedValuesList());
    }                                      

    private void launchShiftButtonMouseClicked(java.awt.event.MouseEvent evt) {
        Schedule schedule = new Schedule(serversOn, bartendersOn, cocktailersOn, SAsOn, runnersOn, hostsOn, kitchenOn);

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new setSched().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JList SAsList;
    private javax.swing.JButton SAsSet;
    private javax.swing.JList bartenderList;
    private javax.swing.JLabel bartendersLabel;
    private javax.swing.JButton bartendersSet;
    private javax.swing.JLabel cocktailersLabel;
    private javax.swing.JList cocktailersList;
    private javax.swing.JButton cocktailersSet;
    private javax.swing.JList hostsList;
    private javax.swing.JButton hostsSet;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JList jList3;
    private javax.swing.JList jList4;
    private javax.swing.JList jList5;
    private javax.swing.JList jList6;
    private javax.swing.JList jList7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane14;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JList kitchenList;
    private javax.swing.JButton kitchenSet;
    public javax.swing.JButton launchShiftButton;
    private javax.swing.JList runnersList;
    private javax.swing.JButton runnersSet;
    private javax.swing.JList serverList;
    private javax.swing.JLabel serversLabel;
    private javax.swing.JButton serversSet;
    // End of variables declaration
}
you didn't post the code where ShiftRunner getting initialized, btw the constructor should be as below,

public ShiftRunner( setSched sched ){      
       
    servers = new CollectionsNiceListModel<Emp>();
       
    this.sched = sched ;
   
    launchListener LL = new launchListener();
    sched.launchShiftButton.addMouseListener(LL);
    sched.serversOn.addListDataListener(null);
   
        }

you need to pass on the referenc of setSched which you created in the main method.
Sorry, ShiftRunner is initialized in the main class of the program by the following single line:

      public static void main(String[] args) {
         
          ShiftRunner sr = new ShiftRunner();

============
"you need to pass on the referenc of setSched which you created in the main method."

Is that what you've done with the this.sched = sched line?

Does this imply that my problem was that ShiftRunner didn't realize I was talking about the sched that was running?

I'm still trying to wrap my head around what this.sched= sched does. Can you elaborate on this a little more on what it does and why it is necessary?

Also, and I know this is related to the previous question, why did you pass setSched sched to ShiftRunner as a parameter? I don't get how to use this constructor, because a new instance of setSched needs to be initialized each time ShiftRunner runs
who is initializing setSched?
I am bit confused, the below main method initializes setSched and make it visible,

public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(setSchedule.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new setSched().setVisible(true);
            }
        });
    }


which main methid initializes ShiftRunner then?
would I put the following in the main method of the program?

setSched sched0 = new setSched()
ShiftRunner sr = new ShiftRunner (sched0)
sorry, sent that before I saw your last post. ShiftRunner is initialized in the main method of the main class (the only non-GUI class that has a main method) in the program. At the moment, the line mentioned above, which initializes ShiftRunner, is all that is in that main method. Ultimately, there will be another GUI "main menu" that the user will use to launch new shifts and perform other operations (add new employee...), and the main class I'm mentioning here will be used to handle that.


That being said, I'd be happy to hear suggestions on a better/simpler way to structure the program, perhaps with fewer classes
ITS WORKING!!!!!!!!!!!!!!!!

Thanks so much!

I simply did what you suggested above, initialized a new setSched and then a new ShiftRunner in the main class / main method, and passed that setSched to that ShiftRunner as a parameter.

I still can't wrap my head around what exactly this did, and why it works now. I'd really appreciate if you could walk me through that, even if only briefly.
ASKER CERTIFIED SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account