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 5 of 5

Thread: Why can't I close my JFrame ?

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why can't I close my JFrame ?

    This is just a small piece of the code, but when I run this I get an error.

    private void buildGUI() {
    		addressView = new JXAddressView();
    		addressView.setData(this);
    		JFrame frame = new JFrame();
    		JPanel p = addressView.getViewPanel();
    		frame.setContentPane(p);
    		frame.pack();
    		frame.setVisible(true);
    		frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}

    I get this error:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    EXIT_ON_CLOSE cannot be resolved to a variable

    at JXplorer.buildGUI(JXplorer.java:32)
    at JXplorer.main(JXplorer.java:21)


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Why can't I close my JFrame ?

    EXIT_ON_CLOSE is a static variable in the JFrame class. It can't find a variable named EXIT_ON_CLOSE in your current class, because you haven't specified one.

    Hint: to refer to a static variable from another class, you use ClassName.VARIABLE_NAME
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why can't I close my JFrame ?

    I still don't know what to do?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Why can't I close my JFrame ?

    For example, the Component class contains several static variables for alignment. If I want to refer to the static variable CENTER_ALIGNMENT of the Component class, I type:

    Component.CENTER_ALIGNMENT

    Simply referencing CENTER_ALIGNMENT without the class name is not enough, as Java has no idea where to look, which is why it says it can't find the variable.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why can't I close my JFrame ?

    It works! Thanks for the quick replies!

Similar Threads

  1. Close jframe
    By takamine in forum AWT / Java Swing
    Replies: 4
    Last Post: February 3rd, 2013, 02:16 PM
  2. problem with my JFrame; JFrame not closing and stay in background
    By golominator in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 6th, 2012, 08:20 AM
  3. Is this correct.Am I close? Help please
    By eagle09 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 26th, 2011, 08:26 AM
  4. [SOLVED] How to close all tabs in JTabbedPane?
    By LeonLanford in forum AWT / Java Swing
    Replies: 7
    Last Post: June 28th, 2010, 11:58 AM
  5. Do I need to close an audio clip?
    By m2oswald in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 8th, 2010, 02:20 AM