Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JOptionPane in Swing

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JOptionPane in Swing

    I tried compiling this code but got an error in line 14. I don't understand what my problem is.
    Here is the error that I encountered:
    JOptionPane.java:14: error: cannot find symbol
    JOptionPane.showMessageDialog(frame,"Content");
    ^
    symbol: method showMessageDialog(JFrame,String)
    location: class JOptionPane
    1 error

    Can anyone help me?

    import java.awt.*;
    import javax.swing.*;

    class JOptionPane
    {

    JFrame frame;

    public void CreateFrame()
    {
    frame = new JFrame("Testing");
    frame.setLayout(null);
    frame.setBounds(0,0,500,400);
    JOptionPane.showMessageDialog(frame,"Content");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    frame.setVisible(true);

    }

    public static void main(String args[])
    {
    JOptionPane obj = new JOptionPane();
    obj.CreateFrame();
    }

    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: JOptionPane in Swing

    class JOptionPane
    You are trying to define your own version of the Java SE class JOptionPane.
    Rename that declaration so the code uses the Java SE one.

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

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

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. JOptionPane help
    By vysero in forum What's Wrong With My Code?
    Replies: 25
    Last Post: September 24th, 2014, 02:54 PM
  2. JOptionPane
    By Kazeth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 29th, 2014, 11:42 PM
  3. [SOLVED] JOptionPane
    By colognem in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 13th, 2014, 06:45 AM
  4. need help in JOptionPane
    By Zuckerberg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2014, 07:08 AM
  5. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM

Tags for this Thread