Topic: 求助:如何让图片有螺旋方阵运动的效果?

  Print this page

1.求助:如何让图片有螺旋方阵运动的效果? Copy to clipboard
Posted by: lisailon
Posted on: 2005-10-14 08:12

我想写一个让图片由外向内一圈一圈地运动,原本想用for--for语句,但不知道那里错了,图片一动也不动,请大家指点一下拉,谢谢~~~~~~
原代码:

import java.awt.*;
import java. applet.*;
public class NewApplet extends java.applet.Applet implements java.lang.Runnable{
int x,y,w,h;//方框的参数
int sw,sh;//屏幕的高宽
int i,k;
int n;
int nw,nh;//小方格的高和宽
int pxi,pyi;//图片的初始格数
int px,py;//图片的位置
int dx,dy;//图片的增量
Image p;
Thread u_thread;
public void init() {
x=2;y=2;w=500;h=440;//方框的参数
sw=this.getWidth();sh=this.getHeight();//屏幕的高宽
n=10;
nw=w/n;nh=h/n;//小方格的高和宽
pxi=0;pyi=0;//图片的初始格数
px=pxi*nw;py=pyi*nh;//图片的位置
dx=1;dy=1;//图片的增量
p=getImage(getDocumentBase(), "em51.gif");


}
public void 方框(Graphics g){
sw=this.getWidth();sh=this.getHeight();
g.setColor(java.awt.Color.pink);
g.fillRect((sw-w)/2,(sh-h)/2, w, h);
g.drawRect((sw-w)/2,(sh-h)/2, w, h);
}
public void 框格(Graphics g){

sw=this.getWidth();sh=this.getHeight();

g.translate((sw-w)/2,(sh-h)/2);//平移坐标位置
g.setColor(java.awt.Color.WHITE);
g.drawRect(x-1,y-1, w-2, h-2);//方框的外边框
for(i=1;i<n;i++){
g.setColor(java.awt.Color.WHITE);
g.drawLine(x,i*(nh), w, i*(nh));//横线
g.drawLine(i*(nw),y,i*(nw), h);//竖线
g.setColor(java.awt.Color.LIGHT_GRAY);
g.drawLine(x,i*(nh)+1, w, i*(nh)+1);//横线的错位
g.drawLine(i*(nw)+1,y,i*(nw)+1, h);//竖线的错位
}
}
public void 加载图画(Graphics g){
pxi=0;pyi=0;//图片的初始格数
px=pxi*nw;py=pyi*nh;//图片的位置
g.drawImage(p,px,py,this);

}
public void paint(Graphics g) {
super.paint(g);
方框(g);
框格(g);
加载图画(g);

}
public void start(){
if (u_thread == null)
{
u_thread = new Thread(this);
u_thread.start();
}
}
public void run() {
while(true){
//图片运动
pxi=0;pyi=0;
pxi=pxi +dx;
pyi=pyi+dy;
for(k=0;k<(n+1)/2;k++){
for(i=k;i<n-k;i++)
{
pxi = pxi + i;
pyi=k;
}
for(i=k+1;i<n-k;i++)
{
pxi=n-k+1;
pyi=pyi+i;
}
for(i=n-k-2;i>=k;i--)
{
pxi=pxi+i;
pyi=n-k-1;
}
for(i=n-k-2;i>=k;i--)
{
pxi=k;
pyi=pyi+i;
}
}

repaint();

try{
u_thread.sleep(600);
}catch (InterruptedException e){
return;
}
}//while
}//public void run()

//减小不必要的重画动作
public void repaint() {
super.repaint();
}

public void update(Graphics g) {
paint(g);
}//减小不必要的重画动作

}

注意
图片在附件里

2.Re:求助:如何让图片有螺旋方阵运动的效果? [Re: lisailon] Copy to clipboard
Posted by: lisailon
Posted on: 2005-10-14 08:18

那个礼物图片是"Present"!!我也不知道为什么它显示成那样????

3.Re:求助:如何让图片有螺旋方阵运动的效果? [Re: lisailon] Copy to clipboard
Posted by: lisailon
Posted on: 2005-10-14 08:26

是"(" "g" ")"呀,为什么回显示成那样?????

4.Re:求助:如何让图片有螺旋方阵运动的效果? [Re: lisailon] Copy to clipboard
Posted by: archerfish
Posted on: 2005-11-18 22:49

I'm a newbie and I can't answer you,but if u wanna print out the right code on the page u should use [ code ] [ /code ] to encapsulate ur code

5.Re:求助:如何让图片有螺旋方阵运动的效果? [Re: lisailon] Copy to clipboard
Posted by: ranchgirl
Posted on: 2005-11-19 04:14

You should check "禁止在这个帖子中使用笑脸标记" and also use code jute 标记
Thanks!

6.Re:求助:如何让图片有螺旋方阵运动的效果? [Re: lisailon] Copy to clipboard
Posted by: colo007
Posted on: 2006-02-05 15:20

同样的重绘的问题,希望能解释一下,只有最后一个图,前面的都不见了。

public void paintComponent(Graphics g)
{
System.out.println("paintComponent invoked!");
// call superclass's method, in case it needs
// to do anything
super.paintComponent(g);
// get a graphics 2d reference
Graphics2D g2 = (Graphics2D) g;


if( myRect==null)
{
g2.drawString(" ",6,60);
}

else{
myRect.setFrame(R[0],R[1],5,5);
g2.draw(myRect);
}

}

public void drawRectangle(String line)
{
a=0;
this.line=line;
StringBuffer buf =new StringBuffer(line).append(" ");
for(i=0; i<buf.length(); )
{
j=i;
while(buf.charAt(i)>=48 && buf.charAt(i)<=57)
{
i++;
//System.out.print("i:"+i+'\n');
}
//System.out.print("i2:"+i+"j:"+j+'\n');

String rx= buf.substring(j,i);
R[a]=Double.valueOf(rx).doubleValue();
System.out.print("a:"+a+"rx:"+R[a]+'\n');
a++;
i++;

myRect = new Rectangle2D.Double(R[0],R[1],5,5);
   super.repaint();
}

}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923