首页上一页 1 下一页尾页 1 条记录 1/1页
JAVA入门与精通问题邵2
发表在Java图书答疑
2009-02-25
是否精华
是
否
版块置顶:
是
否
[font color=#FF0000]package com.wsy;
import java.awt.Container;
import java.net.URL;
import java.util.Random;
import javax.swing.*;
[/font]
public class SwingAndThread extends JFrame{
private JLabel jl=new JLabel();
private static Thread t;
private int count=0;
private Container container = getContentPane();
public SwingAndThread(){
setBounds(300, 200, 250, 100);
container.setLayout(null);
URL url= SwingAndThread.class.getResource("/1.gif");
Icon icon = new ImageIcon(url);
jl.setIcon(icon);
jl.setHorizontalAlignment(SwingConstants.LEFT);
jl.setBounds(10, 10, 200, 50);
jl.setOpaque(true);
t=new Thread(new Runnable(){
public void run(){
while(count<=200){
jl.setBounds(count, 10, 200, 50);
try{
t.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 SwingAndThread();
}
}
错误提示:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at com.wsy.SwingAndThread.<init>(SwingAndThread.java:18)
at com.wsy.SwingAndThread.main(SwingAndThread.java:48)
[[font size=1]font color=#0000FF]
[font size=4]高手帮忙看下
[/font][/font][/font]
import java.awt.Container;
import java.net.URL;
import java.util.Random;
import javax.swing.*;
[/font]
public class SwingAndThread extends JFrame{
private JLabel jl=new JLabel();
private static Thread t;
private int count=0;
private Container container = getContentPane();
public SwingAndThread(){
setBounds(300, 200, 250, 100);
container.setLayout(null);
URL url= SwingAndThread.class.getResource("/1.gif");
Icon icon = new ImageIcon(url);
jl.setIcon(icon);
jl.setHorizontalAlignment(SwingConstants.LEFT);
jl.setBounds(10, 10, 200, 50);
jl.setOpaque(true);
t=new Thread(new Runnable(){
public void run(){
while(count<=200){
jl.setBounds(count, 10, 200, 50);
try{
t.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 SwingAndThread();
}
}
错误提示:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at com.wsy.SwingAndThread.<init>(SwingAndThread.java:18)
at com.wsy.SwingAndThread.main(SwingAndThread.java:48)
[[font size=1]font color=#0000FF]
[font size=4]高手帮忙看下
[/font][/font][/font]