Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

button in jpanel should change background of jframe?

 
Chris Song
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have created 2 classes

First class is a jpanel and it has a button

Second class is a jframe and displays an object of jpanel.

I wrote this program so that i can understand object oriented programming.

My question is How can i change the jframe background colour by clicking the button that is in the jpanel class?

Could somebody provide me with a similar example. I would really apreciate it.

Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this changes the color of the containing JPanel of the main class, not the
JFrame itself.

I've included 2 ways
1) passing a reference of the parent class to the child class
2) just using getParent()

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic