这个图片怎么没调用其呢??求解决。
实现图片的移动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 Container container = new Container(); //声明容器;
这样实例化 ,很少用。。。。
----------------解决方案--------------------------------------------------------