I am aware of the java repaint() method that repaints the whole screen and the repaint(int, int, int, int) for repainting a certain section of the screen but I have an ellipse that I am making move across the screen. Is there a way to only repaint the space containing the ellipse? Or a way to obtain the space an ellipse is taking up? Thanks.
If what you're trying to do is repaint the portion of the screen that contains the ellipse, you could do something like this:
int ovalposX = 0;
int ovalposY = 0;
int ovalwidth = 10;
int ovalheight = 10;
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawOval(ovalposX,ovalposY,ovalwidth,ovalheight)
}
public void redraw(){
repaint(ovalposX, ovalposY, ovalwidth, ovalheight);
}
(If this is incorrect I'm terribly sorry, this is my first post)
Is there a way to only repaint the space containing the ellipse?
Read the section from the Swing tutorial on Custom Painting .
The working example shows how to use two repaint() requests to move a square:
The two requests will be combined into one larger area before the painting is done.
In reality you don't really need to worry about getting this detailed. I doubt you will notice a performance difference between repainting the entire panel or only a portion of it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.