当前位置:编程学习 > JAVA >>

请各位大虾们,帮我改一下这个程序,谢谢咯

因为是初学者,很多都不会,感觉执行起来,效果太差了
import java.util.*;
import java.util.StringTokenizer;
import java.applet.*;
import javax.swing.*;
import java.awt.*;
import java.lang.Runnable;
public class stringtest extends JApplet implements Runnable{
JTextField j1;
String[] name;
int count=0;
Thread motor;
Image[] image;
int imgnum=0;
int x1=0,y1=0;
public void init()
{
 j1=new JTextField("helloworld");
 String[] name=new String[4];
 image=new Image[10];
 StringTokenizer str=new StringTokenizer("1.jpg+2.jpg+3.jpg","+");
 while(str.hasMoreTokens())
 {
 name[count++]=str.nextToken();
 }
 for(int i=0;i<count;i++)
 {
 image[i]=this.getImage(this.getDocumentBase(), name[i]);
 }

 this.setVisible(true);
 this.setSize(500,500);
}
public void paint(Graphics g)
{

if(imgnum<count)
{g.drawImage(image[imgnum++], x1, y1,100,100, this);

}
else
{ imgnum=0;
g.drawImage(image[imgnum++], x1, y1,100,100, this);
}
x1=x1+20;y1=y1+20;
}
public void start()
{
motor=new Thread();
motor.start();
}
public void run()
{
stringtest test=new stringtest();
while(true)
{test.repaint();
try
{Thread.sleep(200);
}
catch(InterruptedException el)
{};
}
}


}
--------------------编程问答-------------------- 不知道你要达到什么效果,我就随便写了,希望有用

public class StringTest extends JApplet implements Runnable {

JTextField j1;
String[] name;
int count = 0;
Thread motor;
Image[] image;
int imgnum = 0;
int x1 = 0, y1 = 0;

public void init() {
String[] name = new String[4];
image = new Image[10];
StringTokenizer str = new StringTokenizer("1.png+2.png+3.png", "+");
while (str.hasMoreTokens()) {
name[count++] = str.nextToken();
}
for (int i = 0; i < count; i++) {
image[i] = this.getImage(this.getDocumentBase(), name[i]);
}
this.setSize(500, 500);
}

public void paint(Graphics g) {

g.drawString("12324", x1, y1);
if (imgnum < count) {
g.drawImage(image[imgnum++], x1, y1, 100, 100, this);

} else {
imgnum = 0;
g.drawImage(image[imgnum++], x1, y1, 100, 100, this);
}
x1 = x1 + 20;
y1 = y1 + 20;

if (x1 > 500) {
x1 = 0;
y1 = 0;
g.setColor(Color.WHITE);
g.fillRect(0, 0, g.getClipBounds().width, g.getClipBounds().height);
}
}

public void start() {
motor = new Thread(this);
motor.start();
}

public void run() {
while (true) {
this.repaint();
try {
Thread.sleep(200);
} catch (InterruptedException el) {
}
}
}

}
--------------------编程问答--------------------
引用 1 楼 hc21314 的回复:
不知道你要达到什么效果,我就随便写了,希望有用
Java code

public class StringTest extends JApplet implements Runnable {

    JTextField j1;
    String[] name;
    int count = 0;
    Thread motor;
    Image[] image;
    i……
楼上不错。格式、变量名再排排
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,