GUI example for beginners

GUI example for beginners

GUI example for beginners
View Answers

April 6, 2012 at 5:55 PM

sory ,, I will posted my code again

import java.util.Scanner;

public class RegistorClass {

 private int accumulator;  private int instructionCounter;  private int instructionRegister;  private int operationCode;  private int operand;  private boolean halt;  private MemoryClass memory;// Operation codes 
// Input/Output operations.  private final int READ = 10;  private final int WRITE = 11;    // Load/Store operations.  private final int LOAD = 20;  private final int STORE = 21;     // Arithmetic operations.  private final int ADD = 30;  private final int SUBTRACT = 31;  private final int DIVIDE = 32;  private final int MULTIPLY = 33;   // Transfer-of-control operations. private final int BRANCH = 40;  private final int BRANCHNEG = 41;  private final int BRANCHZERO = 42;  private final int HALT = 43;public RegistorClass(MemoryClass memory1){

     accumulator = 0;        instructionCounter = 0;       instructionRegister = 0;        operationCode = 0;       operand = 0;        halt = false;         memory = memory1;}   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;         // Read next instruction from memory.    instructionRegister = memory.read(instructionCounter);   operationCode = getOperationCode(instructionRegister);   operand =getOperand(instructionRegister);        boolean transferOfControl = false;        //  execute the instruction.   switch (operationCode)  {       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;  }public void dump() { 
System.out.printf(" accumulator\t\t\t%+05d\n", accumulator); System.out.printf("instructionCounter\t\t %02d\n", instructionCounter); System.out.printf("instructionRegister\t\t%+05d\n", instructionRegister); System.out.printf("operationCode \t\t\t %02d\n", operationCode); 
System.out.printf("operand \t\t\t\t %02d\n", operand);

}public static void main(String[] args) 

 {         System.out.println("*** Welcome to Simpletron! ***");          System.out.println("*** Please enter your program one instruction   ***");         System.out.println("*** (or data word) at a time. I will display    ***");          System.out.println("*** the location number and a question mark (?) ***");         System.out.println("*** You then type the word for that location.   ***");          System.out.println("*** Type -99999 to stop entering your program.  ***");          System.out.println();     MachineClass machine = new MachineClass ();       machine.inputProgramToMemory();      machine.executeProgram();} }

class MachineClass {

private MemoryClass memory1; 
private RegistorClass registor1 ; 
public static final int MEMORY_WORD = 100;

public MachineClass(){       memory1=new MemoryClass( MEMORY_WORD);     registor1=new RegistorClass(memory1);}public void inputProgramToMemory() { 
Scanner input =new Scanner(System.in); 

int memoryWord=0;final int END_OF_INPUT = -9999;      System.out.printf("%02d ? ", memoryWord);int data = input.nextInt();while(data !=END_OF_INPUT)      {         memory1.write(memoryWord,data);   memoryWord++;   System.out.printf("%02d ? ", memoryWord);     data = input.nextInt();}           System.out.println("*** Program loading completed ***");           System.out.println(); }public void computerDump() { System.out.println(); 
System.out.println("REGISTERS:"); 
registor1.dump(); 
System.out.println(); 
System.out.println("MEMORY:"); 
memory1.dump(); } 

// Execute program  public void executeProgram(){        System.out.println("*** Program execution begins  ***");             while (  registor1.executeNextInstruction()) ;                 computerDump(); }}

class MemoryClass {

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

} // Write a value to memory.  public void write(int word, int value) {             if (word < 0 || word >= memory.length)        {               System.out.println("*** 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)        {      System.out.println("*** Attempt to read from a non-existing  memory location ***");          }        else value = memory[word];       return value;  }    public void dump() {          System.out.print( "   ");       for (int i = 0; i < 10; i++)       System.out.printf("%5d ", i);            System.out.println();            for (int i = 0; i < memory.length; i += 10)        {              System.out.print("  "+ i+ " ");              for (int j = 0; j < 10 && i+j < memory.length; j++)                       System.out.printf("%+05d ", memory[i + j]); //05>>> to print five digits ???                        System.out.println();         }  }









Related Tutorials/Questions & Answers:
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
GUI Interface - Java Beginners
GUI Interface  Respected sir, please send me the codimg of basic calculator,functionality must be include additon ,subtraction,division...); this.setTitle("Simple Calculator example
Advertisements
Gui Interface - Java Beginners
Gui Interface  hi I have two seperate interfaces in the same projects . my question is how can I access this interface using a jbutton (i.e jbutton = next where next points to another interface addCourse.java) What would
GUI problem - Java Beginners
GUI problem  how to write java program that use JTextField to input data and JTextField to display the output when user click Display Button??  Handle the actionPerformed event for JButton and try doing something like
GUI - Java Beginners
GUI testing  GUI testing in software testing  HiNow, use the code and get the answer.import javax.swing.*;public class DemoTryCatchDialog...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI Example.Thanks!!  This can be done using KeyEvent in the following way... written...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event
Component gui - Java Beginners
Component gui  Can you give me an example of Dialog in java Graphical user interface?  Hi friend, import javax.swing.*; public...://www.roseindia.net/java/example/java/swing/ Thanks
GUI - Java Beginners
://www.roseindia.net/java/example/java/swing/add_edit_and_delete_employee_inf.shtml
java GUI program - Java Beginners
java GUI program  java program that creates the following GUI, when user enter data in the textfield, the input will be displayed in the textarea... display in textarea example"); frame.setDefaultCloseOperation(JFrame.EXIT
java gui database - Java Beginners
java gui database  I have eight files. Each file has exactly same number(say 100) of entries. Each corresponding entry of all files correspond to one... gui. Could anybody help me. Thanks. Shah
Rental Code GUI - Java Beginners
Rental Code GUI  dear sir... i would like to ask some code of java GUI form that ask the user will choose the menu to input Disk #: type: title: record company: price: director: no. of copies
Convert this code to GUI - Java Beginners
Convert this code to GUI  I have written this.i need to convert the following code to GUI:- import java.awt.*; import java.applet.*; import...); } }  hi friend, We have convert your code into GUI
Java GUI IndexOf - Java Beginners
Java GUI IndexOf  Hello and thank you for having this great site. Here is my problem. Write a Java GUI application called Index.java that inputs several lines of text and a search character and uses String method indexOf
Writing a GUI program - Java Beginners
Writing a GUI program  Hello everyone! I'm trying to write a program that has a text field for input, two buttons and the output text area. A user... to write the code for the GUI. Could anyone please help?  Hi Friend
Java GUI Program - Java Beginners
Java GUI Program  How is the following program supposed to be coded? Write an application that prompts the user to enter the radius of a circle by Day 7 under a thread in your Team Forum called Week Three Program for 10 points
GUI testing/software testing - Java Beginners
GUI testing/software testing  how to create a GUI testing/software testing module in java
GUI convert to celsius program - Java Beginners
GUI convert to celsius program  how to write java GUI program to convert Fahrenheit to Celsius that need user to input value of Fahrenheit... information on Swing Examples visit to : http://www.roseindia.net/java/example
Java GUI problem with linklists and administration - Java Beginners
Java GUI problem with linklists and administration  Hi, I'm having trouble making a GUI interface in java, where a list of names are displayed using a jList. The java program should be able to allow the user to add names, remove
GUI and how to convert a distance - Java Beginners
GUI and how to convert a distance  i need help.. how to create a GUI application that can be is used to convert a distance unit in miles into its corresponding units in kilometer, meter, inches and centimeter. When a user
freemarker example - Java Beginners
freemarker example  hi, i am new to freemarker. please send me an example for freemarker. i want to get the values from java and display those...). and please provide an example with code and directory structure. send me ASAP
Example Code - Java Beginners
Example Code  I want simple Scanner Class Example in Java and WrapperClass Example. What is the Purpose of Wrapper Class and Scanner Class . when i compile the Scanner Class Example the error occur : Can not Resolve symbol
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
example explanation - Java Beginners
example explanation  can i have some explanation regarding the program given as serialization xample....  Hi friend, import java.io.*; import java.util.*; import java.util.Date; import java.io.Serializable
array example - Java Beginners
i cannot solve this example
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
GUI Example  GUI Example code to learn
GUI Interface .Reply me with in hour..Its Urgent - Java Beginners
GUI Interface .Reply me with in hour..Its Urgent  Hi ... Now i am... have to create GUI Interace ..How should i create the Interface. In Existing... a GUI interface with some 6 to 8 Vote symbols and should integrate with the already
Java Gui - Java Beginners
Java GUI - Java Beginners
java gui - Java Beginners
GUI - Java Beginners
Gui - Java Beginners
GUI - Java Beginners
java program example - Java Beginners
java program example  can we create java program without static and main?can u plzz explain with an example
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
MVC architecture example - Java Beginners
MVC architecture example  hi.. I would like to ask the example on Login authentication using MVC model. I really don't understand how it work. Can u give me some example of login authentication using JSP+Servlet+Javabeans
Java Example Update Method - Java Beginners
Java Example Update Method  I wants simple java example for overriding update method in applet . please give me that example
execution of image example program - Java Beginners
execution of image example program  sir. The example for the demo of image display in java,AwtImage.java,after the execution I can see only the frame used, but not the image to be displayed over it, even after selecting
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?  import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MarkStudent { double
OOPS Concept Abstraction with example - Java Beginners
). For example, the Java Collections Framework defines the abstraction called
linked list example problem - Java Beginners
linked list example problem  Q: Create your own linked list (do not use any of the classes provided in the Collections API). Implement the following two operations If you are using jdk1.4 or before
linked list example problem - Java Beginners
linked list example problem  Q: Create your own linked list (do not use any of the classes provided in the Collections API). Implement the following two operations If you are using jdk1.4 or before
GUI framework
GUI framework  what do u mean by GUI framework
GUI component
GUI component  How can a GUI component handle its own events
Convert the code to GUI
GUI code  GUI code
Real Time Example Interface and Abstract Class - Java Beginners
Real Time Example Interface and Abstract Class  Hi Friends, can u give me Real Time example for interface and abstract class.(With Banking Example
gui question
gui question  design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
GUI problem
GUI problem  Create a class called CDProgram and write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest Rate: 7.75 Hint

Ads