2 u011174439 u011174439 于 2013.12.31 23:56 提问

我在开发一个小游戏的时候遇到一个问题

import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.*;

public class test extends JFrame{
int x,y;
int index=0;
static Timer timer = new Timer();

    String Image[]={"tankR.png","tankU.png","tankL.png"};
    String Images[]={"l2.png","l4.png","l5.png"};
    ImageIcon icons1[]=new ImageIcon[3];
    ImageIcon icons2[]=new ImageIcon[3];
    JLabel labs[]=new JLabel[3];
    JLabel labs1[]=new JLabel[3];




 public  test() {
     super("ninni");
     JPanel c=new JPanel();
     for(int i=0;i<3;i++){
            icons1[i]=new ImageIcon(Image[i]);
            icons2[i]=new ImageIcon(Images[i]);
            labs[i]=new JLabel(icons1[i]);
            labs1[i]=new JLabel(icons2[i]);
            c.add(labs[i]);
            c.add(labs1[i]);
            //labs[i].setLocation(50, 50);
            labs[i].setBounds(50, 50, icons1[i].getIconWidth(),icons1[i].getIconHeight());
            labs[i].setVisible(false);
            //labs1[i].setLocation(100, 100);
            labs1[i].setBounds(100, 100, icons2[i].getIconWidth(),icons2[i].getIconHeight());
            labs1[i].setVisible(false);
            }
    //JPanel c=new JPanel();

    this.setContentPane(c);
    c.setLayout(null);
    setSize(320, 240);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //timer.schedule(new mytast(),1000, 2000);

}

// timer.schedule(new mytast(),1000, 2000);


public static void inf(){
    timer.schedule(new mytast(),1000, 2000);


}

public static void inf1(){
timer.schedule(new mytast1(),1000, 2000);

}

    public static void main(String []s){
        //test t=new test();
        inf();
        inf1();

    }
}

class mytast extends TimerTask{
//System.out.println("inisni");
int index=0;
test t=new test();
public void run(){
System.out.println("inisni");
if(index<3){
if(index==0){
t.labs[index].setVisible(true);
index++;}
else{
t.labs[index-1].setVisible(false);
t.labs[index].setVisible(true);
index++;

           }
       System.out.println("你好");}
   }

}
class mytast1 extends TimerTask{
//System.out.println("inisni");
int in=0;
test t=new test();
public void run(){
System.out.println("jhhhhhh");
if(in<3){
if(in==0){
t.labs1[in].setVisible(true);
in++;}
else{
t.labs1[in-1].setVisible(false);
t.labs1[in].setVisible(true);
in++;

           }
       System.out.println("你好");}
   }

}
执行出来之后是两个窗口,我想在一个窗口中实现应该怎么办,求大神帮忙。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!