package dispatcher;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ShowFrame extends JFrame {
MainApplet ma;
public ShowFrame(MainApplet ma,int n[][]) {
super("Map");
setSize(600, 580);
this.ma=ma;
new InitFrame(this);
MapPane map = new MapPane(n,this);
getContentPane().add(map);
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
}
}
}
class MapPane extends JPanel implements Runnable{
int n[][];ShowFrame sf;
Graphics gr;
Thread FCFSthread,RRthread,RR2thread,SPNthread,SRTthread,HRRNthread,FeelBackthread,FeelBack2thread;
public MapPane(int n[][],ShowFrame sf){
this.n=n;this.sf=sf;
}
public void paintComponent(Graphics g) {
g.clearRect(0,0,600,580) ;
g.drawLine(120,20,580,20);
g.drawLine(120,520,580,520);
for(int i=120;i<=580;i=i+20){
if(i%100==20){
String kn=String.valueOf(i/20-6) ;
g.drawString(kn,i-3,12) ;
g.fillRect(i,15,2,5);
g.drawString(kn,i-3,512) ;
g.fillRect(i,515,2,5);
}
else{g.fillRect(i,16,1,4); g.fillRect(i,516,1,4);}
}
drawFCFS(g);
drawRR(g);
drawRR2(g);
drawSPN(g);
drawSRT(g);
drawHRRN(g);
drawFeelBack(g);
drawFeelBack2(g);
}
public void drawBlock(int num,int s,int pos,Graphics g){
g.fillRect((s+6)*20,num*60+pos*10+25,20,10) ;
}
public void drawFCFS(Graphics g){
g.drawString("FCFS:",50,55) ;
g.drawString("A:",108,35) ;
g.drawString("B:",108,45) ;
g.drawString("C:",108,55) ;
g.drawString("D:",108,65) ;
g.drawString("E:",108,75) ;
FCFSthread=new Thread(this);
FCFSthread.start() ;
}
public void drawRR(Graphics g){
g.drawString("RR:(q=1)",50,115) ;
g.drawString("A:",108,95) ;
g.drawString("B:",108,105) ;
g.drawString("C:",108,115) ;
g.drawString("D:",108,125) ;
g.drawString("E:",108,135) ;
RRthread=new Thread(this);
RRthread.start() ;
}
public void drawRR2(Graphics g){
g.drawString("RR:(q=4)",50,175) ;
g.drawString("A:",108,155) ;
g.drawString("B:",108,165) ;
g.drawString("C:",108,175) ;
g.drawString("D:",108,185) ;
g.drawString("E:",108,195) ;
RR2thread=new Thread(this);
RR2thread.start() ;
}
public void drawSPN(Graphics g){
g.drawString("Next(SPN)",40,235) ;
g.drawString("A:",108,215) ;
g.drawString("B:",108,225) ;
g.drawString("C:",108,235) ;
g.drawString("D:",108,245) ;
g.drawString("E:",108,255) ;
SPNthread=new Thread(this);
SPNthread.start() ;
}
public void drawSRT(Graphics g){
g.drawString("SRT",50,295) ;
g.drawString("A:",108,275) ;
g.drawString("B:",108,285) ;
g.drawString("C:",108,295) ;
g.drawString("D:",108,305) ;
g.drawString("E:",108,315) ;
SRTthread=new Thread(this);
SRTthread.start() ;
}
public void drawHRRN(Graphics g){
g.drawString("HRRN",50,355) ;
g.drawString("A:",108,335) ;
g.drawString("B:",108,345) ;
g.drawString("C:",108,355) ;
g.drawString("D:",108,365) ;
g.drawString("E:",108,375) ;
HRRNthread=new Thread(this);
HRRNthread.start() ;
}
public void drawFeelBack(Graphics g){
g.drawString("FeelBack(q=1)",15,415) ;
g.drawString("Queue numbers=5",0,425) ;
g.drawString("A:",108,395) ;
g.drawString("B:",108,405) ;
g.drawString("C:",108,415) ;
g.drawString("D:",108,425) ;
g.drawString("E:",108,435) ;
FeelBackthread=new Thread(this);
FeelBackthread.start() ;
}
public void drawFeelBack2(Graphics g){
g.drawString("FeelBack(q=2^i)",10,475) ;
g.drawString("Queue numbers=5",0,485) ;
g.drawString("A:",108,455) ;
g.drawString("B:",108,465) ;
g.drawString("C:",108,475) ;
g.drawString("D:",108,485) ;
g.drawString("E:",108,495) ;
FeelBack2thread=new Thread(this);
FeelBack2thread.start() ;
}
public void run(){
int a[]=null;int num=0;
try{
if(Thread.currentThread()==FCFSthread){
a=sortFCFS.sort(n);
}
if(Thread.currentThread()==RRthread){
try{
a=sortRR.sort(n);
}catch(InterruptedException e){}
num=1;
}
if(Thread.currentThread()==RR2thread){
try{
a=sortRR2.sort(n);
}catch(InterruptedException e){}
num=2;
}
if(Thread.currentThread()==SPNthread){
a=sortSPN.sort(n);
num=3;
}
if(Thread.currentThread()==SRTthread){
a=sortSRT.sort(n);
num=4;
}
if(Thread.currentThread()==HRRNthread){
a=sortHRRN.sort(n);
num=5;
}
if(Thread.currentThread()==FeelBackthread){
try{
a=sortFB.sort(n);
}catch(InterruptedException e){}
num=6;
}
if(Thread.currentThread()==FeelBack2thread){
try{
a=sortFB2.sort(n);
}catch(InterruptedException e){}
num=7;
}
}catch(ArrayIndexOutOfBoundsException e){
JOptionPane.showMessageDialog(this,"对不起,输入超出了本程序的表示范围!","fail",JOptionPane.WARNING_MESSAGE);
sf.dispose();
}
for(int i=0;i<a.length ;i++){
gr=getGraphics();
if(num%2==0) gr.setColor(Color.red);
else gr.setColor(Color.blue);
if(a[i]>=0)
drawBlock(num,i,a[i],gr);
try{
Thread.sleep(100) ;
}catch(InterruptedException e){}
}
}
}