用代码实现动态画线效果,最好是跟java相关的代码,急急急在线等
可以用写代码的任何软件,用代码实现动态效果,从一个点然后动态画出一条线,带轨迹的直线,然后到达一个坐标后分叉成2个不同方向继续画线,然后2个不同方向的画线再继续分叉,以此...
可以用写代码的任何软件,用代码实现动态效果,从一个点然后动态画出一条线,带轨迹的直线,然后到达一个坐标后分叉成2个不同方向继续画线,然后2个不同方向的画线再继续分叉,以此类推,做到4个分支就可以了。这个过程都是动态的,并且分叉画的2个线是同步画的~没有代码的话希望能提供思路给我,在线等急急急急,谢谢
展开
1个回答
2013-12-26
展开全部
import java.awt.Graphics;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
public class PainterDemo2 extends JFrame{
public PainterDemo2(){
super("Java画图程序");
setSize(600,500); //设置窗口尺寸
setVisible(true); //设置窗口为可视
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
PainterDemo2.this.repaint();
}
});
}
public void paint(Graphics g){
super.paint(g);
int x1=150, y1=150;
int x2=151, y2=151;
g.setColor(Color.red);
for(int i=0; i<10; i++){
g.drawLine(x1, y1, x2, y2);
try{Thread.sleep(100);}catch(Exception eex){}
x1=x2;
y1=y2;
x2=y2+10;
y2=y2+10;
}
int x211=x1, y211=y1;
int x212=x1+1, y212=y1+1;
int x221=x1, y221=y1;
int x222=x1+1, y222=y1+1;
for(int i=10; i<20; i++){
g.drawLine(x211, y211, x212, y212);
g.drawLine(x221, y221, x222, y222);
try{Thread.sleep(100);}catch(Exception eex){}
x211=x212;
y211=y212;
x212=x212-10;
y212=y212+10;
x221=x222;
y221=y222;
x222=x222+10;
y222=y222-10;
}
int x311=x211, y311=y211;
int x312=x211+1, y312=y211+1;
int x321=x211, y321=y211;
int x322=x211+1, y322=y211+1;
int x331=x221, y331=y221;
int x332=x221+1, y332=y221+1;
int x341=x221, y341=y221;
int x342=x221+1, y342=y221+1;
for(int i=10; i<20; i++){
g.drawLine(x311, y311, x312, y312);
g.drawLine(x321, y321, x322, y322);
g.drawLine(x331, y331, x332, y332);
g.drawLine(x341, y341, x342, y342);
try{Thread.sleep(100);}catch(Exception eex){}
x311=x312;
y311=y312;
x312=x312-10;
y312=y312-10;
x321=x322;
y321=y322;
x322=x322+10;
y322=y322+10;
x331=x332;
y331=y332;
x332=x332-10;
y332=y332-10;
x341=x342;
y341=y342;
x342=x342+10;
y342=y342+10;
}
}
public static void main(String[] args){
new PainterDemo2();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询