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

📄 maintainpanel.java

📁 一个带界面的在线测试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        this.mainFrame.reset();
    }//GEN-LAST:event_buttonForEndActionPerformed

    private void buttonForUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonForUpdateActionPerformed
// TODO 将在此处添加您的处理代码:
       // new UpdateItemDialog(this.mainFrame);
       // JOptionPane.showMessageDialog(this,"kosssngdd");
        int index = this.tableForItems.getSelectedRow();
        if (index == -1){
            JOptionPane.showMessageDialog(this,"请先选中一条试题");
        }else{
           
            Item old = (Item)this.ItemBuf.get(index);
             //JOptionPane.showMessageDialog(this,"选中的是:"+old.toString());
            this.mainFrame.setOldItem(old);
             new UpdateItemDialog(this.mainFrame,old);
            boolean result = this.mainFrame.updateItem();
             if (result == true){
                //JOptionPane.showMessageDialog(this,"wokao");
                this.mainFrame.resetItemBuf();
                this.initItemBuf();
                this.repainTable();
             }
        }

    }//GEN-LAST:event_buttonForUpdateActionPerformed

    private void buttonForAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonForAddActionPerformed
// TODO 将在此处添加您的处理代码:
        new AddItemDialog(this.mainFrame);
       // JOptionPane.showMessageDialog(this,"kosssngdd");
        boolean result = this.mainFrame.addItem();
        if (result == true){
            //JOptionPane.showMessageDialog(this,"wokao");
            this.mainFrame.resetItemBuf();
            this.initItemBuf();
            this.repainTable();
        }
        
    }//GEN-LAST:event_buttonForAddActionPerformed
    
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton buttonForAdd;
    private javax.swing.JButton buttonForEnd;
    private javax.swing.JButton buttonForRemove;
    private javax.swing.JButton buttonForUpdate;
    private javax.swing.JPanel infoPanel;
    private javax.swing.JLabel labelForInfo;
    private javax.swing.JPanel opPanel;
    private javax.swing.JPanel panelForTable;
    private javax.swing.JScrollPane scrollPaneForTable;
    private javax.swing.JTable tableForItems;
    // 变量声明结束//GEN-END:variables
    
    //我声明的变量
    private MainFrame mainFrame;
    private List ItemBuf;
  
    
    /**
     *结束维护界面
     */
    private void end(){
        
        this.mainFrame.reset();
        
    }
    
    /** 初始化试题的暂存区*/
    private boolean initItemBuf(){
       try { 
           
           Item item = this.mainFrame.getItemByCondition();
           if (item == null ){
               this.mainFrame.setPickUpStatus(false);
            //如果一下子就取不到,那肯定什么什么啦~
               JOptionPane.showMessageDialog(this,"取不到合乎条件的试题");
               this.end();
               return false;
           }else {
               this.mainFrame.setPickUpStatus(true);
               this.ItemBuf = new LinkedList();
           }
           
           while (item != null){
               this.ItemBuf.add(new TableItem(item));
              item = this.mainFrame.getItemByCondition();
           }
           
          return true;
           
       }catch (Exception e){
           return false;
       }
        
    }
    
        
    /** 重新绘制表格*/
    public void repainTable(){
        
        ItemTableModel itemTM = new ItemTableModel(this.ItemBuf,this);
        this.panelForTable.removeAll();
        this.tableForItems = new JTable(itemTM);
        this.tableForItems.setPreferredScrollableViewportSize(new Dimension(500,150));
        this.tableForItems.setVisible(true);
        this.scrollPaneForTable =  new JScrollPane(this.tableForItems);
        
        this.scrollPaneForTable.setVisible(true);
        this.scrollPaneForTable.setVerticalScrollBarPolicy(
                javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        this.scrollPaneForTable.setHorizontalScrollBarPolicy(
                javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS
                );
        this.tableForItems.getSelectionModel().setSelectionMode(
                javax.swing.ListSelectionModel.SINGLE_SELECTION);
        
        this.panelForTable.setLayout(new BorderLayout());
        this.panelForTable.add(this.scrollPaneForTable,BorderLayout.CENTER);
        this.mainFrame.pack();
    }
}

    /**
     *再次封装Item类,提供isSelected字段
     *标志是否被选择
     *废弃~
     */
class TableItem extends Item{
    private Boolean isSelected;
    public TableItem(Item i){
        super(i);
        this.setType(i.getType());//~ 经常忘记了~不良的设计
        this.isSelected = false;
    }
    public void setIsSelected(Boolean s){
        this.isSelected = s;
    }
    public Boolean getIsSelected(){
        return this.isSelected;
    }
}

/**
 * 该类用于实现JTable的数据模型
 * @author ZZ
 *
 */
class ItemTableModel extends AbstractTableModel{
    
    private List items;
    private Map<Integer ,String> fieldId =new HashMap<Integer,String>();
    private JPanel workplace;
    
    public ItemTableModel(List il,JPanel jp){
        this.items = il;
        this.workplace = jp;
        this.fieldId.put(0, "试题ID");
        this.fieldId.put(1,"难度" );
        this.fieldId.put(2,"内容");
        this.fieldId.put(3,"答案");
        this.fieldId.put(4,"分值");
        this.fieldId.put(5,"时间限制(秒)");
        this.fieldId.put(6,"试题类型");
    }
    
    public int getColumnCount(){
        return this.fieldId.size();
    }
    
    public int getRowCount(){
       return this.items.size();
    }
    
    public Object getValueAt(int row, int col){
        
        TableItem i = (TableItem) this.items.get(row);
        switch (col){
            //case 0:return i.getIsSelected();
            case 0:return new Integer(i.getId());
            case 1:return new Integer(i.getDifficulty());
            case 2:return i.getContent();
            case 3:return i.getAnswer();
            case 4:return new Integer(i.getScore());
            case 5:return new Integer(i.getTimeLimit());
            case 6:return i.getType();
            default: return null;
        }
        
    }
    public String getColumnName(int col){
        return this.fieldId.get(col);
    }


}

⌨️ 快捷键说明

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