动画两个Point对象之间的线 [英] Animating a line between two Point objects

查看:107
本文介绍了动画两个Point对象之间的线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是画两个Point对象之间的直线的方式最简单的方法
这看起来像我画实时该行手?

What's the simplest way to draw a line between two Point objects in a way that will look like I am drawing that line in real time by hand?

例如:

Point a = new Point(5,20);
Point b = new Point(15,20);

我如何这些点用动线连接?

How do I connect these points with a "moving" line?

在换句话说,我希望让用户感到某种运动。有一个简单的方法来做到这一点?

In other words I want to make the user feel "motion" of some sort. Is there a simple way to do that?

推荐答案

继Chinmay Kanchi答案,你需要创建动画的感觉。正如评论由Uhlen上述美国东部时间上工作时,你应该使用Swing的计时器。给你举的例子如何使用定时器。让我们假设我们有一个小组,我们希望它在滑开例如点击一个按钮,因此我们需要动画它滑开,增加它的大小。下面是一个显示pretty你会多少如何使用定时器来完成操作的例子。

Following the answer by Chinmay Kanc you need to create a feeling of animation. As mentioned above in comments by Uhlen you should use Swing's Timer when working on EDT. To give you example of how to use Timer. Lets assume we have a panel and we want it to slide open on e.g. a button click, thus we need to animate it sliding open by increasing its size. Below is an example showing pretty much how you would use Timer to do the operations.

this.extendingTimer = new Timer(0, new ActionListener()
{
    public void actionPerformed(ActionEvent e)
    {
       //assume sliding is vertical     
       int value = maximumHeight;
       //make sure the size will not be bigger then allowed maximum
       if(currentExtensionSize + extensionRate >= value)
       {
          currentExtensionSize = value;
          stopExtending();
       }
       else
          currentExtensionSize += extensionRate;
       setSize(new Dimension(maximumWidth, currentExtensionSize));
    }
});
extendingTimer.setInitialDelay(0);
extendingTimer.setDelay(100);
extendingTimer.setRepeats(true);

这篇关于动画两个Point对象之间的线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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