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

📄 professorspanel.java

📁 The program is used for Classroom Scheduling for tutors and students. It contain gui tools for mana
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        gridBagConstraints.gridy = 6;        gridBagConstraints.gridwidth = 3;        gridBagConstraints.gridheight = 3;        gridBagConstraints.insets = new java.awt.Insets(17, 0, 0, 0);        jPanel4.add(jPanel6, gridBagConstraints);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 1;        gridBagConstraints.gridy = 0;        gridBagConstraints.insets = new java.awt.Insets(0, 17, 0, 17);        add(jPanel4, gridBagConstraints);    }//GEN-END:initComponents            // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.ButtonGroup buttonGroup1;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JPanel jPanel2;    private javax.swing.JPanel jPanel3;    private javax.swing.JPanel jPanel4;    private javax.swing.JPanel jPanel5;    private javax.swing.JPanel jPanel6;    private javax.swing.JRadioButton jRadioButton1;    private javax.swing.JRadioButton jRadioButton2;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JTextField jTextField1;    private javax.swing.JTextField jTextField2;    private javax.swing.JTable profTable;    // End of variables declaration//GEN-END:variables        private ProfessorPanelListener professorPanelListener;    private Schedule schedule = Schedule.getSchedule();    private ProfessorTableModel ptm;    private TableSorter sorter;    private TableColumn firstColumn;    private TableColumn lastColumn;    private TableColumn statusColumn;    private JTextField editFirst = new JTextField();    private JTextField editLast = new JTextField();    private JComboBox cbStatus = new JComboBox(new String[]{"Full Time","Adjunct"});        private void addListeners() {        ProfessorPanelListener professorPanelListener = new ProfessorPanelListener();        jButton1.addActionListener(professorPanelListener);        jButton2.addActionListener(professorPanelListener);                // use an anonymous class        cbStatus.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                System.out.println("I hear the combobox");                int row = profTable.getSelectedRow();                System.out.println("on row " + row);                if (row >= 0) {                    String status = (String)((JComboBox)e.getSource()).getSelectedItem();                    System.out.println("with status " + status);                    Professor profModified = (Professor)schedule.getProfessors().get(row);                    System.out.println("I got this prof" +profModified);                    if (status.equals("Full Time"))                        profModified.setStatus(Professor.FULL_TIME);                    else                        profModified.setStatus(Professor.ADJUNCT);                    System.out.println("It now looks like this " + profModified);                    schedule.setChanged(true);                }            }        });        editFirst.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                System.out.println("I hear the textfield1");                int row = profTable.getSelectedRow();                System.out.println("on row " + row);                int theRealIndex = sorter.map(row);                System.out.println("The real row is row " + theRealIndex);                if (theRealIndex >= 0) {                    String first = editFirst.getText();                    System.out.println("with first: " + first);                    Professor profModified = (Professor)schedule.getProfessors().get(theRealIndex);                    System.out.println("I got this prof" +profModified);                    profModified.setFirstName(first);                    System.out.println("It now looks like this " + profModified);                    schedule.setChanged(true);                }            }        });        editLast.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                int row = profTable.getSelectedRow();                System.out.println("on row " + row);                int theRealIndex = sorter.map(row);                System.out.println("The real row is row " + theRealIndex);                if (theRealIndex >= 0) {                    String last = editLast.getText();                    System.out.println("with last: " + last);                    Professor profModified = (Professor)schedule.getProfessors().get(theRealIndex);                    System.out.println("I got this prof" +profModified);                    profModified.setLastName(last);                    System.out.println("It now looks like this " + profModified);                    schedule.setChanged(true);                }            }        });    }        public void update(java.util.Observable observable, Object obj) {        ptm.fireTableDataChanged();    }        /**     * Inner class to handle the events     */        class ProfessorPanelListener implements ActionListener {                public void actionPerformed(ActionEvent e) {            System.out.println("I hear " + "|"+e.getActionCommand()+"|");            if (e.getActionCommand().equals("Add Professor")){                String  first = jTextField1.getText().trim();                String  last = jTextField2.getText().trim();                                if (first.equals("") || last.equals(""))                    return; // go back - do nothing not enough info                int status;                if (jRadioButton1.isSelected()) {                    status = Professor.FULL_TIME;                } else {                    status = Professor.ADJUNCT;                }                                Professor prof = new Professor(first,last,status);                schedule.addProfessor(prof); // add it to the schedule                jTextField1.setText("");  // resert the fields to blank                jTextField2.setText("");                            } else if (e.getActionCommand().equals("Delete Selected Professor(s)")){                System.out.println("I'm deleting a prof over here");                // Determine which items to be deleted                int[] selected = profTable.getSelectedRows();                                for (int i = selected.length - 1 ; i >= 0 ; i--) {                    int realIndex = sorter.map(selected[i]);                    // Removes the items from the list                    schedule.removeProfessor((Professor)                    schedule.getProfessors().get(realIndex));                }            }        }    } // end inner class            class ProfessorTableModel extends AbstractTableModel {        private Schedule schedule;        final String[] columnNames = {            "First Name",            "Last Name",            "Status",        };        /** Creates a new instance of BookTableModel */        public ProfessorTableModel() {            schedule = Schedule.getSchedule();        }        public int getColumnCount() {            return columnNames.length;        }        public int getRowCount() {            return schedule.getProfessors().size();        }        public String getColumnName(int col) {            return columnNames[col];        }        public Class getColumnClass(int c) {            return " ".getClass();        }        public boolean isCellEditable(int row, int col) {            return true;        }        public Object getValueAt(int row, int col) {            Professor professor = (Professor)schedule.getProfessors().get(row);            switch(col){                case 0: return professor.getFirstName();                case 1: return professor.getLastName();                case 2:                    int status = professor.getStatus();                    if (status == Professor.FULL_TIME)                        return "Full Time";                    else                        return "Adjunct";            }            return ""; // should never do this        }        public void setValueAt(Object value, int row, int col) {            //fireTableCellUpdated(row, col);        }    }    }

⌨️ 快捷键说明

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