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

📄 firsttime.java

📁 模拟操作系统的进程调用
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import asd.Inform;
import java.math.*;


public class FirstTime {
	private List threadList = new List( "时间片调用" );
	private Inform thread1 , thread2 , thread3 , thread4;
	private static JTextArea output;
	private static String input;
	private static int choose;
	public FirstTime() {
    Inform thread1 = new Inform( "进程1" , (int)(Math.random()*10) , (int)(1+Math.random()*5) , (int)(5+Math.random()*8) );
    Inform thread2 = new Inform( "进程2" , (int)(Math.random()*10),  (int)(1+Math.random()*5) , (int)(5+Math.random()*8) );
    Inform thread3 = new Inform( "进程3" , (int)(Math.random()*10) , (int)(1+Math.random()*5) , (int)(5+Math.random()*8) );
    Inform thread4 = new Inform( "进程4" , (int)(Math.random()*10) , (int)(1+Math.random()*5) , (int)(5+Math.random()*8) );
	String s = thread1.getname();
	threadList.insertAtFront( thread4 );
	threadList.insertAtFront( thread3 );
	threadList.insertAtFront( thread2 );
	threadList.insertAtFront( thread1 );
	
	output = new JTextArea();
	output.append( "\n"+thread1.getname() + ": 优先级为"+thread1.getpriority() + " \n占用cup时间为"+thread1.gettimecpu()+"\n进程运行时间"+thread1.getusetime()+" 状态"+thread1.getstatus() );
	output.append( "\n"+thread2.getname() + ": 优先级为"+thread2.getpriority() + " \n占用cup时间为"+thread2.gettimecpu()+"\n进程运行时间"+thread2.getusetime()+" 状态"+thread2.getstatus() );
	output.append( "\n"+thread3.getname() + ": 优先级为"+thread3.getpriority() + " \n占用cup时间为"+thread3.gettimecpu()+"\n进程运行时间"+thread3.getusetime()+" 状态"+thread3.getstatus() );
	output.append( "\n"+thread4.getname() + ": 优先级为"+thread4.getpriority() + " \n占用cup时间为"+thread4.gettimecpu()+"\n进程运行时间"+thread4.getusetime()+" 状态"+thread4.getstatus() );
    
    input = JOptionPane.showInputDialog( "请输入进程调用方式( 1 代表时间片掉用;2 代表优先级掉用. )" );
    choose = Integer.parseInt( input );
    }
	public void run()
	{
		while( !threadList.isEmpty() ) {
			
	       Inform current = threadList.removeFromFront();
           int temp = 0;
	    
	         while( temp != current.gettimecpu() ){
	   	       	temp++;
	    	   	current.setusetime( current.getusetime() - 1 );
	           	if( current.getusetime() != 0 )
	          	{
	   	        	if( temp == current.gettimecpu())
	            	{
	            		threadList.insertAtBack( current );
	           	    	output.append( "\n"+current.getname() + "的时间片用完, 还有" + current.getusetime() + "个时间片未运行   状态:"+current.getstatus() );
	                	break;
	            	}
	         	}
	        	else
	         	{
	         		current.setstatus( -1 );
	            	output.append( "\n"+current.getname() + "运行结束   状态:"+current.getstatus());  
	            	break;
	         	}
	     	}	
	     
	     }	
	     
	     
    }
    
   public JTextArea getOutput(){ return this.output;}

   public static void main ( String args[] )
   {
   	    
   		FirstTime app = new FirstTime();
   	    app.run();
   		JFrame myFrame = new JFrame(); 
   		myFrame.getContentPane().add( output );
   		myFrame.setSize(200,100);
   		myFrame.show();
   	}
}    
    

⌨️ 快捷键说明

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