PDA

Click to See Complete Forum and Search --> : Simple Variable Problem


DaoK
Aug 30th, 2001, 03:35 PM
I know that code is really basic but It show my question:

package test2;
import javax.swing.JOptionPane;
public class test2 {
public static void main ( String args [])
{
int x,
y,
z,
resultat;
String xVal,
yVal,
zVal;
xVal =
JOptionPane.showInputDialog ( "Voyez entrer un nombre" );
yVal =
JOptionPane.showInputDialog ( "Voyez entrer un secon nombre");
zVal =
JOptionPane.showInputDialog ( "Voyez entrer un dernier nombre");
x = Integer.parseInt (xVal);
y = Integer.parseInt (yVal);
z = Integer.parseInt (zVal);
resultat = ( x * y * z );

JOptionPane.showMessageDialog (
null, resultat, "Le produit est : ",
JOptionPane.INFORMATION_MESSAGE);
}
}


I have an error on that line : null, resultat, "Le produit est : ",
Why I have an error ?

crptcblade
Aug 30th, 2001, 03:48 PM
perhaps if you told what error you are getting, it would be easier to tell you why

:)

DaoK
Aug 30th, 2001, 03:53 PM
method showmessagedialog(null, int, java.lang.string, int) not found in class javax.swing.JOptionPanel.


I added the java.lang.string but that did the same message.

crptcblade
Aug 30th, 2001, 04:00 PM
That error means that showmessagedialog is not a known method of the JOptionPanel class. I don't have access to my documentation right now, but check the case of the of showmessagedialog, make sure its not supposed to be ShowMessageDialog or something, and make sure you have the arguments in the correct order

:)

filburt1
Aug 30th, 2001, 04:03 PM
Originally posted by DaoK
method showmessagedialog(null, int, java.lang.string, int) not found in class javax.swing.JOptionPanel.


I added the java.lang.string but that did the same message.

java.lang.String (capital S). And you don't technically need to do java.lang.Whatever, as java.lang.* is automatically imported in all classes.

Wynd
Aug 30th, 2001, 04:10 PM
I think the second parameter has to be a string.

JOptionPane.showMessageDialog(NULL, resultat.toString(), "Le produit est : ", JOptionPane.INFORMATION_MESSAGE);

DaoK
Aug 30th, 2001, 04:30 PM
I put ShowMessageDialog with a capital D.
I put import java.lang.String; with capital S

still haev the error.

Wynd
Aug 30th, 2001, 06:55 PM
Originally posted by filburt1
And you don't technically need to do java.lang.Whatever, as java.lang.* is automatically imported in all classes.

You don't need to include it. By the way, did you try my idea?

filburt1
Aug 30th, 2001, 06:59 PM
Originally posted by Wynd


You don't need to include it. By the way, did you try my idea?

I just said that.

DaoK
Aug 30th, 2001, 08:57 PM
resultat.toString()

Didnt work..... I don't know but it seem to be basic code...Why is that so hard to fix :\

Dillinger4
Aug 30th, 2001, 09:20 PM
I never heard of the JOptionPanel class do you mean JOptionPane?

Dillinger4
Aug 30th, 2001, 09:26 PM
These are the three you want

public static void showMessageDialog(Component parentComponet, Object Message )

public static void showMessageDialog(Component parentComponet, Object Message, String title, int messageType)


public static void showMessageDialogComponent parentComponet, Object Message, String title, int messageType
Icon icon)

DaoK
Aug 31st, 2001, 04:07 PM
That my code :


package test2;
import javax.swing.JOptionPane;
public class test2 {
public static void main ( String args [])
{
int x,
y,
z,
resultat;
String xVal,
yVal,
zVal;
xVal =
JOptionPane.showInputDialog ( "Voyez entrer un nombre" );
yVal =
JOptionPane.showInputDialog ( "Voyez entrer un secon nombre");
zVal =
JOptionPane.showInputDialog ( "Voyez entrer un dernier nombre");
x = Integer.parseInt (xVal);
y = Integer.parseInt (yVal);
z = Integer.parseInt (zVal);
resultat = ( x * y * z );

JOptionPane.showMessageDialog (
null, resultat, "Le produit est : ",
JOptionPane.INFORMATION_MESSAGE);
}
}



I didnt wrote panel... ok why he cant read : resultat but he can read x ?

Wynd
Aug 31st, 2001, 06:42 PM
Originally posted by filburt1


I just said that.
I know, that's why I quoted you :)

VirtuallyVB
Aug 31st, 2001, 07:41 PM
Yes, the second argument can be an Object of type String, but it takes any type Object as well. Unfortunately, int is not an Object.

Integer.toString(resultat)
is acceptable as is
new Integer(resultat)

JOptionPane.showMessageDialog (
null, Integer.toString(resultat), "Le produit est : ", JOptionPane.INFORMATION_MESSAGE
);

JOptionPane.showMessageDialog (
null, new Integer(resultat), "Le produit est : ", JOptionPane.INFORMATION_MESSAGE
);

The compiler was saying that it cannot find a method for class JOptionPane named showMessageDialog which takes the datatypes that you provided in the order you provided.

I prefer when the compiler says
required: Object
found: int
I'm not certain as to when you get the more descriptive form.

DaoK
Aug 31st, 2001, 09:02 PM
I put Integer.toString(resultat) before the last JOptionPanel and I have the same error .

DaoK
Sep 1st, 2001, 02:24 PM
Anyone here have tested the code in his Jbuilder? I need to know why it dont work.

VirtuallyVB
Sep 1st, 2001, 11:23 PM
It worked fine in notepad and compiled and invoked fine from a Dos shell.

If you keep adding that lower-case "L" to JOptionPane, I'm going to smack you. Just kidding. ;)

Cut and paste this:

import javax.swing.JOptionPane;

public class T {
public static void main ( String args []) {
int x,
y,
z,
resultat;
String xVal,
yVal,
zVal;
xVal = JOptionPane.showInputDialog ( "Voyez entrer un nombre" );
yVal = JOptionPane.showInputDialog ( "Voyez entrer un secon nombre");
zVal = JOptionPane.showInputDialog ( "Voyez entrer un dernier nombre");

x = Integer.parseInt (xVal);
y = Integer.parseInt (yVal);
z = Integer.parseInt (zVal);
resultat = ( x * y * z );

JOptionPane.showMessageDialog (
null, Integer.toString(resultat), "Le produit est : ", JOptionPane.INFORMATION_MESSAGE
);
}
}

DaoK
Sep 2nd, 2001, 12:45 PM
T H A N K you :)

VirtuallyVB
Sep 2nd, 2001, 11:12 PM
You're welcome.

What's the predicted weather in Canada this week? We're expecting highs of 90 F and lows of 70 F.