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

📄 mainframe.java

📁 一个简单的操作系统模拟程序 java+swing 可进行一般的文件操作 进程建立及删除等
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * MainFrame.java ver 0.1.4
 *
 * Created on 2006年11月30日, 下午12:27
 *
 *The MainFrame for the project
 *
 *History : 2006年11月30日,ver 0.1.0  create the class
 *          2006年12月9日, ver 0.1.1  first release:
 *                                    add the disk and the shell module
 *          2006年12月15日,ver 0.1.2  second release:
 *                                    add the system kernel
 *          2006年12月16日,ver 0.1.3  third release:
 *                                    fix a shell bug: Cannot parse the input command when it has more than one space between the command and the argument
 *                                    fix a file system bug: Throw the NullPointerException,when the origin file has been delete
 *                                    fix a process bug: All of the program result has the same result file name
 *          2006年12月27日,ver 0.1.4  forth release:                            
 *                                    Can save the disk result to a file named "disk.out"
 */

package ossimulation;
import java.util.*;
import javax.crypto.NullCipher;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.event.*;
import java.io.*;

/**
 *
 * @author  Administrator
 */
public class MainFrame extends javax.swing.JFrame {
    
    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        //Here is the code for the program window intialzation 
        this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent evt){
                int result = JOptionPane.showConfirmDialog(null,"Really Want To Shut Down The System ?","Need Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
                if(result == JOptionPane.YES_OPTION){
                    try{
                        simDisk.saveToFile();
                    }
                    catch(IOException ext){}
                    System.exit(0);
                }
            }
        });
  
        //Here is the code for the simulation disk initializtion
        simDisk = new Disk();
        
        //Here is the code for the fileTree initialization
        rootNode = new DefaultMutableTreeNode(new INode("/",simDisk));//create the root node 
        treeModel = new ExtDefaultTreeModel(rootNode);//create the data model for the tree
        fileTree.setModel(treeModel);//apply the data model to the tree
        fileTree.setEditable(true);//set the tree is editable
        
        //Here is the code for the commendOutputLabel initialization
        this.setSysPrompt();
        cmdOutputLabel.setText(sysPrompt);
        
        //Here is the code for the JProcssBar initialization
        diskUsageBar.setValue(0);
        
        //Here is the code for initialized for the diskUsageArea initialization
        this.calculateDisk();
        
        //Here the code for diskUsageArea initialization
        diskUsageArea.setEditable(false);
    
        //start the kernel
        sysKernel = new Kernel(simDisk);
        sysBaseClock = 1000;
        sysClock = new javax.swing.Timer(sysBaseClock,sysKernel);
        sysClock.start();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        cmdInputField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        fileTree = new javax.swing.JTree();
        cmdOutputLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        diskUsageArea = new javax.swing.JTextArea();
        diskUsageLabel = new javax.swing.JLabel();
        cmdHistoryLabel = new javax.swing.JLabel();
        cmdInputLabel = new javax.swing.JLabel();
        diskUsageBar = new javax.swing.JProgressBar();
        jPanel1 = new javax.swing.JPanel();
        sysTimePromptLabel = new javax.swing.JLabel();
        sysTimeDisplayLabel = new javax.swing.JLabel();
        runningRrocessNamePromptLabel = new javax.swing.JLabel();
        runningPIDPromptLabel = new javax.swing.JLabel();
        runningProcessNameDisplayLabel = new javax.swing.JLabel();
        runningPIDDisplayLabel = new javax.swing.JLabel();
        timeSegmentPromptLabel = new javax.swing.JLabel();
        timeSegmentDisplayLabel = new javax.swing.JLabel();
        readyProcLabel = new javax.swing.JLabel();
        blockProcLabel = new javax.swing.JLabel();
        ramUsageBar = new javax.swing.JProgressBar();
        ramUsageLabel = new javax.swing.JLabel();
        IRPromptLabel = new javax.swing.JLabel();
        IRDisplayLabel = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tempResultArea = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        finalResultArea = new javax.swing.JTextArea();
        tempResultLabel = new javax.swing.JLabel();
        finalResultLabel = new javax.swing.JLabel();
        devALabel = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        readyProcArea = new javax.swing.JTextArea();
        jScrollPane4 = new javax.swing.JScrollPane();
        blockProcArea = new javax.swing.JTextArea();
        jScrollPane7 = new javax.swing.JScrollPane();
        devAArea = new javax.swing.JTextArea();
        devBLabel = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        devBArea = new javax.swing.JTextArea();
        devCLabel = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        devCArea = new javax.swing.JTextArea();
        devATime = new javax.swing.JLabel();
        devBTime = new javax.swing.JLabel();
        devCTime = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        systemMenu = new javax.swing.JMenu();
        pauseMenuItem = new javax.swing.JMenuItem();
        resumeMenuItem = new javax.swing.JMenuItem();
        shutdownMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();
        TipMenu = new javax.swing.JMenu();
        cmdtipsMenuItem = new javax.swing.JMenuItem();
        systemTipMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("The OS Simulation Program   Ver 0.2.1");
        setBackground(new java.awt.Color(204, 204, 204));
        cmdInputField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdInputFieldActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(fileTree);

        cmdOutputLabel.setText("Waiting for your commend...");

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        diskUsageArea.setColumns(20);
        diskUsageArea.setEditable(false);
        diskUsageArea.setRows(5);
        jScrollPane2.setViewportView(diskUsageArea);

        diskUsageLabel.setText("Disk Usage:");

        cmdHistoryLabel.setText("There is no Histroy.");

        cmdInputLabel.setText("Type your commend here:");

        diskUsageBar.setStringPainted(true);

        sysTimePromptLabel.setText("System Up Time:");

        sysTimeDisplayLabel.setText("0 sec");

        runningRrocessNamePromptLabel.setText("Running Process Name:");

        runningPIDPromptLabel.setText("Running Process No.:");

        runningProcessNameDisplayLabel.setText("-------");

        runningPIDDisplayLabel.setText("-------");

        timeSegmentPromptLabel.setText("Time Segment:");

        timeSegmentDisplayLabel.setText("0 sec");

        readyProcLabel.setText("Ready Process List:");

        blockProcLabel.setText("Block Process List:");

        ramUsageBar.setStringPainted(true);

        ramUsageLabel.setText("Memory Usage: ");

        IRPromptLabel.setText("Instruction Register:");

        jScrollPane5.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        tempResultArea.setColumns(20);
        tempResultArea.setEditable(false);
        tempResultArea.setRows(5);
        jScrollPane5.setViewportView(tempResultArea);

        jScrollPane6.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        finalResultArea.setColumns(20);
        finalResultArea.setEditable(false);
        finalResultArea.setRows(5);

⌨️ 快捷键说明

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