Start New Discussion within our Software Development Community

I did it without using GUI because i am not sure how to do in GUI.I need help to put these code in GUI.

import java.util.Scanner;
 import java.util.Stack;

 /**
 This calculator uses the reverse polish notation.
 */
public class Calculator
 {
 public static void main(String[] args)
 {
 Scanner in = new Scanner(System.in);
 Stack<Integer> results = new Stack<Integer>();
 System.out.println("Enter one number or operator per line, Q to quit. ");
 boolean done = false;
 while (!done)
 {
 String input = in.nextLine();

 // If the command is an operator, pop the arguments and push the result

 if (input.equals("+"))
 {
 results.push(results.pop() + results.pop());
 }
 else if (input.equals("-"))
 {

 Integer arg2 = results.pop();
 results.push(results.pop() - arg2);
}
 else if (input.equals("*") || input.equals("x"))
 {
 results.push(results.pop() * results.pop());
 }
 else if (input.equals("/"))
 {
 Integer arg2 = results.pop();
 results.push(results.pop() / arg2);
 }
 else if (input.equals("Q") || input.equals("q"))
 {
 done = true;
 }
 else
 {
 // Not an operator—push the input value

 results.push(Integer.parseInt(input));
 }
 System.out.println(results);
 }
 }
}

and what exactly is your question?
1. decide what kind of gui you want
2. check what frameworks or libraries you'll need
3. read up on some tutorials
4. start coding

if you have some problems with the code, ask them, but don't expect us to completely write a GUI for you.

I assume you mean a Swing - GUI, so you may want to check the Swing tutorials oracle provides.

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