• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Exit button closing a single frame

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all. I have GUI app that involves multiple frames. On the home frame (the first frame that appears when running the app) I have buttons that open a new frame when clicked. Included in these frames is a exit button that I want to close only the frame that it resides in when clicked. Below is the ActionListener the exit button used in one of the frames. MainWindow is the name of the class.



This code gives me the error "non-static method dispose() cannot be referenced from a static context MainWindow.dispose();"
                                                                                                  ^

Any assistance would be greatly appreciated.

 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming your MainWindow class extends JFrame (which it shouldn't do by the way, you should give it a private JFrame field instead), you should call the dispose() method on this (or preferably, the private field).
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have GUI app that involves multiple frames.



First of all you should not be using multiple JFrames. Generally speaking an application should only have a single JFrame. Child windows should be JDialogs.

This code gives me the error "non-static method dispose() cannot be referenced from a static context MainWindow.dispose();"



You can use the ActionEvent object to access the frame you want to close:


You can also check out Closing an Application for a simple API to handle closing of the frame.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic