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

📄 box.java

📁 熟悉非常简单CPU模拟器 1、将所给模拟器的源程序编译成执行程序。 2、运行并观察非常简单CPU模拟器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      else if ( eventSource == viewTraceButton )
      {

         if ( resultsDialog != null )
	 {
	    // Opens trace results window
            traceDialog.setVisible( true );	        	
	 }
	 else
	 {
	    showStatus( "No results to report!" );
	 }
      }
      else if ( eventSource == viewCPUButton )
      {
	 // Opens CPU window
	 CPUBox.setVisible( true );
      }
      else if ( eventSource == viewMemoryButton )
      {
	 // Opens memory window
//         CPUBox.getMemory().setLocation( 568, 0 );
	 CPUBox.getMemory().setVisible( true );
      }
//      else if ( eventSource == viewALUButton )
//      {
	 // Opens alu window
//         CPUBox.aluBox.setLocation( 568, 295 );
//         CPUBox.aluBox.setVisible( true );
//      }
      else if ( eventSource == viewControlUnitButton )
      {

	 if ( selectCU.getSelectedCheckbox().equals( hardWiredCU ) )
	 {
	    // Opens hardwired control unit window
//            CPUBox.controlUnit.setLocation( 700, 200 );
	    // Kills other CU window if it exists
            CPUBox.mcu.setVisible( false );
            CPUBox.mcu.setActive( false );
	    // Displays the Hardwired CU
	    CPUBox.controlUnit.setVisible( true );
            CPUBox.controlUnit.setActive( true );
	 }
	 else if ( selectCU.getSelectedCheckbox().equals(
	    microCodedCU ) )
	 {
	    // Opens microcoded control unit window
//            CPUBox.mcu.setLocation( 700, 200 );
	    // Kills other CU window if it exists
	    CPUBox.controlUnit.setVisible( false );
            CPUBox.controlUnit.setActive( false );
	    // Displays the MicroCoded CU
            CPUBox.mcu.setVisible( true );
            CPUBox.mcu.setActive( true );
	 }

      }
      else if ( eventSource == clearMemoryButton )
      {

         if ( ! CPUBox.isRunning() )
         {
            Memory memory = CPUBox.getMemory();

            // Clears memory contents
            memory.clear();

            if ( memory.isShowing() )
            {
               memory.repaint();
            }

         }

      }
      else if ( eventSource == viewBreakpointsButton )
      {
	 // Opens breakpoints window
	 CPUBox.getBreakpoints().setVisible( true );
      }
      else if ( eventSource == helpButton )
      {
         // Opens help window
         URL codeBaseURL = getCodeBase();
         URL helpURL;

         try
         {
            helpURL = new URL( codeBaseURL.toString() + "help/index.html" );
            getAppletContext().showDocument( helpURL, "_blank" );
         }
         catch ( Exception e ) { }

      }
      else if ( eventSource == aboutButton )
      {
         new AboutDialogue().show();
      }
      else if ( eventSource == sampleButton )
      {
         // Opens help window
         URL codeBaseURL = getCodeBase();
         URL sampleURL;

         try
         {
            sampleURL = new URL( codeBaseURL.toString() + "help/sample.html" );
            getAppletContext().showDocument( sampleURL, "_blank" );
         }
         catch ( Exception e ) { }

      }

   }

   public AssemblyResults getAssemblyResults()
   {
      return ( results );
   }

   public CPU getCPU()
   {
      return ( CPUBox );
   }

   public void disableComponents()
   {
      assembleButton.setEnabled( false );
      hardWiredCU.setEnabled( false );
      microCodedCU.setEnabled( false );
      clearMemoryButton.setEnabled( false );
   }

   public void enableComponents()
   {
      assembleButton.setEnabled( true );
      hardWiredCU.setEnabled( true );
      microCodedCU.setEnabled( true );
      clearMemoryButton.setEnabled( true );
   }

   public Frame getFrame()
   {
      Component c = this;
      Frame f = null;

      while ( ( c = c.getParent() ) != null )
      {

         if ( c instanceof Frame )
         {
            f = ( Frame ) c;
         }

      }

      return ( f );
   }
   
      public int FindNthRowStart(int N,String Text){
           if(N==1){
                   return 0;
           }else{
                   int i=-1;
                   int j=1;
                   while(j!=N){
                           i=Text.indexOf("\n",i+1);
                           j++;
                   }
                   return i+1;
           }
   }
           

   public int FindNthRowEnd(int N,String Text){
                   int i=-1;
                   int j=1;
                   while(j!=N+1){
                           i=Text.indexOf("\n",i+1);
                           j++;
                   }
                   if(i==-1){
                        return Text.length()-1;
                   }else{
                        return i-1;
                   }
   }

   public CheckboxGroup selectCU = new CheckboxGroup();
   public Checkbox hardWiredCU = new Checkbox( "Hardwired", true, selectCU );
   public Checkbox microCodedCU = new Checkbox( "Microprogrammed", false, selectCU );

   public Button assembleButton = new Button( "       Assemble      " );
   public Button viewResultsButton = new Button( "  View Results  " );

   private TextArea programBox;

   private Button viewCPUButton = new Button( "View Register Section" );
   private Button viewTraceButton = new Button( "   View Trace   " );
   private Button viewMemoryButton = new Button( " View Memory  " );

   private Button helpButton = new Button( "  Help  " );
   private Button aboutButton = new Button( "  About  " );
   private Button sampleButton = new Button( "Sample Program" );

//   private Button viewALUButton = new Button( "View ALU" );

   private Button viewControlUnitButton = new Button( "View Control Unit" );
   private Button clearMemoryButton = new Button( "  Clear Memory  " );

   private Button viewBreakpointsButton = new Button( "View Breakpoints" );

   private Label label = new Label( "Memory Location:" );
   private Label space = new Label( "" );
   private Label space2 = new Label( "                    " );
   private Label cuType = new Label( "Control Unit Type" );
   private Label space3 = new Label( "        " );
   
   private TextArea Msg= new TextArea("Welcome to the Simple CPU Simulator.  To start using the simulator type\n in a program followed by the memory location and press assemble.\nAfterwards click on View Register Section and choose run from the menu to start the simulation.", 4, 60,TextArea.SCROLLBARS_NONE);
  
   //private Container Cont=new Container();

   private TextField memoryLocation = new TextField( 5 );

   // Results of the assembly process
   private AssemblyResults results;
   private AssemblyResultsDialog resultsDialog = null;

   // Declare object of type CPU, from CPU.class
   private CPU CPUBox;
   
   static String newline = System.getProperty("line.separator");
   
   public TraceResults traceDialog;
   
         class AboutDialogue extends javax.swing.JFrame implements HyperlinkListener {
    
    /** Creates new form About */
    public AboutDialogue() {
        initComponents();
        this.setSize(new java.awt.Dimension(500, 350));
        this.setBackground(Color.white);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension DialogSize = getSize();
        Point DialogLocation = new Point( ( screenSize.width
                  - DialogSize.width ) / 2, ( screenSize.height -
                  DialogSize.height ) / 2 );

        setLocation( DialogLocation );
    }
    
    //Listens for hyperlink clicks
    public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        try
         {
            getAppletContext().showDocument( event.getURL(), "_blank" );
         }
         catch ( Exception e ) { }
    }
    }

    
    /** 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.
     */
    private void initComponents() {
        AboutLabel = new javax.swing.JLabel();
        LowerPanel = new javax.swing.JPanel();
        OkButton = new javax.swing.JButton();
        CentralPane = new javax.swing.JScrollPane();
        MainText = new javax.swing.JEditorPane();

        setTitle("About The Very Simple CPU Simulatorr");
        setBackground(Color.white);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        AboutLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        AboutLabel.setText("About The Very Simple CPU Simulator");
        AboutLabel.setMaximumSize(new java.awt.Dimension(41, 55));
        AboutLabel.setMinimumSize(new java.awt.Dimension(41, 55));
        AboutLabel.setPreferredSize(new java.awt.Dimension(41, 35));
        AboutLabel.setOpaque(false);
        AboutLabel.setBackground(Color.white);
        getContentPane().add(AboutLabel, java.awt.BorderLayout.NORTH);

        LowerPanel.setPreferredSize(new java.awt.Dimension(10, 45));
        LowerPanel.setOpaque(false);
        LowerPanel.setBackground(Color.white);
        OkButton.setText("Ok");
        OkButton.setPreferredSize(new java.awt.Dimension(100, 26));
        OkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OkButtonActionPerformed(evt);
            }
        });

        LowerPanel.add(OkButton);

        getContentPane().add(LowerPanel, java.awt.BorderLayout.SOUTH);

        CentralPane.setPreferredSize(new java.awt.Dimension(177, 150));
        CentralPane.getViewport().setOpaque(false);
        CentralPane.getVerticalScrollBar().setValue(0);
        String AboutText="<html>\n<body><b>The Very Simple CPU Simulator</b><br><br>Copyright 2001-2003, New Jersey Institute of Technology, Newark, NJ, USA<br><br>\n";
        AboutText+="This program and its source code are made freely available under<br> the terms of the GNU General Public License.  Terms<br> of this license can be found at <a href='http://www.gnu.org'>www.gnu.org</a>.<br><br>\n";
        AboutText+="The latest version of this program and its source code, as well as<br> other simulators developed for use with the textbook <i>Computer Systems<br> Organization and Architecture</i>, can be found at <a href='http://www.awl.com/carpinelli'>www.awl.com/carpinelli</a>.<br><br>\n";
        AboutText+="Development of this program was funded in part by the National<br> Science Foundation through the <a href='http://www.gatewaycoalition.org/'>Gateway Engineering Education Coalition</a>.<br>  Additional funding was supplied by the <a href='http://www.njcmr.org/'>New Jersey Center for Multimedia Research</a>.<br><br>\n";
        AboutText+="Developers: David England, Aleksandr Livshits, and John D. Carpinelli.\n</body></html>";
        MainText.setEditable(false);
        MainText.setContentType("text/html");
        MainText.setText(AboutText);
        MainText.setCaretPosition(0);
        //MainText.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        MainText.setOpaque(false);
        MainText.setBackground(Color.white);
        MainText.addHyperlinkListener(this);
        CentralPane.setViewportView(MainText);
        

        getContentPane().add(CentralPane, java.awt.BorderLayout.CENTER);

        pack();
    }

    private void OkButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
        this.hide();
    }
    
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }
    
    
    // Variables declaration - do not modify
    private javax.swing.JButton OkButton;
    private javax.swing.JPanel LowerPanel;
    private javax.swing.JLabel AboutLabel;
    private javax.swing.JScrollPane CentralPane;
    private javax.swing.JEditorPane MainText;
    // End of variables declaration
    
  }
}

⌨️ 快捷键说明

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