Adblock breaks this site

Java Frames

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

  1. Runescape_Mod

    Runescape_Mod Guru

    Joined:
    Aug 11, 2008
    Posts:
    1,607
    Referrals:
    0
    Sythe Gold:
    0
    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 =)
     
  2. d great one

    d great one Apprentice

    Joined:
    Nov 4, 2007
    Posts:
    930
    Referrals:
    2
    Sythe Gold:
    0
    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();
     
  3. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    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.
     
  4. Runescape_Mod

    Runescape_Mod Guru

    Joined:
    Aug 11, 2008
    Posts:
    1,607
    Referrals:
    0
    Sythe Gold:
    0
    Java Frames

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


 
 
Adblock breaks this site