⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifyschedule.java

📁 The program is used for Classroom Scheduling for tutors and students. It contain gui tools for mana
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        addButton.setText("Add Course(s)");
        addButton.setToolTipText("Add the course(es) to the schedule");
        jPanel4.add(addButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel2.add(jPanel4, gridBagConstraints);

        cbTimeSlot.setToolTipText("Select a time slot");
        cbTimeSlot.setAlignmentX(0.0F);
        cbTimeSlot.setAlignmentY(0.0F);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 30;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(cbTimeSlot, gridBagConstraints);

        cbClassroom.setToolTipText("Select a classroom");
        cbClassroom.setAlignmentX(0.0F);
        cbClassroom.setAlignmentY(0.0F);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 30;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(cbClassroom, gridBagConstraints);

        cbProfessor.setToolTipText("Select a professor");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 30;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel2.add(cbProfessor, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.3;
        gridBagConstraints.weighty = 0.5;
        gridBagConstraints.insets = new java.awt.Insets(17, 17, 17, 17);
        add(jPanel2, gridBagConstraints);

    }//GEN-END:initComponents

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // Add your handling code here:
    }//GEN-LAST:event_deleteButtonActionPerformed
        
    public void update(java.util.Observable observable, Object obj) {
        stm.fireTableDataChanged();
                         
        // add the unscheduled courses to the list available to schedule
        ArrayList courses = schedule.getCourses();
        Vector unScheduledCourses = new Vector(20,10);
        
        for (int i = 0; i < courses.size(); i++)
            if (!((Course)courses.get(i)).getIsScheduled())
                unScheduledCourses.addElement(courses.get(i));
        
        courseList.setListData(unScheduledCourses);
        
        cbProfessor.removeAllItems();
        Iterator it = schedule.getProfessors().iterator();
        while(it.hasNext())
            cbProfessor.addItem(it.next());
        
        cbTimeSlot.removeAllItems();
        it = schedule.getTimeSlots().iterator();
        while(it.hasNext())
            cbTimeSlot.addItem(it.next());
        
        cbClassroom.removeAllItems();
        it = schedule.getClassrooms().iterator();
        while(it.hasNext())
            cbClassroom.addItem(it.next()); 
        
        // repeat for the table Combo boxes
        professorTableCB.removeAllItems();
        it = schedule.getProfessors().iterator();
        while(it.hasNext())
            professorTableCB.addItem(it.next());
        
        timeSlotTableCB.removeAllItems();
        it = schedule.getTimeSlots().iterator();
        while(it.hasNext())
            timeSlotTableCB.addItem(it.next());
        
        classroomTableCB.removeAllItems();
        it = schedule.getClassrooms().iterator();
        while(it.hasNext())
            classroomTableCB.addItem(it.next());
        
        sectionCounter.setText(String.valueOf(schedule.getSchedCourses().size()));
        
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JComboBox cbClassroom;
    private javax.swing.JComboBox cbProfessor;
    private javax.swing.JComboBox cbTimeSlot;
    private javax.swing.JList courseList;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton printButton;
    private javax.swing.JTextField sectionCounter;
    private javax.swing.JLabel sectionCounterLabel;
    // End of variables declaration//GEN-END:variables
    

    private Schedule schedule = Schedule.getSchedule();
    private Component parent;
    
    private ScheduleTableModel stm;
    private TableSorter sorter;
    
    private TableColumn courseColumn;
    private TableColumn crnColumn;
    private TableColumn roomColumn;
    private TableColumn timeSlotColumn;
    private TableColumn professorColumn;
    private TableColumn conflictColumn;
    private TableColumn noteColumn;
    
    private JComboBox professorTableCB, timeSlotTableCB, classroomTableCB;
    private JTextField crnTableTF;
    private DialogCellEditor myCE;
    
    class ModifyPanelListener implements ActionListener {
        
        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
            System.out.println("I hear this:\n" + actionEvent.getSource() + "\n");
            
            if(actionEvent.getSource() == printButton) {
                printTheView(schedule, true);
            }
            
            if (actionEvent.getSource() == addButton) {
                Object[] coursesToSchedule = courseList.getSelectedValues();
                
                if (coursesToSchedule.length == 0) {
                    JOptionPane.showMessageDialog(parent, "Select a course to be scheduled");
                    return;
                }
                Professor profToSchedule = (Professor) cbProfessor.getSelectedItem();
                
                if (profToSchedule == null) {
                    JOptionPane.showMessageDialog(parent, "Select a professor to be scheduled");
                    return;
                }
                TimeSlot timeSlotToSchedule = (TimeSlot) cbTimeSlot.getSelectedItem();
                
                if (timeSlotToSchedule == null) {
                    JOptionPane.showMessageDialog(parent, "Select a time slot to schedule");
                    return;
                }
                int selected = cbClassroom.getSelectedIndex();
                
                if (selected < 0) {
                    JOptionPane.showMessageDialog(parent, "Select a room to schedule");
                    return;
                }
                
                Classroom classroomToSchedule = (Classroom) schedule.getClassrooms().get(selected);
                
                for(int i = 0; i < coursesToSchedule.length; i++) {
                    SchedCourse theNewScheduledCourse = new SchedCourse(
                    profToSchedule,
                    classroomToSchedule,
                    (Course) coursesToSchedule[i],
                    timeSlotToSchedule);
                    schedule.addSchedCourse(theNewScheduledCourse);
                }
            } else if (actionEvent.getSource() == deleteButton) {
                // Determine which items to be deleted.
                int[] selected = jTable1.getSelectedRows();
                
                for (int i = selected.length - 1; i >= 0; i--) {
                    // Removes the items from the list                    
                    crnColumn.getCellEditor().cancelCellEditing();
                    roomColumn.getCellEditor().cancelCellEditing();
                    timeSlotColumn.getCellEditor().cancelCellEditing();
                    professorColumn.getCellEditor().cancelCellEditing();
                    noteColumn.getCellEditor().cancelCellEditing();
                    schedule.removeSchedCourse((SchedCourse) schedule.getSchedCourses().get(selected[i]));
                }
            }             
        }
    }
    
        // this is a helper for the actionListener
    
    private void printTheView(Pageable toPrint, boolean confirm) {
        System.out.println("I'm going to print a table");
        
        PrinterJob printJob = PrinterJob.getPrinterJob();  // Get a printing object
        printJob.setPageable(toPrint);    // The schedule is printable
        
        if (confirm) {
            if (printJob.printDialog())   // Display print dialog
            {                                        // If true is returned...
                try {
                    printJob.print();                // then print
                }
                catch(PrinterException pe) {
                    System.out.println(pe);
                    JOptionPane.showMessageDialog(ClassroomScheduler.getFrame(),
                    "Error printing a schedule.",
                    "Unknown Printer Error",
                    JOptionPane.ERROR_MESSAGE);
                }
            }
        } 
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -