我积累了一点,所以如果有人有任何想法,那会很有帮助。
目前该程序正在编译并运行,但我不知道如何完成它。
我正在使用日食。我想做的是,当我启动程序时,每 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);
}
}
put Icon / ImageIcons
to the Queue
, Map
, Array
, List
, Vector
通过开始摇摆计时器 http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html捡起Icon / ImageIcon
从数组
add 图标/图像图标 http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html to the JLabel http://docs.oracle.com/javase/tutorial/uiswing/components/label.html, 通过使用JLabel#setIcon() http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html#setIcon%28javax.swing.Icon%29
与 Swing GUI 相关的代码应该从invokeLater()
,更多在初始线程 http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)