
-----------------------------------
SilverSprite
Mon Jul 07, 2003 3:14 pm

Prompt
-----------------------------------
How do you create a prompt?

-----------------------------------
rizzix
Mon Jul 07, 2003 3:27 pm


-----------------------------------
elaborate...? what do u mean?

-----------------------------------
SilverSprite
Mon Jul 07, 2003 3:43 pm


-----------------------------------
i need to prompt the user to enter two integers.. how would i write a class to do that?

-----------------------------------
bugzpodder
Mon Jul 07, 2003 4:26 pm


-----------------------------------
System.out.print would do

-----------------------------------
Dan
Mon Jul 07, 2003 5:46 pm


-----------------------------------
int num = JOptionPane.showInputDialog("Enter an int");

-----------------------------------
SilverSprite
Mon Jul 07, 2003 6:14 pm


-----------------------------------
thx dan..

-----------------------------------
rizzix
Mon Jul 07, 2003 6:15 pm


-----------------------------------
heh but if u use dan's method.. then u need to import the javax.swing.* classes


EDIT: woops typo... corrected it

-----------------------------------
SilverSprite
Mon Jul 07, 2003 6:30 pm


-----------------------------------
int num = JOptionPane.showInputDialog("Enter an int");
i get an incompatible types error..

-----------------------------------
rizzix
Mon Jul 07, 2003 6:56 pm


-----------------------------------
it will return a string... the documentation says so.


do this to conver teh string object to an int:


int num =  Integer.parseInt(JOptionPane.showInputDialog("Enter an int"));


EDIT: based on bugzpodder recomendation.. which is the better way out..

-----------------------------------
bugzpodder
Mon Jul 07, 2003 7:51 pm


-----------------------------------
parseInt is the way to go.  if you look on the hand out you'll see.

-----------------------------------
rizzix
Mon Jul 07, 2003 8:08 pm


-----------------------------------
icic.. nice   :o

-----------------------------------
SilverSprite
Mon Jul 07, 2003 9:09 pm


-----------------------------------
oh.. thx all

-----------------------------------
w0lv3rin3
Sat Sep 13, 2003 8:59 pm


-----------------------------------
Small example


        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
Sun Sep 14, 2003 10:57 am


-----------------------------------
w0lv3rin3, thats JavaScript not Java. Thanks anyways.

-----------------------------------
w0lv3rin3
Sun Sep 14, 2003 11:31 am


-----------------------------------
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.

-----------------------------------
rizzix
Sun Sep 14, 2003 11:41 am


-----------------------------------
what packages do you need to import? That code does not look like any familiar code to me.

based on the following i presumed it was javascript.

you variables are not declared but directly defined.
screen.write(""); is something i'm sure java does not have.

anyways.. you might be using what is known as bsh or the bean shell.
i don't know much of the bean shell syntax. but it's supposed to be the Java scripting language. Technically any valid java code is a valid beanshell code. but not the other way round.


but if it is java that code won't compile. (as i said what packages do i need to import?)

-----------------------------------
w0lv3rin3
Sun Sep 14, 2003 2:16 pm


-----------------------------------
here is full code from a program I was pratcing on:

packages needed are avi.*


import avi.*;



//this is line comment for the human eye
//the compiler completely ignores comments
/*this is a block comment and allows you
 * to put block comments. Use this style
 * when you need more than a line comment
 */
//import java.lang.*; 
import avi.*;
public class Hello //class name
{ //the beginning of the class definition
    public static void main(String[] args)
    {  
        Window screen = new Window("Testing","bold+italics","red",30);
        DialogBox inNumber1, inNumber2;
        //can do it in a seperate statement
        inNumber1 = new DialogBox(screen,"Input first integer");
        inNumber2 = new DialogBox(screen, "Input second integer");
        
        int number1, number2, sum, difference, product, remainder;
        float quotient;
        float fnum1 = 3.1f;
        double dnum1 = 3.3;
        short snum1 = 2;
        long lnum1 = 3;
        char cnum1 = 'q';
        boolean ans = false;
        
        int example1 = 3/2;
        float example2 = 3/2;
        //how to do the right arithmetic
        float example3 = 3.0f/2;
        //alternative way
        float example4 = (float)3/2;
        float example5 = (float)3 / 2 + 4 * 6;
        double example6 = 3.0/2;
        final float PI = 3.14f;
        //these two statements can replace the above statement
        //final float PI;
        //PI = 3.14f;
        //the next statement will give compilation error
        //PI = 2.3f;
        dnum1 = fnum1;//this is allowed
        fnum1 = (float)dnum1;//this is not allowed, want to do it
        number1 = 10;
        number2 = 5;
        screen.showWindow();
        //we will now use DialogBox class to take input
        //instead of hard coded data
        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("Number1 = " + number1 + " and Number2 = " + number2);
        screen.write("\nSum = "+ sum);
        screen.write("\nDifference = "+ difference);
        screen.write("\nProduct = "+ product);
        screen.write("\nQuotient = "+ quotient);
        screen.write("\nRemainder = "+ remainder);
        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");
        screen.write("Example1 = " + example1);
        screen.write("\nExample2 = " + example2);
        screen.write("\nExample3 = " + example3);
        screen.write("\nExample4 = " + example4);
        screen.write("\nExample5= " + example5);
        screen.write("\nExample6= " + example6);
        screen.write("\nDouble = " + dnum1);
        screen.write("\nFloat = " + fnum1);
        
        screen.write("\nHello to all of you");
       // System.out.println("Hello to all of you");
    }
}

-----------------------------------
rizzix
Sun Sep 14, 2003 9:20 pm


-----------------------------------
o ok.. ur using non-standard packages.. ur ehm.. college provides.
thats cool. although you can learn java with the standard packages.

-----------------------------------
nate
Mon Sep 15, 2003 9:48 pm


-----------------------------------
for a college student you sure don't know your grammar.

ur a biggest newb


-----------------------------------
Tony
Mon Sep 15, 2003 9:59 pm


-----------------------------------
yeah... there should be a rule that when you post java code that implements non standart packages, please include all the "include..." lines so the rest of us wouldn't have to guess  :wink: 

maybe rizzix should write it up, he knows Java better then I do

-----------------------------------
rizzix
Wed Sep 17, 2003 4:27 pm


-----------------------------------
yea i'd agree tony. there are far too many java-like scripting variants that look similar to java. it get's pretty confusing at times. I mean java code is 100% bean shell compatible yet not the other way round (i.e bsh code is not 100% java compatible). speaking of which do check out this awsome scripting language @ www.beanshell.org .. and don't be to hard on that dude, he probably got offended for some reason :?
