Author |
Message |
SilverSprite
|
Posted: Mon Jul 07, 2003 3:14 pm Post subject: Prompt |
|
|
How do you create a prompt? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Mon Jul 07, 2003 3:27 pm Post subject: (No subject) |
|
|
elaborate...? what do u mean? |
|
|
|
|
|
SilverSprite
|
Posted: Mon Jul 07, 2003 3:43 pm Post subject: (No subject) |
|
|
i need to prompt the user to enter two integers.. how would i write a class to do that? |
|
|
|
|
|
bugzpodder
|
Posted: Mon Jul 07, 2003 4:26 pm Post subject: (No subject) |
|
|
System.out.print would do |
|
|
|
|
|
Dan
|
Posted: Mon Jul 07, 2003 5:46 pm Post subject: (No subject) |
|
|
int num = JOptionPane.showInputDialog("Enter an int"); |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
SilverSprite
|
Posted: Mon Jul 07, 2003 6:14 pm Post subject: (No subject) |
|
|
thx dan.. |
|
|
|
|
|
rizzix
|
Posted: Mon Jul 07, 2003 6:15 pm Post subject: (No subject) |
|
|
heh but if u use dan's method.. then u need to import the javax.swing.* classes
EDIT: woops typo... corrected it |
|
|
|
|
|
SilverSprite
|
Posted: Mon Jul 07, 2003 6:30 pm Post subject: (No subject) |
|
|
Hacker Dan wrote: int num = JOptionPane.showInputDialog("Enter an int");
i get an incompatible types error.. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rizzix
|
Posted: Mon Jul 07, 2003 6:56 pm Post subject: (No subject) |
|
|
it will return a string... the documentation says so.
do this to conver teh string object to an int:
code: |
int num = Integer.parseInt(JOptionPane.showInputDialog("Enter an int"));
|
EDIT: based on bugzpodder recomendation.. which is the better way out.. |
|
|
|
|
|
bugzpodder
|
Posted: Mon Jul 07, 2003 7:51 pm Post subject: (No subject) |
|
|
parseInt is the way to go. if you look on the hand out you'll see. |
|
|
|
|
|
rizzix
|
Posted: Mon Jul 07, 2003 8:08 pm Post subject: (No subject) |
|
|
icic.. nice |
|
|
|
|
|
SilverSprite
|
Posted: Mon Jul 07, 2003 9:09 pm Post subject: (No subject) |
|
|
oh.. thx all |
|
|
|
|
|
w0lv3rin3
|
Posted: Sat Sep 13, 2003 8:59 pm Post subject: (No subject) |
|
|
Small example
code: |
inNumber1 = new DialogBox(screen,"Input first integer");
inNumber2 = new DialogBox(screen, "Input second integer");
inNumber1.showDialogBox();
number1 = inNumber1.getInteger();
inNumber2.showDialogBox();
number2 = inNumber2.getInteger();
sum = number1 + number2;
difference = number1 - number2;
product = number1 * number2;
quotient = (float)number1 / number2;
remainder = number1 % number2;
screen.write("\n=========================================");
screen.write("\nSum\tDifference\tProduct\tQuotient\tRemainder");
screen.write("\n"+ sum + "\t\t" + difference + "\t\t\t\t" + product + "\t\t\t" + quotient + "\t\t" + remainder);
screen.write("\n=========================================\n"); |
|
|
|
|
|
|
rizzix
|
Posted: Sun Sep 14, 2003 10:57 am Post subject: (No subject) |
|
|
w0lv3rin3, thats JavaScript not Java. Thanks anyways. |
|
|
|
|
|
w0lv3rin3
|
Posted: Sun Sep 14, 2003 11:31 am Post subject: (No subject) |
|
|
r you kidding me, ur a biggest newb, THAT IS JAVA that code i just posted. omfg, im in college right now, and my professor just taught me that code, for a beginner code. |
|
|
|
|
|
|