Soooooo, I'm just starting out in a Java programming class and our first assignment was to create some simple programs to add, subtract, multiply, and divide two integers (which I was able to figure out from one of his handouts and a lot of googling - don't laugh at my frankencode below).
Anyway, the way I have the programs set up right now, (ssing JCreator), I input my numbers in the "General Output" section at the bottom of the screen. My professor had showed us how to make windows pop up in class though (using the JOptionPane.showMessageDialog deal), and I thought it would be fun if I could make it possible to input my numbers for adding and subtracting, etc... pop up in those windows so the user could input them in a less ghetto fashion.
So does anyone know a way to do this, or can you point me in the direction to find out? I've googled it, but I can't seem to find what I'm trying to do. I'm sure its incredibly basic, I'm just brand new, don't know a thing, and don't know what the hell to try.
Here's the code I've got so far for an addition program (it works but like I said, I want windows to pop up). Thanks for any info, and if anyone is a game programmer and you wanna share what you did to get to that point, please let me know cuz that's my goal!
import java.io.*; //needed to access input stream class import java.util.Scanner;
public class XYAdd
public static void main (String  args)
Scanner input = new Scanner (System.in);
int x; //first number to add int y; //second number to add int Total; //sum of x and y
//set up the basic input stream
System.out.println ("Enter x");
x = input.nextInt(); //read first number from user //using the scanner class
System.out.println ("Enter y");
y = input.nextInt(); //read second number from user
Total = x + y; //add numbers
System.out.printf ("Total is %d\n", Total); //display total
} Reply with quote