Results 1 to 3 of 3
  1. #1
    RayDunster is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Removing panels from a seperate class

    So, for the final project in my Comp.Sci class, we have to keep all of our classes at 200 lines or less. So, I decided to have the main code in one class and all the panels for the GUI in another. It's working well, the panel from the class shows up and everything, but for some reason it's not being removed. Here's what our code looks like:

    Java Code:
     public boolean action (Event e, Object o)
        {    
            if (e.target instanceof Button)
            {
                if (e.target == begin)
                {
                    remove (x);
                    remove (y);                
                    
                    x = screen.nextScreen(goNext);
    
                    add (x);
                    
                    validate();
                }    
    
                if (e.target == goNext)
    
                {       
                    remove (x);
    
                    x = screen.menu();
    
                    add (x, "South");
                    validate();
    
                }
    Where "screen.x" is the class with all the panels. Are we missing something? We're not sure why the "remove (x);" isn't removing the screen and why "add (x, "South");" isn't adding the next panel. If I was too vague in posting this, please feel free to ask questions!

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Removing panels from a seperate class

    FWIW, read the API - the action method has been deprecated since java 1.1 (considering the current released version is java 7, that's a long time)!
    Component (Java Platform SE 6)
    You should use listeners instead( eg ActionListener )
    For your problem as it stands, add some println's in there to make sure the code you expect to run is actually being ran.

  3. #3
    RayDunster is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Removing panels from a seperate class

    Hey! That worked! The sample code our teacher provided us with was obviously fairly outdated. All the buttons are working fine, and all the screens are coming and going as planned, thanks!

    Uh, as another question, is there a way to use layers in java? Like, I know it's possible, but is there a simple way? For example, there's a menu at the back and there are a series of buttons/labels on top of it. Furthermore, is there a way to remove the labels and buttons, or rather replace them with a new set of buttons and labels?

Similar Threads

  1. Replies: 1
    Last Post: 11-06-2011, 11:18 PM
  2. Help displaying an array from a seperate class
    By aeon1613 in forum New To Java
    Replies: 2
    Last Post: 01-16-2011, 08:15 AM
  3. Keyboard Input In A Seperate Class?
    By FatalSylence in forum New To Java
    Replies: 6
    Last Post: 10-12-2010, 05:29 AM
  4. Manipulating components of a seperate GUI Class
    By ribbs2521 in forum New To Java
    Replies: 1
    Last Post: 10-20-2009, 10:53 PM
  5. Adding and removing panels dynamically
    By kbyrne in forum AWT / Swing
    Replies: 1
    Last Post: 04-12-2008, 08:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •