my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes widget not loading in frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "widget not loading in frame" Watch "widget not loading in frame" New topic
Author

widget not loading in frame

abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

hi, i am trying out the MiniMusicPlayer3 program from the book HeadFirst Java...

Problem: My class which extends JPanel is not loading in my frame.... but the events are occurring...


This is my code:






help me...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39070
    
  23
Why have you got static fields? I think those fields should go with an object and should not be static.

Which page is it on? I have my copy here, and it would help to compare your code with what was printed.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

In your MyDrawPanel class you attempt to override JPanel#paintComponent(), but you've misspelled the name as paintComponenet(). Your method never gets invoked, which is why you're only seeing the default empty JPanel graphics

If you use the @Override annotation on a method that should be an overrides of a super class method or an implementation of an interface method, you can prevent this kind of thing very easily. In fact you seem to have done just that with the controlChange() method...


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

Campbell Ritchie wrote:Why have you got static fields? I think those fields should go with an object and should not be static.

Which page is it on? I have my copy here, and it would help to compare your code with what was printed.



The code is at page 392
abrar alvi
Ranch Hand

Joined: Feb 01, 2012
Posts: 66

Jelle Klap wrote:In your MyDrawPanel class you attempt to override JPanel#paintComponent(), but you've misspelled the name as paintComponenet(). Your method never gets invoked, which is why you're only seeing the default empty JPanel graphics

If you use the @Override annotation on a method that should be an overrides of a super class method or an implementation of an interface method, you can prevent this kind of thing very easily. In fact you seem to have done just that with the controlChange() method...




Thanks Jelle Klap,

Really it was a silly mistake....

Yes, now the code is running just fine.....
 
GeeCON Prague 2014
 
subject: widget not loading in frame