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

📄 mainframe.java

📁 一个带界面的在线测试系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return this.isPickUpStatus;
    }
    
    
    /**
     *暂存一个新的Item,为插入做准备
     */
    public void setNewItem(Item i){
        this.newItem = i;
    }
    
 
    /**暂存试题的旧值*/
    public void setOldItem(Item i){
        this.oldItem = i;
    }
    
    /**将缓存中的试题清理掉*/
    public void resetItemBuf(){
        this.itemBuf = null;
        this.itemBufIndex = 0;
    }
    
    /**
     *插入试题,如果插入成功则返回true ,否则为false
     */
    public boolean addItem(){
        try{
            if (this.newItem == null){
                //根本就没有设置新值,插入是失败的
                return false;
            }else {
                this.itemLib.addItem(this.newItem);
                return true;
            }

        }catch(Exception e){
            JOptionPane.showMessageDialog(this,e.toString());
            
            return false;
        }finally{
            this.oldItem = null;
            this.newItem = null;
            this.resetItemBuf();
        }
    }
    
    /**
     *更新试题
     */
    public boolean updateItem(){
        try{
            if (this.newItem == null){
                return false;
            }else {
              
                this.itemLib.updateItem(this.oldItem, this.newItem);
                 
                return true;
            }

        }catch(Exception e){
            
             JOptionPane.showMessageDialog(this,e.toString());
               return false;
        }finally{
            
            this.oldItem = null;
            this.newItem = null;
            this.resetItemBuf();
            
        }
    }
    
    /**
     *删除试题
     */
    public boolean removeItem(){
        try{
            if (this.oldItem == null){
                return false;
            }else {
              
                this.itemLib.removeItem(this.oldItem.getId());
                return true;
            }

        }catch(Exception e){
            
             JOptionPane.showMessageDialog(this,e.toString());
               return false;
        }finally{
            this.oldItem = null;
            this.newItem = null;
            this.resetItemBuf();
        }
    }
    /**
     *展开条件查询窗口
     */
    private void showFilterPanel(){
        this.workplacePanel.removeAll();
        this.workplacePanel.setLayout(new BorderLayout());
        this.panelFilter = new FilterPanel(this);
        this.workplacePanel.add(this.panelFilter);
        this.pack();
    }
    /**
     * 工作区回复原始状态
     */
    public void reset(){
        
        this.workplacePanel.removeAll();
        
        this.repaint();

        this.tbButtonForMaintain.setEnabled(true);
        this.menuItemForMaintain.setEnabled(true);
        this.tbButtonForTest.setEnabled(true);
        this.menuItemForTest.setEnabled(true);
        this.itemBuf = null;
        this.itemBufIndex = 0;
        
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        this.tbButtonForExit.setEnabled(true);
        this.menuItemForExit.setEnabled(true);
        
    }
    
    /**
     *  在条件查询结束后,去到下一个阶段:测试或者维护
     */
    public void toNextStage(){
        
        //得到筛选条件
        this.filterCondition = this.panelFilter.getConditionDecision();
        if (this.filterCondition.equals("combination")){
            
            this.diff = this.panelFilter.getConditionOfDiff();
            this.type = this.panelFilter.getConditionOfType();
            
        }else if (this.filterCondition.equals("id")){
            this.itemId = this.panelFilter.getConditionOfId();
        }else if (this.filterCondition.equals("type")){
            this.type = this.panelFilter.getConditionOfType();
        }
        
        //开始下一阶段
        if (this.flagToTesting == true ){
            this.showTestingPanel();
            
        }else {
            this.showMaintainPanel();
        }
    }
    
    /**
     * 开始联机测试
     */
    public void toTesting(){
        this.flagToTesting = true;
        this.setEnviroment();
        this.showFilterPanel();
    }
    
     /**
     * 开始试题维护
     */
    public void toMaintain(){
        this.flagToTesting = false;
        this.setEnviroment();
        this.showFilterPanel();
    }
    
    /**
     * 展开测试面板
     */
    public void showTestingPanel(){
        
        this.workplacePanel.removeAll();
        this.workplacePanel.setLayout(new BorderLayout());
        this.panelTesting = new TestingPanel(this);
        if (this.isPickUpStatus == false ){
            JOptionPane.showMessageDialog
                             (this,"找不到和条件匹配的试题!将返回主界面!");
            this.reset();
          
        }else {
            this.workplacePanel.add(this.panelTesting);
            this.pack();
        }
        
    }
    
    /**
     *展开维护面板
     */
    public void showMaintainPanel(){
        
        this.workplacePanel.removeAll();
        this.workplacePanel.setLayout(new BorderLayout());
        this.panelMaintain = new MaintainPanel(this);
        
        if (this.isPickUpStatus == false ){
        
            JOptionPane.showMessageDialog
                             (this,"找不到和题目匹配的试题!将返回主界面!");
            this.reset();
            
        }else {
            this.workplacePanel.add(this.panelMaintain);
            this.pack();
        }
        
    }
    
    /**
     * 得到题库里所有的题目类型
     */
    public Object[] getItemTypes(){
        return this.itemLib.getAllItemTypes();
    }
    
    public void setEnviroment(){
            this.tbButtonForMaintain.setEnabled(false);
            this.menuItemForMaintain.setEnabled(false);
            this.tbButtonForTest.setEnabled(false);
            this.menuItemForTest.setEnabled(false);
            
            this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
            this.tbButtonForExit.setEnabled(false);
            this.menuItemForExit.setEnabled(false);
  
    }
    
    /**
     * 利用筛选条件得到想要的题目
     */
    public Item getItemByCondition()throws Exception{
        
        if (this.filterCondition.equals("random") ){
        	//随机抽题
            return this.itemLib.getItemRandom();
        }else if (this.filterCondition.equals("combination")){
           //条件组合抽取题目
            if (this.itemBuf == null){
                List temp1 = this.itemLib.getAllItems();
                List temp2 = new LinkedList();
                List temp3 = new LinkedList();
                
                //利用难度进行筛选
                if (this.diff != -1){
                    for (int i = 0; i < temp1.size(); i++){
                        Item item = ((Item)temp1.get(i));
                        if (item.getDifficulty() == this.diff) {
                            temp2.add(item);
                        }
                    }
                }else {
                    temp2 = temp1;
                }
                
                //利用类型进行筛选
                if (this.type != null){
                    
                    for (int i = 0; i < temp2.size(); i++){
                        Item item = (Item)temp2.get(i);
                        if(item.getType().equals(this.type) == true){
                            temp3.add(item);
                        }
                    }
                    
                }else {
                    temp3 = temp2;
                }
                
                this.itemBuf = temp3;
                return this.getItemByCondition();//自递归~
                
            }else {
                if (this.itemBufIndex < this.itemBuf.size()){
                    Item item = (Item)this.itemBuf.get(this.itemBufIndex);
                    this.itemBufIndex ++;
                    return item;
                }else {
                    return null;//已经空了~
                }
            }
        }else if (this.filterCondition.equals("all")){
        	//取得所有的题目
            if (this.itemBuf == null){
                this.itemBuf = this.itemLib.getAllItems();
                return this.getItemByCondition();//自递归
            }else {
                if (this.itemBufIndex < this.itemBuf.size()){
                    Item item = (Item)this.itemBuf.get(this.itemBufIndex);
                    this.itemBufIndex ++;
                    return item;
                }else {
                    return null;
                }
            }
        }else if (this.filterCondition.equals("id")){
        	//利用ID取题
            if (this.itemBufIndex == 0){
                this.itemBufIndex ++;
                return this.itemLib.getItemById(this.itemId);
            }
            else {
                return null;
            }
            
        }
        return null;
    }
    
    /**
     *返回标记是否在处于测试中
     *@return 是处于测试功能中,则返回true;否则返回false,一般这时候是表示处于维护功能
     */
    public boolean isTesting(){
        return this.flagToTesting;
    }
    
    public int getItemsNum(){
        if (this.itemBuf == null ){
            return 0;
        }else {
            return this.itemBuf.size();
        }
    }
    
    /**
     * 得到用户输入的对试题的筛选条件
     */
    public String getConditionType(){
        return this.filterCondition;
    }
    
    /**
     * 展开 "帮助" 对话框
     */
    private void showHelp(){
        String help = "点选工具条或者菜单->操作项上联机测试按钮进行测试\n";
        help += "点选工具条或者菜单->操作项上的试题维护按钮进行试题维护\n";
        help += "点选工具条或者菜单->操作项上的退出按钮可以推出本系统\n";
        JOptionPane.showMessageDialog(this,help);
    }
    
    /**
     * 展开"关于"对话框
     */
    private void showAbout(){
        
        String help = "联机测试系统\n";
        help += "author:中山大学软件学院07级硕士张章\n";
        help += "version:1.0";
        JOptionPane.showMessageDialog(this,help);
        
    }
}

⌨️ 快捷键说明

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