回 帖 发 新 帖 刷新版面

主题:[讨论]急救 谁能帮我解决以下我问题出在那里了啊????

谁能告诉我这是出了什么问题呀  怎么这么多错误啊
package 移动图片;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.AdjustmentListener;
import java.net.*;
import java.awt.event.*;
public class test2  extends JFrame
{
    JLabel jl;
    static int x=0,y=100;
    ImageIcon icon;
    URL url;
    Color c=new Color(255,255,255);
    ActionListener taskPerformer=new ActionListener()
    {
        public void actionPerformed(ActionEvent evt)
        {
            x++;
            jl.setLocation(x,y);
        }
        };
Timer ttl=new Timer(10,taskPerformer);
 public test2()
 {
     try{url=Class.forName("test2").getResource("84.gif");}
     catch(Exceptione)
     {}
     icon=new ImageIcon("84.gif");
     jl.setBounds(300,300,150,200);
     this.getContentPane().add(jl);
     this.getContentPane().setLayout(null);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setBounds(100,100,500,300);
     this.setVisible(true);
     ttl.start();}
 public static void main(String args[])
 {
     Test t=new test2();
 }
    }

回复列表 (共2个回复)

沙发

包名最好不要用中文!!!
只是解决了错误,具体功能实现,自己解决

package 移动图片;

import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import java.awt.event.ActionEvent;
import java.awt.event.AdjustmentListener;
import java.net.*;
import java.awt.event.*;

public class Test2 extends JFrame {
    
    //JLabel jl;   //未初始化,将出现空指针异常
    JLabel jl = new JLabel();

    static int x = 0, y = 100;

    ImageIcon icon;

    URL url;

    Color c = new Color(255, 255, 255);

    ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            x++;
            jl.setLocation(x, y);
        }
    };

    Timer ttl = new Timer(10, taskPerformer);

    public Test2() {
        try {
            url = Class.forName("移动图片.Test2").getResource("84.gif");
        } catch (ClassNotFoundException e1) {
            
            e1.printStackTrace();
        }
        /*try {
            //url = Class.forName("test2").getResource("84.gif");
        }

        // catch(Exceptione) 
        catch (Exception e)

        {
        }*/
        
        icon = new ImageIcon("84.gif");
        jl.setBounds(300, 300, 150, 200);
        this.getContentPane().add(jl);
        this.getContentPane().setLayout(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(100, 100, 500, 300);
        this.setVisible(true);
        ttl.start();
        
    }

    public static void main(String args[]) {
        Test2 t = new Test2();
    }
}

板凳

谢谢你 兄弟

我来回复

您尚未登录,请登录后再回复。点此登录或注册