Java Frames

Discussion in 'Programming General' started by Runescape_Mod, Jan 8, 2010.

Java Frames
  1. Unread #1 - Jan 8, 2010 at 9:55 AM
  2. Runescape_Mod
    Joined:
    Aug 11, 2008
    Posts:
    1,607
    Referrals:
    0
    Sythe Gold:
    0

    Runescape_Mod Guru

    Java Frames

    Hey I am making a program and I want for when you press a JButton for the current window to close and a new window to open... if i try setting the visibility to false it wont work because the actionlistener is in a different method so it cant find the original created frame. if anyone has tips that would be great. thanks =)
     
  3. Unread #2 - Jan 8, 2010 at 12:49 PM
  4. d great one
    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0

    d great one Apprentice

    Java Frames

    I think you have to use .dispose(); on the window to close. Though it will dispose the codes... not sure.
    Just try this.dispose();
     
  5. Unread #3 - Jan 8, 2010 at 6:59 PM
  6. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Java Frames

    I assume that you're storing the first JFrame as a local field, and so, you are unable to access the instance you created from javax.swing.JFrame in a different method.

    If the above is the case, there are several things that you can do to fix it.
    • Rather then storing the JFrame instance in a local field, store it in an instance/class variable so that you can access it from a different method. (Recommended)
    • Rather then implementing ActionListener in your class, create an inner ActionListener class within your method. If you mark you add the 'final' access modifier to your JFrame local field, that inner class can access it.
     
  7. Unread #4 - Jan 19, 2010 at 7:51 PM
  8. Runescape_Mod
    Joined:
    Aug 11, 2008
    Posts:
    1,607
    Referrals:
    0
    Sythe Gold:
    0

    Runescape_Mod Guru

    Java Frames

    Hey I figured it out, thanks for the help =)
     
< Mp3 Renamer | Need some help making a useful program. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site