每2秒换一次图片 [英] change pictures every 2 sec
问题描述
我有点累了,所以如果有人有任何想法,那将是有帮助的. 所以目前该程序正在编译和运行,但我不知道如何完成它. 我正在使用日食.我想做的是,当我启动程序时,每2秒更改4张不同的图片,因此,如果您有任何建议,请不要害羞.这是程序.
I stack a bit so if anyone has any ideas it would be helpful. So currently the program is compiling and running but I do not know how to finish it. I am using eclipse. What i want to do is when i start the program to change 4 different pictures in every 2 seconds so if you have any advices do not be shy. Here is the program.
/** 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);
}
}
推荐答案
-
将
Icon / ImageIcons
放入Queue
,Map
,Array
,List
,Vector
put
Icon / ImageIcons
to theQueue
,Map
,Array
,List
,Vector
通过启动 Swing Timer 拾取
Icon / ImageIcon
来自数组add Icon / ImageIcons to the JLabel, by using JLabel#setIcon()
代码应从
invokeLater()
初始化,更多信息请参见初始线程code related for Swing GUI should be initialized from
invokeLater()
, more in the Initial Threads这篇关于每2秒换一次图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!