Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 计时器无法转换为Actionlistener错误?_Java_User Interface - Fatal编程技术网

Java 计时器无法转换为Actionlistener错误?

Java 计时器无法转换为Actionlistener错误?,java,user-interface,Java,User Interface,我们为基于计时器的动画编写了一个代码,我嵌套了Changelistener和ACtionlistener。但是,根据我得到的错误,我的计时器(在actionlistener中)无法转换为这样的计时器。我怎样才能解决这个问题 import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.awt.*; public class Slider3 { public static J

我们为基于计时器的动画编写了一个代码,我嵌套了Changelistener和ACtionlistener。但是,根据我得到的错误,我的计时器(在actionlistener中)无法转换为这样的计时器。我怎样才能解决这个问题

import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;

public class Slider3 {

    public static JSlider slider = new JSlider(JSlider.HORIZONTAL, 1000, 20, 0);
    public static JLabel label;
    public static JPanel panel = new JPanel();
    public static int delay;
    public static int speed;
    public static Timer timer = new Timer (delay, new SliderListener());

    public void main(String[] args) {   
        JFrame frame = new JFrame("Legend Of Zelda");
        panel.setLayout(new GridLayout(5, 5, 5, 25));
        slider.addChangeListener(new SliderListener());
        delay = speed;

        frame.setVisible(true);
        frame.setResizable(false);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        timer.start();

        panel.add(label);
        panel.add(slider);
        frame.setContentPane(panel);
        frame.pack();
    }

    private static class SliderListener implements ChangeListener, ActionListener {

        public void stateChanged(ChangeEvent e) {
            for (int i = 1; i < 11; i++) {
                ImageIcon imageIcon = new ImageIcon(i + ".jpg");
                label.setIcon(imageIcon);
            }
            int speed = slider.getValue();
        }

        public void actionPerformed (ActionEvent e) {
            delay = speed;
            timer = new Timer(delay, timer);
        }
    }
}
import javax.swing.*;
导入java.awt.event.*;
导入javax.swing.event.*;
导入java.awt.*;
公共类幻灯片3{
公共静态JSlider滑块=新JSlider(JSlider.HORIZONTAL,1000,20,0);
公共静态标签;
publicstaticjpanel面板=newjpanel();
公共静态输入延迟;
公共静态整数速度;
公共静态计时器=新计时器(延迟,新的SliderListener());
public void main(字符串[]args){
JFrame=新JFrame(“塞尔达传奇”);
面板设置布局(新网格布局(5,5,5,25));
addChangeListener(新的SliderListener());
延迟=速度;
frame.setVisible(true);
frame.setresizeable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setBorder(BorderFactory.createEmptyByOrder(10,10,10,10));
panel.setLayout(新的BoxLayout(panel,BoxLayout.PAGE_轴));
timer.start();
面板。添加(标签);
面板。添加(滑块);
frame.setContentPane(面板);
frame.pack();
}
私有静态类SliderListener实现ChangeListener、ActionListener{
公共无效状态已更改(更改事件e){
对于(int i=1;i<11;i++){
ImageIcon ImageIcon=新的ImageIcon(i+“.jpg”);
label.setIcon(图像图标);
}
int speed=slider.getValue();
}
已执行的公共无效操作(操作事件e){
延迟=速度;
定时器=新定时器(延时、定时器);
}
}
}

Timer构造函数的第二个参数应该是ActionListener,您正在传递一个计时器。。。你期望什么/你想做什么?int speed=slider.getValue();