hi ..
i make this code .. but when i run it ..doesn't show whole output in window ..and its not show correct answer ..
i can't find error / but its not worked welll

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulator;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Simulator extends JPanel implements ActionListener {
   static final int READ = 10, WRITE = 11, LOAD = 20, STORE = 21, 
      ADD = 30, SUBTRACT = 31, MULTIPLY = 32, DIVIDE = 33, BRANCH = 40, 
      BRANCH_NEG = 41, BRANCH_ZERO = 42, HALT = 43;
   JTextField input, prompt, accum, counter, operandField,
      operCode, register;
   JLabel accumLabel, counterLabel, operandLabel,
      operCodeLabel, registerLabel;
   JButton doneButton, executeButton;
   boolean readFlag;
   int memory[], accumulator, instructionCounter, index,
      operand, operationCode, instructionRegister;

   public void init()
   {
      initializeRegisters();
      instructions();

      // create GUI components
      doneButton = new JButton( "Done" );
      doneButton.addActionListener( this );
      executeButton = new JButton( "Execute next instruction" );
      executeButton.setEnabled( false );
      executeButton.addActionListener( this );
      input = new JTextField( 5 );
      input.addActionListener( this );
      prompt = new JTextField( 15 );

      register = new JTextField( 4 );
      counter = new JTextField( 2 );
      operCode = new JTextField( 2 );
      operandField = new JTextField( 2 );
      accum = new JTextField( 4 );

      prompt.setEditable( false );
      prompt.setText( "0" + index + " ? " );
      register.setEditable( false );
      counter.setEditable( false );
      operCode.setEditable( false );
      operandField.setEditable( false );

      accumLabel = new JLabel( "Accumulator:" );
      counterLabel = new JLabel( "InstructionCounter:" );
      registerLabel = new JLabel( "InstructionRegister:" );
      operCodeLabel = new JLabel( "OperationCode:" );
      operandLabel = new JLabel( "Operand:" );

      // add components to applet
      JPanel panel = new JPanel();
     panel.setLayout( new FlowLayout() );

      panel.add( accumLabel );
      panel.add( accum );
      panel.add( counterLabel );
      panel.add( counter );
      panel.add( registerLabel );
      panel.add( register );
      panel.add( operCodeLabel );
      panel.add( operCode );
      panel.add( operandLabel );
      panel.add( operandField );
      panel.add( prompt );
      panel.add( input );
      panel.add( doneButton );
      panel.add( executeButton );

      displayRegisters(); // place correct values in fields
   }

   // set values held by text fields
   public void displayRegisters()
   {
      operandField.setText( "" + operand );
      counter.setText( "" + instructionCounter );
      accum.setText( "" + accumulator );
      operCode.setText( "" + operationCode );
      register.setText( "" + instructionRegister );
   }

   // set all registers to the correct start value
   public void initializeRegisters()
   {
      memory = new int[ 100 ];
      accumulator = 0;
      instructionCounter = 0;
      instructionRegister = 0;
      operand = 0;
      operationCode = 0;

      index = 0;
      readFlag = false;

      for ( int k = 0; k < memory.length; k++ )
         memory[ k ] = 0;
   }

   // ensure value is within range
   public boolean validation( int value )
   {
      if ( value < 9999 && value > -9999 )
         return false;

      else
         return true;
   }

   // ensure that accumulator has not overflowed
   public boolean testOverflow()
   {
      if ( validation( accumulator ) ) {
         System.out.println( "*** Fatal error." +
            "Accumulator overflow. ***" );
         executeButton.setEnabled( false );

         return true;
      }

      return false;
   }

   // perform all simulator functions
   public void execute()
   {

      prompt.setText( "" );

      instructionRegister = memory[ instructionCounter ];
      operationCode = instructionRegister / 100;
      operand = instructionRegister % 100;

      switch( operationCode ) {
         case READ:

            // actual value is assigned in actionPeformed
            readFlag = true;
            input.setText( "" );
            input.setEditable( true );
            prompt.setText( "Enter an integer:" );
            instructionCounter++;
            break;

         case WRITE:
            System.out.println( "Contents of " + operand +
               " is " + memory[ operand ] );
            instructionCounter++;
            break;

         case LOAD:
            accumulator = memory[ operand ];
            instructionCounter++;
            break;

         case STORE:
            memory[ operand ] = accumulator;
            instructionCounter++;
            break;

         case ADD:
            accumulator += memory[ operand ];

            if ( testOverflow() == true )
               return;

            instructionCounter++;
            break;

         case SUBTRACT:
            accumulator -= memory[ operand ];

            if ( testOverflow() == true )
               return;

            instructionCounter++;
            break;

         case MULTIPLY:
            accumulator *= memory[ operand ];

            if ( testOverflow() == true )
               return;

            instructionCounter++;
            break;

         case DIVIDE:

            if ( memory[ operand ] == 0 ) {
               System.out.println( "*** Fatal error." +
                  "Attempt to divide by zero. ***" );

               executeButton.setEnabled( false );
               return;
            }

            accumulator /= memory[ operand ];
            instructionCounter++;
            break;

         case BRANCH:
            instructionCounter = operand;
            break;

         case BRANCH_NEG:

            if ( accumulator < 0 )
               instructionCounter = operand;

            else
               instructionCounter++;

            break;
         case BRANCH_ZERO:

            if ( accumulator == 0 )
               instructionCounter = operand;
            else

               instructionCounter++;

            break;

         case HALT:

            executeButton.setEnabled( false );
            dump();
            break;

         default:
            executeButton.setEnabled( false );
            System.out.println( "*** Fatal error. " +
               " Invalid operation code. ***" );
      }

      // update the register textfields
      displayRegisters();
   }

   // read in user input, test it, perform operations
   public void actionPerformed( ActionEvent e )
   {
      if ( e.getSource() == input && index < 100 ) {
         int temp = Integer.parseInt( input.getText() );

         // not a read instruction
         if ( !readFlag ) {

            // allow user to reenter values
            if ( validation( temp ) == false ) {
               memory[ index++ ] = temp;

               // clear text field
               input.setText( "" );

               if ( index < 10 )
                  prompt.setText( "0" + index + " ? " );

               else
                  prompt.setText( index + " ? " );
            }

            else
               input.setText( "" );


         }

         // read instruction
         else {
            if ( validation( temp ) == false ) {
               memory[ operand ] = temp;
               input.setEditable( false );
               readFlag = false;
               executeButton.setEnabled( true );
            }

            else {
               input.setText( "" );

               executeButton.setEnabled( false );
            }
         }
      }

      else if ( e.getSource() == doneButton ) {
         input.setEditable( false );
         executeButton.setEnabled( true );
         doneButton.setEnabled( false );
         index = 0;
         execute();   // execute first instruction
      }

      else if ( e.getSource() == executeButton ) {
         index++;
         execute();
      }
   }

   // print out user instructions
   public void instructions()
   {
      System.out.println( "*** Welcome to Simpletron! ***\n" +
         "*** Please enter your program one instruction ***\n" +
         "*** ( or data word ) at a time into the input ***\n" +
         "*** text field. I will display the location ***\n" +
         "*** number and a question mark (?). You then ***\n" +
         "*** type the word for that location. Press the ***\n" +
         "*** Done button to stop entering your program ***\n" );
   }

   // create a string version of the number to output
   public String prepareNumber( int number )
   {
      int count = 0, factor = 1000;
      String output;

      // account for sign of number
      if ( number < 0 ) {
         number *= -1;
         output = "-";
      }

      else
         output = "+";

      // build String representation of number
      while ( factor >= 1 ) {
         output += number / factor;
         number %= factor;
         factor /= 10;
      }

      return output;
   }

   // output information in registers
   public void dump()
   {
      System.out.println( "REGISTERS:" );
      System.out.print( "accumulator            " );
      System.out.println( prepareNumber( accumulator ) );
      System.out.print( "instructionCounter        " );
      System.out.print( ( instructionCounter / 10 ) );
      System.out.println( ( instructionCounter % 10 ) );
      System.out.print( "instructionRegister    " );
      System.out.println( prepareNumber( instructionRegister ) );
      System.out.print( "operationCode             " );
      System.out.print( ( operationCode / 10 ) );
      System.out.println( ( operationCode % 10 ) );
      System.out.print( "operand                   " );
      System.out.print( ( operand / 10 ) );
      System.out.println( ( operand % 10 ) );
      System.out.println( "\nMEMORY:" );
      System.out.println( "        0      1      2      3" +
         "      4      5      6      7      8      9" );

      for ( int k = 0; k < 10; k++ ) {

         if ( k == 0 )
            System.out.print( " " + k + "  " );
         else
            System.out.print( ( k * 10 ) + "  " );

         for ( int i = 0; i < 10; i++ )
            System.out.print( prepareNumber(
               memory[ k * 10 + i ] ) + "  " );

         System.out.println();
      }
   }

    void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
        throw new UnsupportedOperationException("Not yet implemented");
    }


}  // end class Simulat

`

here is main ..

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulator;

 import javax.swing.JFrame;

public class M {

    public static void main(String[] args) {
         Simulator r = new Simulator();
        r.setSize(350,250);
       r.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        r.setVisible(true);
    }
}

What error messages do you get when you execute the code?

There is no window for showing the GUI in the code you posted. The code needs a window like a JFrame to be displayed.

Edited 4 Years Ago by NormR1

there is no errors .. and its display window ..but some of output not appear in window ..

There is no code to show a frame. How are you executing the program? There is no code to show any of the GUI.

i have create panel ..and button . and textfield .those are component of GUI

Where is the window that you need to show those components in?
Have you read the tutorial about how to create GUI?
Click Here

Edited 4 Years Ago by NormR1

i learn something new and i edit my code ..
here
i make space to write my code in assemble alnguage . then when user click on compile its ( compile program)
but i do not know . how i can read the content in textarea

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cleare;

import javax.swing.JTextArea;  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import java.awt.BorderLayout;  
public class ClearE implements ActionListener  
{   
JTextArea textArea=new JTextArea("Enter an assembly program here ");  
JButton button=new JButton("Click here to clear text");  
JButton button2=new JButton("Compile");  
BorderLayout bl=new BorderLayout();  

JFrame frame=new JFrame("Clear JTextArea text");  

public ClearE()  
{  
 textArea.setLineWrap(true);  
 textArea.setWrapStyleWord(true);  
 button.addActionListener(this);  
 frame.setLayout(bl);  
 frame.add(textArea,BorderLayout.CENTER);  
 frame.add(button,BorderLayout.SOUTH);  
 frame.add(button2,BorderLayout.EAST);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
 frame.setSize(400,500);  
 frame.setVisible(true);  
}  

public void actionPerformed(ActionEvent event)  
{  
 if(event.getSource()==button)  
 {  
   textArea.setText("");  
 }  
}  
public static void main(String[]args)  
{  
 ClearE cjtat=new ClearE();  
}  
} 

read the content in textarea

Read the API doc for the textarea class. It has methods for getting text from the textarea.

how i can different between lines ,, i means if i write at one line how i can read it alone

Edited 4 Years Ago by programing

the user enter code in assembly language ex:
1009
1010
2009
3110
4107
1109
4300
0000
0000
-99999
until user enetr -99999 will stop .. and when i click on combile the result will apear like read and write and so on ,,
but if user make it at one line like
100910102009311041071109430000000000-99999

how i can know the first 4digit

and here the static values

static final int READ = 10, WRITE = 11, LOAD = 20, STORE = 21,
ADD = 30, SUBTRACT = 31, MULTIPLY = 32, DIVIDE = 33, BRANCH = 40,
BRANCH_NEG = 41, BRANCH_ZERO = 42, HALT = 43;

If the user's input is in a String, you can use methods in the String class to get any part of the String that you want.

and how i can open an internal frame .
such when i click next will open new frame

i'am edit my first code and make it GUI

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package one;
  import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridBagLayout;
import javax.swing.JOptionPane;

public class One extends JFrame{
     private int accumulator; 
     private int instructionCounter; 
     private int instructionRegister; 
     private int operationCode; 
     private int operand; 
     private boolean halt; 
     private final int READ = 10; 
     private final int WRITE = 11;   

     private final int LOAD = 20; 
     private final int STORE = 21;   
     private final int ADD = 30; 
     private final int SUBTRACT = 31; 
     private final int DIVIDE = 32; 
     private final int MULTIPLY = 33;  
     private final int BRANCH = 40; 
     private final int BRANCHNEG = 41; 
     private final int BRANCHZERO = 42; 
     private final int HALT = 43;
         private MemoryClass memory; 
    private JTextField s;
    private JLabel g;
    private JButton o;
    public One(MemoryClass memory1){
        super("Simpulator");
        setLayout(new FlowLayout());
        s=new JTextField(10);
        g=new JLabel("enter ");
        o=new JButton("execute next)");
        add (g);
        add(s);
        add(o);
        accumulator=0;
        instructionCounter=0;
        instructionRegister=0;
        operationCode=0;
        operand=0;
        halt=false;
        memory=memory1;
    ButtonHandler handler=new ButtonHandler() ;

    o.addActionListener(handler);

    }

  public int getOperationCode(int word){
      int operationCode=word/100;
      return operationCode;
  }
  public int getOperand(int word){
      int operand=word%100;
      return operand;

  }
  public boolean executeNextInstruction(){
      if(halt)
          return false;
      instructionRegister=memory.read(instructionCounter);
      operationCode =getOperationCode(instructionRegister);
      operand=getOperand(instructionRegister);
      boolean transferofcontrol=false;
      switch(operationCode ){
          case READ:
             // String nu=JOptionPane.showInputDialog("enter");

              memory.write(operand, Integer.parseInt(""));
              break;
          case WRITE:
              int data=memory.read(operand);
              if (!halt)
                  JOptionPane.showInputDialog(null,data);
              break;
          case LOAD:
      accumulator=memory.read(operand);
      break;
          case STORE:
      memory.write(operand,accumulator);
      break;
          case ADD:
      accumulator+=memory.read(operand);
      break;
          case SUBTRACT:
      accumulator-=memory.read(operand);
      break;
          case DIVIDE:
      int divisor=memory.read(operand);
              if(!halt)
                  if(divisor==0){
                       JOptionPane.showInputDialog(null,"attempt to divide by zero");
                  }
                  else 
                  accumulator/=divisor;
              break;
          case MULTIPLY:
              accumulator*=memory.read(operand);
              break;
          case BRANCH:
              instructionCounter=operand;
              transferofcontrol=true;
              break;
          case BRANCHNEG:
              if(accumulator<0){
                  instructionCounter=operand;
                  transferofcontrol=true;}
              break;
          case BRANCHZERO:
              if (accumulator==0){
                  instructionCounter=operand;
                  transferofcontrol=true;
              }
              break;
          case HALT:
                JOptionPane.showInputDialog(null,"EXECUTE TERMINATE");
              transferofcontrol=true;
              halt=true;
              break;
          default:
               JOptionPane.showInputDialog(null,"INVALID operation code");
              halt=true;
      }
      if(!transferofcontrol)
          instructionCounter++;
      return !halt;
  }
  public void dump()
  {
        JOptionPane.showInputDialog(null," accumulator\t\t\t%+05d\n"+ accumulator+ 
         "instructionCounter\t\t %02d\n"+instructionCounter+"instructionRegister\t\t%+05d\n"+  
                instructionRegister+"operationCode \t\t\t %02d\n"+operationCode+"operand \t\t\t\t %02d\n"+operand);


                  }
  class MachineClass{

   private  MemoryClass memory1;    
   private One registor1 ;   
   public static final int MEMORY_WORD = 100;
    public MachineClass()
    {  
         memory1=new MemoryClass( MEMORY_WORD);
         registor1=new One(memory1);
    }
    public void inputProgramToMemory() 
{ 
    Integer.parseInt("");
    int memoryWord=0;
    final int END_OF_INPUT = -9999; 
      JOptionPane.showInputDialog(null,"%02d ? "+memoryWord);
      int data = Integer.parseInt("");

    while(data !=END_OF_INPUT)      
    {      
       memory1.write(memoryWord,data);
       memoryWord++;
     JOptionPane.showInputDialog(null,"%02d ? "+memoryWord);  
       data = Integer.parseInt("");
    }

               JOptionPane.showInputDialog(null,"*** Program loading completed ***");

    }   



   public void computerDump() 
   {          
        JOptionPane.showInputDialog(null,"REGISTERS:");  
        registor1.dump();      
        JOptionPane.showInputDialog(null,"MEMORY:");   
        memory1.dump(); 
   }    

    // Execute program  
    public void executeProgram()
    {   
      JOptionPane.showInputDialog(null,"*** Program execution begins  ***");        

         while (  registor1.executeNextInstruction()) ;       
              computerDump(); 
    }
}
   class MemoryClass {

    private int[] memory; 

    public MemoryClass(int amountOfMemoryWord ) 
   {
         memory = new int[amountOfMemoryWord];   

    }
    public void write(int word, int value) 
    {       
          if (word < 0 || word >= memory.length)  
          {     
              JOptionPane.showInputDialog(null,"*** Attempt to write to a non-existing memory location ***");   
          }

         else memory[word] = value; 

     }   
 public int read(int word) 

    {   
         int value = 0;       
         if (word < 0 || word >= memory.length)   
         {      JOptionPane.showInputDialog(null,"*** Attempt to read from a non-existing  memory location ***");     

         }   
         else value = memory[word];     
      return value;  

    }   



     public void dump() 
    {      
         for (int i = 0; i < 10; i++)  
        JOptionPane.showInputDialog(null,"%5d "+i);       

         for (int i = 0; i < memory.length; i += 10)   
         {     
             JOptionPane.showInputDialog(null,"  "+ i+ " ");     
             for (int j = 0; j < 10 && i+j < memory.length; j++)       
                  JOptionPane.showInputDialog("%+05d ", memory[i + j]); //05>>> to print five digits ???        

          } 
     }   


   } 


    private  class ButtonHandler implements ActionListener{

        public void actionPerformed(ActionEvent e){
          if(e.getSource() == o)
          {       
        MachineClass machine = new MachineClass ();   
        machine.inputProgramToMemory();  
        machine.executeProgram();}
        }
    }
     public static void main(String [] args)
{
    One op=new One();
     op.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     op.setSize(300,100);
    op.setVisible(true);
}  
}

when i compile it .. said there is errore ,, but it not appear

when i compile it .. said there is errore ,

Please post the full text of the error messages from the compiler.

run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - constructor One in class one.One cannot be applied to given types;
  required: one.One.MemoryClass
  found: no arguments
  reason: actual and formal argument lists differ in length
    at one.One.main(One.java:265)
Java Result: 1
BUILD SUCCESSFUL (total time: 9 seconds)

On line 265 the code tries to call the One class constructor without any arguments. The One class does NOT have a constructor without arguments.
Either add a constructor to One that does not have an argument,
or change the call to the constructor to have the arguments it requires.

Edited 4 Years Ago by NormR1

its give me thes errors :

run:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:504)
    at java.lang.Integer.parseInt(Integer.java:527)
    at one.One$MachineClass.inputProgramToMemory(One.java:169)
    at one.One$ButtonHandler.actionPerformed(One.java:264)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:504)
    at java.lang.Integer.parseInt(Integer.java:527)
    at one.One$MachineClass.inputProgramToMemory(One.java:169)
    at one.One$ButtonHandler.actionPerformed(One.java:264)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2713)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:680)
    at java.awt.EventQueue$4.run(EventQueue.java:678)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

it so much . how i can know where the error ..
:(

java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:504)
at java.lang.Integer.parseInt(Integer.java:527)
at one.One$MachineClass.inputProgramToMemory(One.java:169)

At line 169 the code tried to convert the String: "" to an int value using the parseInt() method.  The parseInt method threw the exception because "" is not a valid number.

program not work at all

Please explain what you are doing. The exception is thrown when the code is being executed, not from compiling.

i want to make simple GUI for assembly program ..
the final frame should display the accumulator .. accumulator; 
       instructionCounter; 
    instructionRegister; 
      operationCode; 
      int operand;
      -
      input seem :
      1007
      1008
      2007
      3008
      2109
      1109
      4300
      0000
      0000
      0000
      -99999
      ..this program will show sum of two number 
      i try before to make in text area
      but i do not know how i can read it ..

i do not know how i can read it

If the lines of user input are in a text area, the JTextArea class has methods for getting its contents. Have you tried using that?

i ' am start with simple one ..
but i can't make it if i have (string ) .. how i convert the lines enterd from user into code (executed in assembly )
here where i'am face dificults..

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cleare;
import javax.swing.JTextArea;  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import java.awt.event.ActionEvent;  
import java.awt.event.ActionListener;  
import java.awt.BorderLayout;  
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.*;
public class ClearE extends JFrame  
{    
 private JPanel panel;
JTextArea textArea=new JTextArea(35,35);  
JButton button=new JButton("Click here to clear text");  
JButton button2=new JButton("Compile");  
  String string="";
JFrame frame=new JFrame("SIMULATOR");  
 private JPanel d;
public ClearE()  
{  
 textArea.setLineWrap(true);  

    panel=new JPanel();
    d=new JPanel();
     panel.setLayout(new GridLayout(1,3));
 textArea.setWrapStyleWord(true);  
//panel.setLayout(new BorderLayout());
 d.add(textArea);  
  panel.add(button);  
 panel.add(button2);

 ClearE.Action handler =new ClearE.Action();
 button.addActionListener(handler);  
 button2.addActionListener(handler);
add(panel,BorderLayout.SOUTH);
add(d,BorderLayout.CENTER);
}  

    private class Action implements ActionListener{
public void actionPerformed(ActionEvent event)  
{  
 if(event.getSource()==button)  
 {  
   textArea.setText("");  
 }  
 if (event.getSource()==button2){
      string=String.format(textArea.getText());
      JOptionPane.showMessageDialog(null,string);   
 }
}  }
public static void main(String[]args)  
{  
 ClearE frame=new ClearE();  

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
 frame.setSize(400,500);  
 frame.setVisible(true); 
}

} 

this code will clear the content of textarea
and other for read content text area ..
how i can send the content of textarea to be compiled as assembly program (read -write -div-sub-etc)

The variable named: string on line 52 has the contents of the textarea. Is that what you want to pass to another class/method as input?

Several ways:
pass string in the constructor to the other class
call a method with string as a argument to the method

 case READ:    

            Scanner scan = new Scanner(System.in); 

            // Read a word from the keyboard.       
            System.out.print("Enter an integer: ");               

            // Write word to memory.       
            memory.write(operand, scan.nextInt());     


            break;           

     case WRITE:        

           // Read a word from memory.      
          int data = memory.read(operand);        

           // Display the word on the screen        

         if (!halt)
             System.out.println(data);            

          break;            

     case LOAD:       

         // Load a word from memory into the accumulator.      

         accumulator = memory.read(operand); //    accumulator=memory[operand]; 

         break;


    case STORE:       

         // Store accumulator into memory.      

         memory.write(operand, accumulator);  // memory[operand]=accumulator;  


         break;             

    case ADD:      

          // Add word from memory to accumulator.      

           accumulator += memory.read(operand);      


           break;             

    case SUBTRACT:       

         // Subtract word from memory from accumulator.        

           accumulator -= memory.read(operand);       


           break;            

    case DIVIDE:      

          // Divide accumulator by a word loaded from memory.      

           int divisor = memory.read(operand);   //divisor=memory[oprand] ;  

           if (!halt)        
             if (divisor == 0)         
            {          
                  System.out.println("*** Attempt to divide by zero ***");           

            }        

            else            accumulator /= divisor;        

            break;          

    case MULTIPLY:       

         // Multiply accumulator by a word loaded from memory.       

           accumulator *= memory.read(operand);     


           break;       

    case BRANCH:       

         // Branch to location in memory.       

            instructionCounter = operand;      
            transferOfControl = true;       

            break;             

    case BRANCHNEG:       

         // Branch to location in memory if accumulator is negative.      

           if (accumulator < 0)      
          {     
             instructionCounter = operand;        
             transferOfControl = true;     
          }      
          break;             

   case BRANCHZERO:       

       // Branch to location in memory if accumulator is zero.      

           if (accumulator == 0)

          {    
            instructionCounter = operand;    
            transferOfControl = true;        
          }     

           break;             

    case HALT:           

           System.out.println("*** Simpletron execution terminated ***");       
           transferOfControl = true;      
           halt = true;     

           break;           

    default:       

         System.out.println("*** Invalid operation code ***");      

           halt= true; // break;    



         }     



         if (!transferOfControl) 


               instructionCounter++; 


      return !halt;

      }

how i can the content of textarea pass throgh switch test to get the operation

This article has been dead for over six months. Start a new discussion instead.