Java的不能动画广场,出来的旋转方 [英] Java- Not able to animate square, comes out as rotating square

查看:166
本文介绍了Java的不能动画广场,出来的旋转方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Java,需要一些帮助!我的教授要我创建4个方法,这最终目标是输出动画旋转方形像我这种早些时候code,我把做的:

I am new to java and need some help! My professor wants me to create 4 methods, which ultimate goal is to output a animated rotating square like I did in this earlier code that I made:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GTest2 {
public static void main(String[] args) {
    GraphicsPanel gp = new GraphicsPanel();
    gp.delay(1000);
    int x = gp.getWidth() / 2;
    int y = gp.getHeight() / 2;
    gp.setLocation(x, y);
    for (int n=1; n <= 150; n++)  {
        gp.clear();
        for (int angle=0; angle < 360; angle += 10) {
            for (int i=0; i < 4; i++)  {             
                gp.draw(100);
                gp.turn(90);
            }
            gp.turn(10);
        }
        gp.render();        
        gp.delay(30);       
        gp.turn(2);         
    }
}
}

我的教授提供给我们班GraphicsPanel所以我们可以做创建图形和动画的这些程序: http://pastebin.com/ Ha1pdLrc

这是我到目前为止,但我似乎只已经能够创建一个旋转的正方形:

This is what I have so far, but I seem to only have been able to create a rotating square:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class G7 {
    public static void main(String[] args) {
        GraphicsPanel gp = new GraphicsPanel();
        gp.delay(1000);         
        animateCircleOfPolygons(gp);
    }

public static void animateCircleOfPolygons(GraphicsPanel gp){ 
    for (int n = 1; n <= 150; n++)  {
        gp.clear();
        drawCircleOfPolygons(gp);
        gp.render();        
        gp.delay(30);       
        gp.turn(2);
    }
}

public static void drawCircleOfPolygons(GraphicsPanel gp){
    for (int angle = 0; angle < 360; angle += 10) {
        drawPolygon(gp, 100, 4);
        gp.turn(10);
    }
}

public static void drawPolygon(GraphicsPanel gp, int sideLength, int sideCount){
    for (int i = 0; i < sideCount; i++)  {
        gp.draw(sideLength);
        gp.turn(360.0 / sideCount);
        gp.delay(30);
    }
}
}

我已经到处找一个答案都无济于事,任何人可以请帮助我理解我在做什么错了。

I have looked everywhere for an answer to no avail, can anybody please help me understand what I am doing wrong.

推荐答案

不是真的知道我完全理解你的问题,但如果它是第二个例子code G7 不会出现动画(如第一批)事实证明比第一个例子code GTest2 那是因为你有重复延时要慢: gp.delay(30); 第二code;看来无论是在 animateCircleOfPolygons 功能以及在 drawPolygon 功能。它删除无论是code会产生相同的输出。(因为它应该 - 这是同样的逻辑,毕竟)

Not really sure if I understand your issue fully, but if it is that the second example code G7 doesn't appear to be animated (like the first) as it turns slower than in the first example code GTest2 it's because you have duplicated the delay: gp.delay(30); in the second code; it appears both in the animateCircleOfPolygonsfunction as well as in the drawPolygonfunction. It you remove either the code will produce identical output (as it should - it's the same logic after all).

这篇关于Java的不能动画广场,出来的旋转方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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