当前位置: 代码迷 >> Java相关 >> 这个图片怎么没调用其呢??求解决。
  详细解决方案

这个图片怎么没调用其呢??求解决。

热度:151   发布时间:2011-11-02 23:02:21.0
这个图片怎么没调用其呢??求解决。
实现图片的移动

package simpleflash;

import java.net.URL;
import java.awt.Container;
//import java.util.Random;
import javax.swing.*;

public class MyFirstFlash extends JFrame
{
    private JLabel jl = new JLabel();  //声明标签对象;
    private static Thread t;           //声明线程对象;
    private int count = 0;               //声明计数变量;
    private Container container = new Container(); //声明容器;
   
    public MyFirstFlash()
    {
        setBounds(300, 200, 250, 100);
        container.setLayout(null);
        URL url = MyFirstFlash.class.getResource("me.jpeg");  //获取图片的URL;
        Icon icon = new ImageIcon(url);
        jl.setIcon(icon);
        jl.setHorizontalAlignment(SwingConstants.LEFT);  //设置图片在标签的中间;
        jl.setBounds(10, 10, 200, 50);
        jl.setOpaque(true);            // 设置标签绘制其内部所有像素;
        jl.setVisible(true);
   
        t = new Thread(new Runnable()   //创建匿名内部类使Runnable对象和Thread对象t相关联 ;
        {
            public void run()              //重写run方法;
            {
                while (count <= 200)
                {
                    jl.setBounds(count, 10, 200, 50);
                    try
                    {   
                        Thread.currentThread().sleep(1000);
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                    count += 4;
                    if (count == 200)
                    {
                        count = 10;
                    }
                }
            }
        });
        t.start();
        container.add(jl);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }
   
    public static void main(String[] args)
    {
        new MyFirstFlash();
    }

}
搜索更多相关的解决方案: 声明  图片  private  package  public  

----------------解决方案--------------------------------------------------------
private Container container = new Container(); //声明容器;
这样实例化 ,很少用。。。。

----------------解决方案--------------------------------------------------------
  相关解决方案