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

📄 mainfrm.java

📁 进程调度和存储管理模拟
💻 JAVA
字号:
package cn.edu.cauc.crab.ossimulate;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;import javax.swing.event.*;import javax.swing.border.*;/** * <p>Title: OS simulate</p> * <p>Description: This is my home work.</p> * <p>Copyright: Copyleft (c) 2004</p> * <p>Company: CAUC</p> * @author Crab * @version 0.1 */public class MainFrm extends JFrame {    ProcessSchedule pSch;    PageReplacement pR;    private JPanel contentPane;    private XYLayout xYLayout1 = new XYLayout();    private JTabbedPane mainJDP = new JTabbedPane();    private JPanel processJP = new JPanel();    private JPanel aboutJP = new JPanel();    private XYLayout xYLayout2 = new XYLayout();    private JScrollPane jScrollPane1 = new JScrollPane();    private JTextArea outJTA = new JTextArea();    private JRadioButton FCFS = new JRadioButton();    private JRadioButton SPF = new JRadioButton();    private JRadioButton FPF = new JRadioButton();    private JRadioButton jRadioButton4 = new JRadioButton();    private JRadioButton TF = new JRadioButton();    private ButtonGroup buttonGroup1 = new ButtonGroup();    private JButton makeListBT = new JButton();    private JSlider tf = new JSlider();    private JLabel second = new JLabel();    private JLabel jLabel2 = new JLabel();    private TitledBorder titledBorder1;    private JLabel jLabel1 = new JLabel();    private JButton start = new JButton();    private XYLayout xYLayout3 = new XYLayout();    private JScrollPane jScrollPane2 = new JScrollPane();    private JTextArea about = new JTextArea();    private JPanel memoryJP = new JPanel();    private XYLayout xYLayout4 = new XYLayout();    private JScrollPane jScrollPane3 = new JScrollPane();    private JTextArea out = new JTextArea();    private JRadioButton LRU = new JRadioButton();    private JRadioButton FIFO = new JRadioButton();    private ButtonGroup buttonGroup2 = new ButtonGroup();    private JSlider memory = new JSlider();    private JLabel mL = new JLabel();    private JButton makePLBT = new JButton();    private JButton pageBeginBT = new JButton();    //Construct the frame    public MainFrm() {        enableEvents(AWTEvent.WINDOW_EVENT_MASK);        try {            jbInit();        }        catch(Exception e) {            e.printStackTrace();        }    }    //Component initialization    private void jbInit() throws Exception  {        //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrm.class.getResource("[Your Icon]")));        contentPane = (JPanel) this.getContentPane();        titledBorder1 = new TitledBorder("");        contentPane.setLayout(xYLayout1);        this.setSize(new Dimension(683, 448));        this.setTitle("操作系统模拟");        processJP.setLayout(xYLayout2);        FCFS.setActionCommand("FCFS");        FCFS.setSelected(true);        FCFS.setText("先来先服务");        FCFS.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                FCFS_actionPerformed(e);            }        });        SPF.setActionCommand("SPF");        SPF.setText("短进程/作业优先");        SPF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                SPF_actionPerformed(e);            }        });        FPF.setActionCommand("FPF");        FPF.setText("高响应比优先");        FPF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                FPF_actionPerformed(e);            }        });        jRadioButton4.setText("jRadioButton4");        TF.setActionCommand("TF");        TF.setText("时间片轮转");        TF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                TF_actionPerformed(e);            }        });        makeListBT.setActionCommand("makeListBT");        makeListBT.setText("生成进程/作业队列");        makeListBT.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                makeListBT_actionPerformed(e);            }        });        second.setText("0");        jLabel2.setText("秒");        tf.addChangeListener(new javax.swing.event.ChangeListener() {            public void stateChanged(ChangeEvent e) {                tf_stateChanged(e);            }        });        tf.setMinimum(1);        tf.setEnabled(false);        tf.setBorder(BorderFactory.createLineBorder(Color.black));        processJP.setBorder(BorderFactory.createEtchedBorder());        jLabel1.setText("时间片:");        start.setActionCommand("start");        start.setText("开  始  模  拟");        start.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                start_actionPerformed(e);            }        });        aboutJP.setLayout(xYLayout3);        about.setEditable(false);        about.setText("需求说明,用户手册:刘德焕 020341514\n总体设计,界面接口:李俊伟 020341511\n详细设计,编程实现:刘登科 020341515\n软件测试,软件维护:黄  博 020341507");        outJTA.setEditable(false);        memoryJP.setLayout(xYLayout4);        LRU.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                LRU_actionPerformed(e);            }        });        LRU.setText("最近最久未使用");        LRU.setActionCommand("LRU");        FIFO.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                FIFO_actionPerformed(e);            }        });        FIFO.setText("先入先出");        FIFO.setActionCommand("FIFO");        FIFO.setSelected(true);        memory.setMaximum(10);        memory.setMinimum(3);        memory.setValue(3);        memory.setBorder(BorderFactory.createEtchedBorder());        memory.addChangeListener(new javax.swing.event.ChangeListener() {            public void stateChanged(ChangeEvent e) {                memory_stateChanged(e);            }        });        mL.setText("内存:" + memory.getValue());        makePLBT.setText("建立页面申请列表");        makePLBT.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                makePLBT_actionPerformed(e);            }        });        pageBeginBT.setText("开  始  模  拟");        pageBeginBT.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                pageBeginBT_actionPerformed(e);            }        });        contentPane.add(mainJDP,                            new XYConstraints(3, 2, 671, 418));        mainJDP.add(aboutJP,  "关于作者");        mainJDP.add(processJP,  "进程/作业模拟");        processJP.add(jScrollPane1,              new XYConstraints(152, 4, 492, 342));        processJP.add(FCFS, new XYConstraints(14, 7, 130, 23));        processJP.add(SPF, new XYConstraints(14, 31, 130, 23));        processJP.add(jRadioButton4, new XYConstraints(72, 7, 1, 47));        processJP.add(FPF, new XYConstraints(14, 54, 130, 23));        processJP.add(TF, new XYConstraints(14, 78, 130, 23));        processJP.add(makeListBT, new XYConstraints(14, 114, 134, 23));        processJP.add(tf,    new XYConstraints(14, 173, 134, 23));        processJP.add(jLabel1,     new XYConstraints(15, 146, 63, 17));        processJP.add(jLabel2,  new XYConstraints(124, 146, 19, 20));        processJP.add(second, new XYConstraints(68, 146, 44, 19));        processJP.add(start,        new XYConstraints(14, 223, 134, 23));        mainJDP.add(memoryJP,  "内存页面调度");        jScrollPane1.getViewport().add(outJTA, null);        buttonGroup1.add(FCFS);        buttonGroup1.add(SPF);        buttonGroup1.add(FPF);        buttonGroup1.add(TF);        aboutJP.add(jScrollPane2,      new XYConstraints(91, 11, 415, 358));        jScrollPane2.getViewport().add(about, null);        memoryJP.add(jScrollPane3, new XYConstraints(190, 18, 308, 347));        memoryJP.add(LRU,   new XYConstraints(10, 141, 130, 23));        memoryJP.add(FIFO,   new XYConstraints(10, 103, 130, 23));        jScrollPane3.getViewport().add(out, null);        buttonGroup2.add(LRU);        buttonGroup2.add(FIFO);        memoryJP.add(memory,    new XYConstraints(10, 62, 109, 27));        memoryJP.add(mL, new XYConstraints(10, 28, 100, 19));        memoryJP.add(makePLBT,      new XYConstraints(10, 178, 138, 28));        memoryJP.add(pageBeginBT,        new XYConstraints(10, 221, 138, 28));    }    //File | Exit action performed    public void jMenuFileExit_actionPerformed(ActionEvent e) {        System.exit(0);    }    //Help | About action performed    public void jMenuHelpAbout_actionPerformed(ActionEvent e) {        MainFrm_AboutBox dlg = new MainFrm_AboutBox(this);        Dimension dlgSize = dlg.getPreferredSize();        Dimension frmSize = getSize();        Point loc = getLocation();        dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);        dlg.setModal(true);        dlg.pack();        dlg.show();    }    //Overridden so we can exit when window is closed    protected void processWindowEvent(WindowEvent e) {        super.processWindowEvent(e);        if (e.getID() == WindowEvent.WINDOW_CLOSING) {            jMenuFileExit_actionPerformed(null);        }    }    void TF_actionPerformed(ActionEvent e) {        tf.enable();    }    void tf_stateChanged(ChangeEvent e) {        second.setText("" + tf.getValue());    }    void FCFS_actionPerformed(ActionEvent e) {        tf.disable();    }    void SPF_actionPerformed(ActionEvent e) {        tf.disable();    }    void FPF_actionPerformed(ActionEvent e) {        tf.disable();    }    void makeListBT_actionPerformed(ActionEvent e) {        if (FCFS.isSelected())            pSch = new FCFSProcessSchedule(outJTA);        else if (SPF.isSelected())            pSch = new SPFProcessSchedule(outJTA);        else if (FPF.isSelected())            pSch = new FPFProcessSchedule(outJTA);        else if (TF.isSelected())            pSch = new TFProcessSchedule(tf.getValue(), outJTA);        MakeListDLG dlg = new MakeListDLG(this, pSch);        //Center the window        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        Dimension frameSize = dlg.getSize();        if (frameSize.height > screenSize.height) {            frameSize.height = screenSize.height;        }        if (frameSize.width > screenSize.width) {            frameSize.width = screenSize.width;        }        dlg.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);        dlg.show();    }    void start_actionPerformed(ActionEvent e) {        outJTA.setText("");        pSch.start();    }    void LRU_actionPerformed(ActionEvent e) {    }    void FIFO_actionPerformed(ActionEvent e) {    }    void memory_stateChanged(ChangeEvent e) {        mL.setText("内存:" + memory.getValue());    }    void makePLBT_actionPerformed(ActionEvent e) {        if (FIFO.isSelected())            pR = new FIFOPageReplacement(memory.getValue(), out);        else if (LRU.isSelected())            pR = new LRUPageReplacement(memory.getValue(), out);        makePLDLG dlg = new makePLDLG(this, pR);        //Center the window        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();        Dimension frameSize = dlg.getSize();        if (frameSize.height > screenSize.height) {            frameSize.height = screenSize.height;        }        if (frameSize.width > screenSize.width) {            frameSize.width = screenSize.width;        }        dlg.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);        dlg.show();    }    void pageBeginBT_actionPerformed(ActionEvent e) {        out.setText("");        pR.start();    }}

⌨️ 快捷键说明

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