Reputation: 503
i have my class declared:
public class myRightPanel extends JPanel
then i override the paintComponent of my super class like this:
public void paintComponent(Graphics g){
super.paintComponents(g);
//Draw bunch of things here
}
Now it turns out i also need a method which takes in two integer(x,y) parameters and adds something to my already drawn myRightPanel
at that coordinates. How do i do this when i have already overridden my paintComponent()
?
Upvotes: 0
Views: 69
Reputation: 168825
Store the x,y as a Point
as an attribute of the class so it is accessible within the paint method. Call repaint()
.
Upvotes: 3
Reputation: 6029
You need to use the Graphics object to draw any content you want.
For example:
public void paintComponent(Graphics g){
super.paintComponents(g);
g.drawString("Hello test", 0, 0);
}
I recommend reading Java 2D tutorial: http://docs.oracle.com/javase/tutorial/2d/index.html
Upvotes: 0