一个关于java中重绘的问题,我将窗口放大后为什么只保留了最后一个图形,我应该如何修改代码呢
问题代码:classPaintPanelMotionextendsJPanel{intx;inty;publicPaintPanelMotion(){super();ad...
问题代码:
class PaintPanelMotion extends JPanel{
int x;
int y;
public PaintPanelMotion(){
super();
addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent event){
x=event.getX();
y=event.getY();
repaint();
}
});
}
@Override
public void paintComponent(Graphics comp){
Graphics2D comp2D=(Graphics2D) comp;
comp2D.setColor(Color.blue);
comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle2D.Float rect= new Rectangle2D.Float(x-100,y-50,200,100);
Ellipse2D.Float circle =new Ellipse2D.Float(x-125,y-125,250,250);
comp2D.draw(rect);
comp2D.draw(circle);
}
} 展开
class PaintPanelMotion extends JPanel{
int x;
int y;
public PaintPanelMotion(){
super();
addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent event){
x=event.getX();
y=event.getY();
repaint();
}
});
}
@Override
public void paintComponent(Graphics comp){
Graphics2D comp2D=(Graphics2D) comp;
comp2D.setColor(Color.blue);
comp2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Rectangle2D.Float rect= new Rectangle2D.Float(x-100,y-50,200,100);
Ellipse2D.Float circle =new Ellipse2D.Float(x-125,y-125,250,250);
comp2D.draw(rect);
comp2D.draw(circle);
}
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
2015-01-18
展开全部
两个事件,只使用其中一个就可以了。
追问
我初学,不是太明白
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询