Results 1 to 20 of 20

Thread: Simple Variable Problem

  1. #1
    DaoK
    Guest

    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 ?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3
    DaoK
    Guest
    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.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  5. #5
    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.

  6. #6
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  7. #7
    DaoK
    Guest
    I put ShowMessageDialog with a capital D.
    I put import java.lang.String; with capital S

    still haev the error.

  8. #8
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    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.

  9. #9
    Originally posted by Wynd


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

  10. #10
    DaoK
    Guest
    Code:
    resultat.toString()
    Didnt work..... I don't know but it seem to be basic code...Why is that so hard to fix :\

  11. #11

  12. #12
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    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)

  13. #13
    DaoK
    Guest
    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 ?

  14. #14
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Originally posted by filburt1


    I just said that.
    I know, that's why I quoted you
    Alcohol & calculus don't mix.
    Never drink & derive.

  15. #15
    VirtuallyVB
    Guest

    Thumbs up

    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.

  16. #16
    DaoK
    Guest
    I put Integer.toString(resultat) before the last JOptionPanel and I have the same error .

  17. #17
    DaoK
    Guest
    Anyone here have tested the code in his Jbuilder? I need to know why it dont work.

  18. #18
    VirtuallyVB
    Guest

    Wink 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
    );
    }
    }

  19. #19
    DaoK
    Guest
    T H A N K you

  20. #20
    VirtuallyVB
    Guest

    Question

    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
  •  



Click Here to Expand Forum to Full Width