椭圆形离开小径 [英] oval leaves the trail

查看:34
本文介绍了椭圆形离开小径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的球动画,从一个角开始,然后转到面板的另一个角.我为此编写了一个程序.

I am trying to make a simple ball animation, that starts from 1 corner and goes to another corner of the panel. I have written a program for that.

当我运行程序时,ovalball 会离开.我的意思是说,当程序运行时,它会留下颜色轨迹".在我的程序中,timer 每 100 毫秒触发一个事件.

When I run the program the oval or ball leaves the trail. What I mean to say is that it leaves it's 'color trail' when the program runs. In my program timer fires an event every 100 milliseconds.

以下是负责运行代码的逻辑:

void function() {
  // in this there is a action listener timed accordingly to fire event of 
  // doing x++ every 100th miliseconds
}

public void paintComponent(final Graphics g) {
 g.setColor(Color.black);
 g.drawOval(x,y,width,height);
 g.fillOval(x,y,width,height);
}

输出的屏幕截图:

推荐答案

尝试

public void paintComponent(final Graphics g) {
 super.paintComponent(g);

 g.setColor(Color.black);
 g.drawOval(x,y,width,height);
 g.fillOval(x,y,width,height);
}

这篇关于椭圆形离开小径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆