Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: I cannot get the example to compile, a problem with JOption.showMessageDialoug

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Rep Power
    0

    Question I cannot get the example to compile, a problem with JOption.showMessageDialoug

    Java Code:
    import javax.swing.*;    //Needed for Swing classes
    import java.awt.event.*; //Needed for event listener interface
    import javax.swing.JOptionPane;
    /**
       This class demonstrates how to retrieve the action command
       from an event object.
    */
    
    public class EventObject extends JFrame
    {
       private JButton button1; //Button 1
       private JButton button2; //Button 2
       private JButton button3; //Button 3
       private JPanel panel;    //A panel to hold components
       private final int WINDOW_WIDTH = 300; //Window width
       private final int WINDOW_HEIGHT = 70; //Window height
       
       /**
          Constructor
       */
       
       public EventObject()
       {
          //Set the title bar text
          setTitle("Event Object Demostration");
          
          //Set the size of the window
          setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
          
          //Specify what happens when the close button is clicked 
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
          //Create the three buttons
          button1 = new JButton("Button 1");
          button2 = new JButton("Button 2");
          button3 = new JButton("Button 3");
          
          //Register an event listener with all three buttons
          button1.addActionListener(new ButtonListener());
          button2.addActionListener(new ButtonListener());
          button3.addActionListener(new ButtonListener());
          
          //Create a panel and add the buttons to it.
          panel = new JPanel();
          panel.add(button1);
          panel.add(button2);
          panel.add(button3);
          
          //Add panel to the content pane
          add(panel);
          
          //Display the window
          setVisible(true);
       }  
       
       /**
          Private inner class that handles the event when the user clicks a button
       */
       
       private class ButtonListener implements ActionListener
       {
          public void actionPerformed(ActionEvent e)
          {
          
             //Get the action command
             String actionCommand = e.getActionCommand();
             
             //Determine which button was clicked and display a message
             if(actionCommand.equals("Button 1"))
             {
                JOptionPane.showMessgeDialog(null, "You clicked the first button.");
             }
             else if (actionCommand.equals("Button 2"))
             {
                JOptionPane.showMessgeDialog(null, "You clicked the second button.");
             }
             else if (actionCommand.equals("Button 3"))
             {
                JOptionPane.showMessgeDialog(null, "You clicked the third button.");
             }
          }
       }
       
       /**
          main method
       */
       
       public static void main(String[] args)
       {
          new EventObject();
       }
    }
    EventObject.java:71: error: cannot find symbol
    JOptionPane.showMessgeDialog(null, "You clicked the first button.");
    ^
    symbol: method showMessgeDialog(<null>,String)
    location: class JOptionPane
    EventObject.java:75: error: cannot find symbol
    JOptionPane.showMessgeDialog(null, "You clicked the second button.");
    ^
    symbol: method showMessgeDialog(<null>,String)
    location: class JOptionPane
    EventObject.java:79: error: cannot find symbol
    JOptionPane.showMessgeDialog(null, "You clicked the third button.");
    ^
    symbol: method showMessgeDialog(<null>,String)
    location: class JOptionPane
    3 errors
    Last edited by April.Slawson92; 04-21-2017 at 07:04 PM. Reason: Moderator

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,948
    Rep Power
    30

    Default Re: I cannot get the example to compile, a problem with JOption.showMessageDialoug

    If there are compiler error messages, please copy the full text of the error message and paste it here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    April.Slawson92 likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,948
    Rep Power
    30

    Default Re: I cannot get the example to compile, a problem with JOption.showMessageDialoug

    error: cannot find symbol
    Make sure the spelling and args are correct.
    Go to the API doc, copy the source statement from there for calling the method and paste it in code about your code.
    Compare the two lines to see what is different.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    MoreOnJava is offline Member
    Join Date
    Mar 2017
    Posts
    1
    Rep Power
    0

    Unhappy Re: I cannot get the example to compile, a problem with JOption.showMessageDialoug

    Hi,

    Looks like you forgot the letter "a" in "showMessageDialog" - you are spelling as "showMessgeDialog"

Similar Threads

  1. I need help with JOption Panel!
    By jakex69 in forum New To Java
    Replies: 3
    Last Post: 01-26-2012, 04:08 AM
  2. Region and Language problem in Joption
    By rjain in forum New To Java
    Replies: 0
    Last Post: 11-04-2011, 11:19 AM
  3. Example of JOption
    By RanLineR in forum New To Java
    Replies: 4
    Last Post: 10-20-2010, 12:27 PM
  4. JOption pop up window is behind all other windows
    By biggmann in forum New To Java
    Replies: 3
    Last Post: 10-15-2010, 08:24 PM
  5. JOption Msgbox title help?
    By ZaabZ in forum New To Java
    Replies: 7
    Last Post: 08-26-2010, 09:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •