|
-
Aug 30th, 2001, 03:35 PM
#1
Simple Variable Problem
I know that code is really basic but It show my question:
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 have an error on that line : null, resultat, "Le produit est : ",
Why I have an error ?
-
Aug 30th, 2001, 03:48 PM
#2
perhaps if you told what error you are getting, it would be easier to tell you why
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 30th, 2001, 03:53 PM
#3
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.
-
Aug 30th, 2001, 04:00 PM
#4
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
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 30th, 2001, 04:03 PM
#5
Member
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.
-
Aug 30th, 2001, 04:10 PM
#6
Fanatic Member
I think the second parameter has to be a string.
Code:
JOptionPane.showMessageDialog(NULL, resultat.toString(), "Le produit est : ", JOptionPane.INFORMATION_MESSAGE);
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 30th, 2001, 04:30 PM
#7
I put ShowMessageDialog with a capital D.
I put import java.lang.String; with capital S
still haev the error.
-
Aug 30th, 2001, 06:55 PM
#8
Fanatic Member
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?
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 30th, 2001, 06:59 PM
#9
Member
Originally posted by Wynd
You don't need to include it. By the way, did you try my idea?
I just said that.
-
Aug 30th, 2001, 08:57 PM
#10
Code:
resultat.toString()
Didnt work..... I don't know but it seem to be basic code...Why is that so hard to fix :\
-
Aug 30th, 2001, 09:20 PM
#11
Dazed Member
I never heard of the JOptionPanel class do you mean JOptionPane?
-
Aug 30th, 2001, 09:26 PM
#12
Dazed Member
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)
-
Aug 31st, 2001, 04:07 PM
#13
That my code :
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 ?
-
Aug 31st, 2001, 06:42 PM
#14
Fanatic Member
Originally posted by filburt1
I just said that.
I know, that's why I quoted you
Alcohol & calculus don't mix.
Never drink & derive.
-
Aug 31st, 2001, 07:41 PM
#15
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.
-
Aug 31st, 2001, 09:02 PM
#16
I put Integer.toString(resultat) before the last JOptionPanel and I have the same error .
-
Sep 1st, 2001, 02:24 PM
#17
Anyone here have tested the code in his Jbuilder? I need to know why it dont work.
-
Sep 1st, 2001, 11:23 PM
#18
You'll get it
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
);
}
}
-
Sep 2nd, 2001, 12:45 PM
#19
T H A N K you
-
Sep 2nd, 2001, 11:12 PM
#20
You're welcome.
What's the predicted weather in Canada this week? We're expecting highs of 90 F and lows of 70 F.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|