Results 1 to 3 of 3
- 01-18-2012, 07:07 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
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:
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!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(); }
- 01-18-2012, 07:48 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
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.
- 01-19-2012, 07:38 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
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
-
loading images from seperate class and drawing them
By ccub in forum Java 2DReplies: 1Last Post: 11-06-2011, 11:18 PM -
Help displaying an array from a seperate class
By aeon1613 in forum New To JavaReplies: 2Last Post: 01-16-2011, 08:15 AM -
Keyboard Input In A Seperate Class?
By FatalSylence in forum New To JavaReplies: 6Last Post: 10-12-2010, 05:29 AM -
Manipulating components of a seperate GUI Class
By ribbs2521 in forum New To JavaReplies: 1Last Post: 10-20-2009, 10:53 PM -
Adding and removing panels dynamically
By kbyrne in forum AWT / SwingReplies: 1Last Post: 04-12-2008, 08:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks