当前位置: 代码迷 >> J2SE >> (FCFS)进程调度,
  详细解决方案

(FCFS)进程调度,

热度:109   发布时间:2016-04-24 00:52:15.0
(FCFS)进程调度,求救……
刚学java,各位帮忙添加一下我的代码,虽然有点长,但是要实现的功能不是很复杂,主要是创建和启动进程(先来先服务算法)。而且界面方面已经实现。
主要问题是事件实现函数部分,不知道怎么写,怎么在创建进程完后,继续让进程运行……

最后:感激不尽……
第一类pcb
Java code
package process;public class pcb {    static final int Running=1;    static final int Ready=2;    static final int Waiting=3;    private String processname;    private int runtime;   //生存周期    private int prority;    //优先级    private int processstate;      //状态    private int pcbflag;           //暂定    public pcb(String name,int time,int pro)    {        this.processname=name;        this.runtime=time;        this.prority=pro;    }    public pcb()    {        pcbflag=0;    }    public void setprocessname(String name)    {        this.processname=name;    }    public String getprocessname()    {        return processname;    }    public void setruntime(int time)    {        this.runtime=time;    }    public int getruntime()    {        return runtime;    }    public void setprority(int pro)    {        this.prority=pro;    }    public int getprority()    {        return prority;     }    public void setprocessstate(int state)    {        this.processstate=state;    }    public String getprocessstate()    {        String s=new String();        if(this.processstate==1)        {            s="runing";        }        else if(this.processstate==2)        {            s="ready";        }        else if(this.processstate==3)            s="waiting";        return s;    }}


主类
Java code
package process;import javax.swing.*;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.event.*;public class Main {    private JButton startbutton;   //开始    private JButton newbutton;     //新建    private JLabel namelabel;    private JLabel proritylabel;    private JLabel timelabel;    private JLabel readylabel;    private JLabel runinglabel;    private JTable readytable;    private JTable runingtable;    private JTextField nametext;    private JTextField timetext;    private JComboBox proritycom;     //优先级设置    private JPanel newpanel;    private JPanel readypanel;    private JScrollPane readysp;    private JScrollPane runingsp;    Vector waitingvectorname;    pcb []readyarray;    pcb []newarray;    Object[][] readydata;    Object[][] runingdata;    int first;    int end;    int count=0;       //就绪队列中的进程数量        pcb a;    pcb test;    public Main()    {        a=new pcb();        first=0;        end=0;        JFrame jf=new JFrame("进程调度");        Container c=jf.getContentPane();        c.setLayout(null);        newpanel=new JPanel();        newpanel.setLayout(null);        readypanel=new JPanel();        readypanel.setLayout(null);        startbutton=new JButton("开始");        newbutton=new JButton("新建进程");        namelabel=new JLabel("进程名");        proritylabel=new JLabel("优先级");        timelabel=new JLabel("生存期");        readylabel=new JLabel("就绪队列");        runinglabel=new JLabel("运行进程");        nametext=new JTextField();        timetext=new JTextField();        proritycom=new JComboBox();        readyarray=new pcb[8];        waitingvectorname=new Vector();        readydata=new Object[8][4];        runingdata=new Object[1][3];        String []col1={"进程","生存期","优先级","状态"};        String []col2={"进程","生存期","优先级"};        readytable=new JTable(readydata,col1);        readytable.setEnabled(false);        runingtable=new JTable(runingdata,col2);        runingtable.setEnabled(false);        runingsp=new JScrollPane();        readysp=new JScrollPane();        readysp.getViewport().add(readytable);        runingsp.getViewport().add(runingtable);        runingtable.setRowHeight(22);        readytable.setRowHeight(22);        for(int i=1;i<=10;i++)            proritycom.addItem(i);        newpanel.setSize(450,100);        newpanel.setLocation(0,10);        namelabel.setSize(80,20);        namelabel.setLocation(10,5);        nametext.setSize(100,25);        nametext.setLocation(10,30);        proritylabel.setSize(80,20);        proritylabel.setLocation(140,5);        proritycom.setSize(100,25);        proritycom.setLocation(140,30);        timelabel.setSize(80,20);        timelabel.setLocation(280,5);        timetext.setSize(100,25);        timetext.setLocation(280,30);        newbutton.setSize(120,20);        newbutton.setLocation(140,80);        readysp.setSize(400,100);        readysp.setLocation(10,30);        runingsp.setSize(400,43);        runingsp.setLocation(10,250);        readypanel.setSize(450,410);        readypanel.setLocation(0,120);        readylabel.setSize(100,22);        readylabel.setLocation(10,2);        startbutton.setSize(80,20);        startbutton.setLocation(147,350);        runinglabel.setSize(100,20);        runinglabel.setLocation(10,200);        c.add(newpanel);        newpanel.add(namelabel);        newpanel.add(nametext);        newpanel.add(proritylabel);        newpanel.add(proritycom);        newpanel.add(timelabel);        newpanel.add(timetext);        newpanel.add(newbutton);        readypanel.add(runingsp);        readypanel.add(readysp);               readypanel.add(readylabel);        readypanel.add(runinglabel);        readypanel.add(startbutton);        c.add(readypanel);        jf.setSize(450,550);        jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);        jf.setLocationRelativeTo(null);        jf.setVisible(true);        startbutton.addActionListener(new MyActionListener());        newbutton.addActionListener(new MyActionListener());    }      class MyActionListener implements ActionListener      {            public void actionPerformed(ActionEvent e)            {                             }    public static void main(String[] args) {        new Main();    }}