setSize(400,300);
show();
放在One的构造函数中,循环显示还要大改.

解决方案 »

  1.   

    怎么改?
    那为什么我向CMD输出数字 就可以?
      

  2.   

    import javax.swing.*;
    import java.awt.*;
    class One extends JFrame
    {
    JLabel jj;
    JPanel pp;
    public One()
    {
    jj=new JLabel();
    pp=new JPanel();
    pp.add(jj);
    Container cc=getContentPane();
    cc.add(pp);
    setSize(400,300);
    show();
    }
    void display(ImageIcon n)
    {
    for(int i=0;i<100;i++)
    {
    try
    {

    jj.setIcon(n);
    Thread.sleep(10);

    }
    catch(InterruptedException e)
    {}
    }
    }
    /*public static void main(String args[])
    {
    One rr=new One();
    rr.setSize(400,300);
    rr.show();
    }*/
    }
    class Two implements Runnable
    {
    ImageIcon nnn;
    Thread t;
    static One one=new One();
    public Two(ImageIcon n)
    {
    nnn=n;
    //one=new One();
    t=new Thread(this);
    t.start();
    }
    public void run()
    {
    //synchronized(one)
    //{
    one.display(nnn);
    //}
    }
    public static void main(String args[])
    {
    ImageIcon aa=new ImageIcon("1.gif");
    ImageIcon bb=new ImageIcon("2.gif");
    ImageIcon cc=new ImageIcon("3.gif");

    Two t1=new Two(aa);
    Two t2=new Two(bb);
    Two t3=new Two(cc);
    }
    }
    //看一看
      

  3.   

    你这个也不行,虽然能够出结果,但是结果不稳定,有错!我这里有一个以前做的,可以参考!/**
     *author FuTao
     */
    import javax.swing.*;
    import java.awt.*;
    public class TestThreadImage extends Thread
    {
    JFrame jFrame;
    JPanel jPanel;
    JLabel jLabel;
    ImageIcon imageIcon[];
    int a;
    public TestThreadImage()
    {
    a=0;
    imageIcon = new ImageIcon[3] ;
    imageIcon[0] = new ImageIcon("1.JPG");
    imageIcon[1] = new ImageIcon("2.GIF");
    imageIcon[2] = new ImageIcon("3.GIF");
    jFrame = new JFrame();
    jPanel = new JPanel();
    jLabel = new JLabel("");
    jPanel.add(jLabel);
    jFrame.getContentPane().add(jPanel);
    jFrame.setSize(200,200);
    jFrame.setVisible(true);
    }
    public void run()
    {
    while(true)
    {
    if(a<3)
    {
      jLabel.setIcon(imageIcon[a]);
      a++;
    }
    else
    a=0;
    try
    {
    sleep(1000);
    }catch(InterruptedException e){}
    }
    }
    public void dis()
    {
    this.start();
    }
    public static void main(String args[])
    {
    TestThreadImage testThreadImage = new TestThreadImage();
    testThreadImage.dis();

    }
    }
      

  4.   

    我是想用同步实现的 
    没了synchronized就不能叫同步了吧
    用同步怎么实现啊?