CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Delhi India
    Posts
    2

    A little help plz Continued ............................

    This is how I coded the problem which doesnot compile & generate errors given below this code file

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

    /*<Html>
    <Applet
    code = Simpletron1.class
    height = 250
    width = 614>
    </Applet>
    </Html>*/

    public class Simpletron1 extends JApplet implements ActionListener
    {
    //Constant variables used in the program

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

    //Other variables of the program

    int memory[],
    accumulator = 0,
    instructionRegister = 0,
    instructionCounter = 0,
    operationCode = 0,
    operand = 0;


    //GUI components used in the program

    JLabel lMemory,
    lDataOrInstruction,
    lRegistersAndTheirCurrentValues,
    lAccumulator,
    lInstructionCounter,
    lInstructionRegister,
    lOperationCode,
    lOperand;

    JTextField tMemory,
    tDataOrInstruction,
    tAccumulator,
    tInstructionCounter,
    tInstructionRegister,
    tOperationCode,
    tOperand;
    JTextArea startArea;

    JButton bDone, bExecuteNextInstruction;

    String display = " ";

    DecimalFormat twoDigits, fourDigits;


    public void init()
    {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    display = "*** Welcome to Simpletron! ***\n"+
    "*** Please enter your program one instruction or data word at a time into the ***\n"+
    "*** input text field before which I display the location number with a question ***\n"+
    "*** mark (?). Press Done button to stop entering your program ***\n";

    twoDigits = new DecimalFormat("00");
    fourDigits = new DecimalFormat("0000");

    memory = new int[100];

    startArea = new JTextArea(6, 60);
    startArea.setFont(new Font("Courier", Font.BOLD, 12));
    startArea.setText(display);
    c.add(startArea);

    lMemory = new JLabel("Memory");
    c.add(lMemory);
    //tMemory = new JTextField(5);
    //tMemory.setText(twoDigits.format(instructionCounter)+ " ?");
    //c.add(tMemory);

    lDataOrInstruction = new JLabel("Instruction/Data");
    c.add(lDataOrInstruction);
    tDataOrInstruction = new JTextField(10);
    tDataOrInstruction.addActionListener(this);
    c.add(tDataOrInstruction);

    Icon bug1 = new ImageIcon("cdbug2.gif");
    bDone = new JButton("Done", bug1);
    bDone.addActionListener(this);
    c.add(bDone);

    Icon bug2 = new ImageIcon("cdbug3.gif");
    bExecuteNextInstruction = new JButton("Execute Next Instruction", bug2);
    c.add(bExecuteNextInstruction);

    Icon bug3 = new ImageIcon("bug1.jpg");
    lRegistersAndTheirCurrentValues = new JLabel("Registers And Their Current Values:-- ", bug3, SwingConstants.LEFT);
    c.add(lRegistersAndTheirCurrentValues);

    lAccumulator = new JLabel("Accumulator");
    c.add(lAccumulator);
    tAccumulator = new JTextField(5);
    tAccumulator.setText("0000");
    c.add(tAccumulator);

    lInstructionCounter = new JLabel("Instruction Counter");
    c.add(lInstructionCounter);
    tInstructionCounter = new JTextField(5);
    //tInstructionCounter.setText(twoDigits.format(instructionCounter));
    c.add(tInstructionCounter);

    lInstructionRegister = new JLabel("Instruction Register");
    c.add(lInstructionRegister);
    tInstructionRegister = new JTextField(5);
    //tInstructionRegister.setText("+0000");
    c.add(tInstructionRegister);

    lOperationCode = new JLabel("Operation Code");
    c.add(lOperationCode);
    tOperationCode = new JTextField(5);
    //tOperationCode.setText(twoDigits.format(operationCode));
    c.add(tOperationCode);

    lOperand = new JLabel("Operand");
    c.add(lOperand);
    tOperand = new JTextField(5);
    //tOperand.setText(twoDigits.format(operand));
    c.add(tOperand);


    }
    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == tDataOrInstruction)
    {
    above:
    for(instructionCounter = 0; instructionCounter<memory.length; instructionCounter++)
    {

    tDataOrInstruction.setText(twoDigits.format(Integer.toString(instructionCounter))+" ?"+e.getActionCommand());

    //1// To store what the user input into tDataOrInstruction text field in memory after conveting into integer
    memory[instructionCounter] = Integer.parseInt(tDataOrInstruction.getText());

    //2// Assign these values to instrutionRegister
    instructionRegister= memory[instructionCounter];

    //3// Display value of tInstructionRegister
    tInstructionRegister.setText(fourDigits.format(Integer.toString(instructionRegister)));

    //4// Extract the valuse of operationCode from instructionRegister
    operationCode = instructionRegister/100;

    //5// Display this value in tOperationCode text field
    tOperationCode.setText(twoDigits.format(Integer.toString(instructionCounter)));

    //6//Extract the value of operand from instructionRegister
    operand = instructionRegister%100;

    //7// Display this value in tOperand text field
    tOperand.setText(twoDigits.format(Integer.toString(operand)));

    if(instructionCounter==0)
    continue above;

    //To display the value of memory location when instructionCounter is 1
    tMemory.setText(twoDigits.format(Integer.toString(instructionCounter)+" ?"));

    //To display the value if instructionCounter in tInstructionCounter text field
    tInstructionCounter.setText(twoDigits.format(Integer.toString(instructionCounter)));

    }

    }
    if(e.getSource() == bDone)
    {
    display = "\t\t*** Program loading completed. ***\n"+
    "\t\t*** Program execution begins. **\n";
    startArea.append(display);
    Dump dump= new Dump();
    //dump.height(200);
    //dump.width(500);
    //dump.setVisible(true);
    }
    }
    }


    [COLOR=orangered] The error generated compailing the file[/COLOR=orangered]


    at java.awt.Component.dispatchEvent(Component.java:3476)
    at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1713)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:627)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:831)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:741)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:592)
    at java.awt.Component.dispatchEventImpl(Component.java:3505)
    at java.awt.Container.dispatchEventImpl(Container.java:1627)
    at java.awt.Component.dispatchEvent(Component.java:3476)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

    :confused

  2. #2
    Join Date
    Jan 2002
    Location
    Halifax, NS, Canada
    Posts
    985
    Please don't post duplicate posts.

    Formatted code is much easier to read. Please use the code tags

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    also, that's a stack trace from a running program. compiler errors dont look like that ?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured