• Post Reply Bookmark Topic Watch Topic
  • New Topic

Add a Jpanel component to a Jframe  RSS feed

 
Daanish Suhail
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* I have extended JFrame class as follows 'public class First extends JFrame implements ActionListener{'.

* There another class which extends JPanel class as follows

class DrawPanel extends JPanel{

public void paintComponent(Graphics g)
{
g.fillRect(20,50 ,100 , 100);
g.setColor(Color.cyan);
}

}

* How do I call and add this paintComponent() to my JFrame which i am creating in class First?

*(I'm a complete novice at this)
 
Daanish Suhail
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just learnt that paintComponent() is called automatically ... agreed... but for which panel or frame?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I just learnt that paintComponent() is called automatically ... agreed... but for which panel or frame?

from the docs:
public void repaint()
Repaints this component.
If this component is a lightweight component, this method causes a call to this component's paint method as soon as possible. Otherwise, this method causes a call to this component's update method as soon as possible.
Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.


the
"see Painting in AWT and Swing."
is a link
http://java.sun.com/products/jfc/tsc/articles/painting/index.html
 
Daanish Suhail
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dunn.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!