• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

widget not loading in frame

 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic