谁告诉我有哪个控件可以让图片自动移动的

解决方案 »

  1.   

    我可以给你写个,不过,需要money
      

  2.   

    将图片放在Label中,开个线程定时替换Label中的图片,假定图片名为1.gif,2.gif,3.gif,4.gif
    示意代码如下
    label.setIcon(new ImageIcon("1.gif") );
    int count=1;
    while(true)
    {
        try{
            label.setIcon(new ImageIcon(count+".gif"));
            count++;
            if(count>4)
            {count=1;}
            repaint();
            sleep(1000/25);
          } 
         catch(Exception e)
         {
            System.out.println("线程错误"+e.toString());
          }
    }
      

  3.   

    写个换图片的线程吧,不过由于swing并不是线程安全的,所以将换图片这个动作放入到swing event dispatch thread中
      

  4.   

    java核心技术第二卷有   自己看看应该可以写出来
      

  5.   

    也可以不需要线程...
    把图片放到一个Component里...
    paint会时时刷新组件,只需要在这个方法里面改变图片需要显示的位置即可...
      

  6.   

    package day20;import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.awt.geom.Ellipse2D;import javax.swing.JFrame;
    import javax.swing.JPanel;public class ThreadTest {
    private JFrame frame;

    public ThreadTest(){
    frame=new JFrame("自动");
    GraphPanel gp=new GraphPanel();
    frame.add(gp,BorderLayout.CENTER);
    }

    public void showMe(){
    frame.setVisible(true);
    frame.setSize(500,500);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
    new ThreadTest().showMe(); }}class GraphPanel extends JPanel {
    private int x,y;
    private Color c;
    private int i=0;
    private boolean stop = false;

    public GraphPanel(){
    Thread t=new moveThread();
    t.start();
    }
    class moveThread extends Thread{
    public void run() {
    while(stop == false){
    System.out.println("被刷新");
    try {
    Thread.sleep(3000);
    x=(int)(Math.random()*200+1);
    y=(int)(Math.random()*200+1);
    repaint();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }
    }
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    if(i%2==0){
    c=Color.BLUE;
    }else{
    c=Color.RED;
    }
    i++;
    System.out.println(x);
    Graphics2D g2=(Graphics2D)g;
    Shape s=new Ellipse2D.Double(x,y,55,55); 
    g2.setColor(c);
    g2.draw(s);
    g2.fill(s);
    }
    }
    LZ看看,这段代码是我用来使一个圆随机变动的,使用线程实现的,可以参照一下
      

  7.   

      找一下jdk包中的demo程序,里边有比较多的程序涉及这方面得问题。