java 画图动画
发布网友
发布时间:2022-07-13 15:02
我来回答
共5个回答
热心网友
时间:2023-11-03 11:56
//只是实现了简单功能,有待改进
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class DrawTest extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
private static final int S_WIDTH = 800;
private static final int S_HEIGHT = 600;
private Oval o1 = new Oval(80, 100);
private Oval o2 = new Oval(300, 120, 2, 90, 320, 380);
private Oval o3 = new Oval(600, 120, 1, 120, 180, 400);
private Oval o4 = new Oval(80, 300, 3, -60, 200, 200);
public void dataInit() {
this.setTitle("Draw Test");
this.setBackground(Color.CYAN);
this.setLocation(200, 180);
this.setSize(DrawTest.S_WIDTH, DrawTest.S_HEIGHT);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Thread(this).start();
this.setVisible(true);
}
public void paint(Graphics g) {
o1.move(g);
o2.move(g);
o3.move(g);
o4.move(g);
}
public static void main(String[] args) {
new DrawTest().dataInit();
}
public void run() {
while (true) {
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class Oval {
private int lx;
private int ly;
private int step = 5;
private int startAngle = 0;
private int width = 80;
private int height = 100;
public Oval(int lx, int ly, int step, int startAngle, int width,
int height) {
this.lx = lx;
this.ly = ly;
this.step = step;
this.startAngle = startAngle;
this.width = width;
this.height = height;
}
public Oval(int lx, int ly) {
this.lx = lx;
this.ly = ly;
}
public Oval() {
}
public void draw(Graphics g) {
Color c = g.getColor();
g.setColor(Color.red);
g.drawArc(lx, ly, width, height, startAngle, startAngle - step);
g.setColor(c);
}
public void move(Graphics g) {
startAngle -= step;
draw(g);
}
}
}
热心网友
时间:2023-11-03 11:57
有点难度
热心网友
时间:2023-11-03 11:57
难是不难,只是得花点时间
热心网友
时间:2023-11-03 11:58
JAVA运行程序是 需要一定的时间 最好把JAVA升级 运行内存达到15M的话 就可以达到瞬间
热心网友
时间:2023-11-03 11:58
连说都没说清楚怎么帮你。什么叫任意长度大小的园及椭圆啊
还要一次多个图形同时话。鬼都不知道你在坐什么。
还有什么叫画的过程你是想园是一点一点的走出来还是什么的?你说的都知道什么意思。