java - 每 2 秒更换一次图片

标签 java swing timer imageicon

我有点堆积,所以如果有人有任何想法,那将会有所帮助。 所以目前程序正在编译和运行,但我不知道如何完成它。 我正在使用 eclipse 。我想做的是当我启动程序时每 2 秒更改 4 张不同的图片,所以如果您有任何建议,请不要害羞。这是程序。

/** Here is the GUI of the program
 * class name SlideShowGui.java
 * @author Kiril Anastasov
 * @date 07/03/2012
 */

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

public class SlideShowGui extends JPanel implements ActionListener 
{
    JLabel name, comments, images;
    JTextField namejtf, commentsjtf, captionjtf;
    JButton submit;
    ImageIcon pictures, pictures2, pictures3, pictures4;
    boolean go = true;

    SlideShowGui()
    {
        name = new JLabel("Name:");
        this.add(name);

        namejtf = new JTextField(15);
        this.add(namejtf);

        comments = new JLabel("Comments:");
        this.add(comments);

        commentsjtf = new JTextField(15);
        this.add(commentsjtf);

        submit = new JButton("Submit");
        this.add(submit);
        submit.addActionListener(this);
        pictures = new ImageIcon("galileo1.jpg");
        images = new JLabel(pictures);

        pictures2 = new ImageIcon("galileo2.jpg");
        pictures3 = new ImageIcon("galileo3.jpg");
        pictures4 = new ImageIcon("galileo4.jpg");
        this.add(images);

        captionjtf = new JTextField(24);
        this.add(captionjtf);

    }

    public void actionPerformed(ActionEvent ae)
    {

    }
}

/**The driver class of the program. Here is the JFrame 
 * class name TestSlideShow.java
 * @author Kiril Anastasov
 * @date 07/03/2012
 */

import java.awt.*;
import javax.swing.*;
public class TestSlideShow 
{
    public static void main(String[] args) 
    {
        JFrame application = new JFrame();
        SlideShowGui panel = new SlideShowGui();
        application.add(panel);
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.setSize(300,600);
        application.setLocation(400,100);
        application.setVisible(true);


    }

}

最佳答案

关于java - 每 2 秒更换一次图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9606008/

相关文章:

java - 自动生成 hashcode() 和 equals() 的快捷方式是什么?

java - 从 JFrame 中的 JLabel 中删除图像

Java - 在 JButton 和 JTextArea 上画一个圆圈

javascript - 单击按钮后开始倒计时

ios - 带有通知问题的 Swift 暂停和重新创建计时器

c# - 类/静态方法实例中的 SharePoint 计时器作业 : Using SPListItem. Update()

java - ReplaceAll 正则表达式匹配所有模式,无需特定字符串

java - 如何链接多个 RxJava 的 groupBy() 方法,例如 groupBy().groupBy()

java - 如何在 Java 代码中使用 OpenMP?

java - 在 JFrame 中添加同一类的两个组件