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

📄 disk.java

📁 操作系统磁盘空间分配与回收
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		   else //have enough
		   {
			    for(int i=0;i<total;i++)
	 		       {
	 		    	   for(int k=0;k<mark;k++)
	 		    	   {
	 		    		   di2.setValueAt(Integer.toString(weishi[i][k]), i+1, k+1);
	 		    	   }
	 		    	   
	 		       }
			 
			   area1.setText("");
			   area1.append("the name of program:  "+pro.name+"\n");
			   vector.add(pro);
			   for(int i=pro.count-1;i>=0;i--)
			   {
				   di2.setValueAt(Integer.toString(1), pro.hang[i], pro.lie[i]);
				   //---------------ַ--------------
				   zi_hao=pro.hang[i]-1;
				   wei_hao=pro.lie[i]-1;
     		       int shanqu=Integer.parseInt(t2.getText())*Integer.parseInt(t3.getText());
     		       relative_kuai=zi_hao*mark+wei_hao;
     		       zhu_nu=relative_kuai/shanqu;
     		       cidao_nu=relative_kuai%shanqu/cidao;
     		       wuli_nu=relative_kuai%shanqu%cidao;
     		       area1.append("the"+(pro.count-i)+"kuai"+"\n"+ "          zihao"+"="+zi_hao+"\n");
     		       area1.append("           weihao     ="+wei_hao+"\n");
     		       area1.append("           xiangduikuaihao=zihao*"+mark+"+wei hao="+zi_hao+"*"+mark+"+"+wei_hao+"="+relative_kuai+"\n");
     		       area1.append("           zhu hao=zihao="+zi_hao+"\n");
     		       area1.append("           cidao hao=wei hao/"+cidao+"="+wei_hao+"/"+cidao+"="+cidao_nu+"\n");
     		       area1.append("           wulikuaihao   =weihao%"+cidao+"="+wei_hao+"%"+cidao+"="+wuli_nu+"\n");
     		       //----------------------------------------------------
			   }
			   JOptionPane.showMessageDialog(division_la,"success");
		   }
 	   }
	
//--------------------------
 if(e.getSource()==separated)
{
	  for(int i=0;i<total;i++)
	       {
	    	   for(int k=0;k<mark;k++)
	    	   {
	    		   di1.setValueAt(Integer.toString(weishi[i][k]), i+1, k+1);
	    	   }
	    	   
	       }
	       Process pro=new Process();
		   pro.count=Integer.parseInt(count_field.getText());
		   pro.name=wenjian_field.getText();
		   f_s_name=pro.name;
	     
		   pro.hang=new int[pro.count];
		   pro.lie=new int[pro.count];;
		   
		   boolean op=true,ot=true;
		   int zi_hao=0,wei_hao=0;
		   int relative_kuai,zhu_nu,cidao_nu,wuli_nu;
		   
		   int limit=0;
		   int hang,lie;
		   int coun=0;
		   int mm=0;
		   for(int j=0;j<pro.count;j++)
		   {
			   
		   for(int i=0;(i<total&&op);i++)
		   {
		    	for(int k=0;(k<mark&&ot);k++)
		    	{
		    		if(weishi[i][k]==0)
		    		{
		    			System.out.println(coun);
		    			pro.hang[mm]=i;
		    			pro.lie[mm]=k;
		    		    mm++;
		    		    coun++;
		    		    weishi[i][k]=1;
		    		 
		    			
		       if(coun==pro.count)
		    		{   
		    			op=false;
		    			ot=false;
		    
		    		}
		
		    	 }//for k
		    	
		    }//for i
		   }//for j			
	       
	     if(coun!=pro.count)
		   {
			   JOptionPane.showMessageDialog(division_la,"޿޿disk has no piece to distribute,please recall!");
			  
		   }
		  
		   else //have enough
		   {
			    for(int i=0;i<total;i++)
	 		       {
	 		    	   for(int k=0;k<mark;k++)
	 		    	   {
	 		    		   di2.setValueAt(Integer.toString(weishi[i][k]), i+1, k+1);
	 		    	   }
	 		    	   
	 		       }
			 
			   area1.setText("");
			   area1.append("the name of program:  "+pro.name+"\n");
			   vector.add(pro);
			   for(int i=pro.count-1;i>=0;i--)
			   {
				   di2.setValueAt(Integer.toString(1), pro.hang[i], pro.lie[i]);
				   //---------------ַ--------------
				   zi_hao=pro.hang[i];
				   wei_hao=pro.lie[i];
     		       int shanqu=Integer.parseInt(t2.getText())*Integer.parseInt(t3.getText());
     		       relative_kuai=zi_hao*mark+wei_hao;
     		       zhu_nu=relative_kuai/shanqu;
     		       cidao_nu=relative_kuai%shanqu/cidao;
     		       wuli_nu=relative_kuai%shanqu%cidao;
     		       wuli_nu=relative_kuai%shanqu%cidao;
     		       area1.append("the"+(pro.count-i)+"kuai"+"\n"+ "          zihao"+"="+zi_hao+"\n");
     		       area1.append("           weihao     ="+wei_hao+"\n");
     		       area1.append("           xiangduikuaihao=zihao*"+mark+"+wei hao="+zi_hao+"*"+mark+"+"+wei_hao+"="+relative_kuai+"\n");
     		       area1.append("           zhu hao=zihao="+zi_hao+"\n");
     		       area1.append("           cidao hao=wei hao/"+cidao+"="+wei_hao+"/"+cidao+"="+cidao_nu+"\n");
     		       area1.append("           wulikuaihao   =weihao%"+cidao+"="+wei_hao+"%"+cidao+"="+wuli_nu+"\n");
     		       //----------------------------------------------------
			   }
			 
		   }    
	       
 }
 JOptionPane.showMessageDialog(division_la,"success");  
}

//-------------------------------------	
 if(e.getSource()==fen_clear)//
	   {
		   wenjian_field.setText("");
		   count_field.setText("");
		   area1.setText("");
	   }
 //------------------------------------	   
 	   if(e.getSource()==reclaim)
 	   {   
 		   
 		   reclaim_dia=new JDialog();
 		   reclaim_dia.setTitle("before disk   recall");
 		   reclaim_dia.setSize(500,550);
 		   reclaim_dia.setLayout(new FlowLayout());
 		   
 		   reclaim_la=new JDialog();
		   reclaim_la.setTitle("after disk recall");
		   reclaim_la.setSize(500,850);
		   reclaim_la.setLocation(520,1);
		   reclaim_la.setLayout(new FlowLayout(FlowLayout.CENTER,20,10));
		       
 		   re1=new JTable(total+1,mark+1);
 		   JScrollPane res1=new JScrollPane(re1);
 		   
		   re2=new JTable(total+1,mark+1);
		   JScrollPane res2=new JScrollPane(re2);
		       
		       re1.setValueAt("wei", 0, 0);
		       re1.setValueAt("zi0", 1, 0);
		       
		       re2.setValueAt("wei", 0, 0);
		       re2.setValueAt("zi0", 1, 0);
		       
		       for(int i=0;i<mark;i++)
		       {
		    	   re1.setValueAt(Integer.toString(i), 0, i+1);
		    	   re2.setValueAt(Integer.toString(i), 0, i+1);
		       }
		       
		       for(int i=0;i<total-1;i++)
		       {
		    	   re1.setValueAt(Integer.toString(i+1), i+2, 0);
		    	   re2.setValueAt(Integer.toString(i+1), i+2, 0);
		           
		       }
		       
		       for(int i=0;i<total;i++)
		       {
		    	   for(int k=0;k<mark;k++)
		    	   {
		    		   re1.setValueAt(Integer.toString(weishi[i][k]), i+1, k+1);
		    		  
		    	   }
		    	   
		       }	       
		     reclaim_dia.add(before_recall);
		     reclaim_dia.add(res1);
		       
		     reclaim_la.add(after_recall);
		     reclaim_la.add(res2);
		     
		     reclaim_la.add(wen_name);
 		     reclaim_la.add(word);
 		     reclaim_la.add(ensure_re);
 		     reclaim_la.add(clear_re);
 		     reclaim_la.add(exit_re);
		       
		       JPanel p3;
		       p3=new JPanel();
		       p3.setSize(400,300);
		       p3.setLocation(750,150);
		       p3.setLayout(new BorderLayout());
		       p3.add("North",name);
		       p3.add("Center", sc2);
		       reclaim_la.add(p3);
		       
		       this.setVisible(false);
		       reclaim_dia.setVisible(true);
		       reclaim_la.setVisible(true);
		       
              
               area2.append(""+"the continuous file name: "+f_c_name+"\n");
		  
               area2.append(""+"the separated file name: "+f_s_name+"\n");
 	   }	
	
//-------------------------	
	 if(e.getSource()==close)
 	   {
 		   this.dispose();
 	   }
//--------------------	
	
 if(e.getSource()==exit)
 	   {
 		   division_dia.setVisible(false);
 		   division_la.setVisible(false);
 		   this.setVisible(true);
 	   }
//--------------- recall-------------------------
	
 if(e.getSource()==ensure_re)//
 	   { 
 	
 		   String name=word.getText();
 		   boolean oo=true;
 		   Process p;
		   p=new Process();
		 
 		   for(int i=0;i<vector.size()&&oo;i++)
 		   {
 			   if(name.equals(((Process)vector.elementAt(i)).name))
 				{
 				   oo=false;
 				   p.count=((Process)vector.elementAt(i)).count;
 				   p.name=((Process)vector.elementAt(i)).name;
 				   p.hang=new int[p.count];
 				   p.lie=new int[p.count];
 				   for(int k=0;k<p.count;k++)
 				   {
 					   p.hang[k]=((Process)vector.elementAt(i)).hang[k];
 					   p.lie[k]=((Process)vector.elementAt(i)).lie[k];
 				   }
 				   vector.removeElementAt(i);//remove the process of file
 				}//if
 		   }//for
 		   
 		  
 			   area2.setText("");
 			   area2.append("file name:  "+p.name+"  all recall  "+p.count+"  pankuai\n");
 			   int zi_hao,wei_hao;
 			   for(int i=0;i<p.count;i++)
 	 		   {
 	 			  re2.setValueAt(Integer.toString(0), p.hang[i], p.lie[i]);
 	 			  if(p.name==f_c_name)
 	 			  { 
 	 		
 	 			  	weishi[p.hang[i]-1][p.lie[i]-1]=0;
 	 			    zi_hao=p.hang[i]-1;
 	 			    wei_hao=p.lie[i]-1;
 	 			    area2.append("the "+(i+1)+"  kuai"+"\n"+"           zihao="+zi_hao+"\n");
  		            area2.append("           weihao="+wei_hao+"\n");
 	 			   
 	 			  }
 	 			   if(p.name==f_s_name)
 	 			  {
 	 		
 	 			   weishi[p.hang[i]][p.lie[i]]=0;
 	 			   zi_hao=p.hang[i];
 	 			   wei_hao=p.lie[i];
 	 			   area2.append("the "+(i+1)+"  kuai zihao="+zi_hao+"\n");
  		           area2.append("           weihao="+wei_hao+"\n");
 	 			  
 	 			   }
 	 		   
 	 		   }
 	 		    if(oo==true)
 		   {
 			   JOptionPane.showMessageDialog(reclaim_la, "no file,fail!");
 		   }
 		   else//find,delect
 		   {
 			   for(int i=0;i<total;i++)
 			   {
 				   for(int k=0;k<mark;k++)
 				   {
 					  re2.setValueAt(Integer.toString(weishi[i][k]), i+1, k+1); 
 					  
 				   }//for
 			   }//for
 			  JOptionPane.showMessageDialog(reclaim_la, "success!");
 		   }//else
 	
 		   
 	   }// 	
 //-------------------------

	   if(e.getSource()==clear_re)//е
 	   {
 		   word.setText("");
 		   area2.setText("");
 	
 		  area2.append(""+"the continuous file name: "+f_c_name+"\n");
 	
		  area2.append(""+"the separated file name: "+f_s_name+"\n");
 		   
 	   }
//---------------------------------	
    if(e.getSource()==exit_re)//recall exit
 	   {
 		   reclaim_dia.setVisible(false);
 		   reclaim_la.setVisible(false);
 		   this.setVisible(true);
 	   }
	
	}
 public static void main(String args[])
   {   
    new disk();
   }     	
	
}
class WinClose implements WindowListener
 { public void windowClosing(WindowEvent e)
    {
			System.exit(0);
      
    }
   
   public void windowOpened(WindowEvent e){}
   public void windowActivated(WindowEvent e){}
   public void windowDeactivated(WindowEvent e){}
   public void windowClosed (WindowEvent e){}
   public void windowIconified(WindowEvent e){} 
   public void windowDeiconified(WindowEvent e){}
 }

⌨️ 快捷键说明

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