3

私は少し積み重ねているので、誰かが何かアイデアを持っているならそれは役に立ちます。そのため、現在、プログラムはコンパイルおよび実行されていますが、終了する方法がわかりません。私は日食を使用しています。私がやりたいのは、プログラムを開始して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);


    }

}
4

1 に答える 1

4
  • 、、、、、Icon / ImageIconsに置くQueue_ Map_ Array_ListVector

  • アレイからのスイングタイマーピックアップを開始することによってIcon / ImageIcon

  • JLabel#setIcon()を使用して、 Icon/ImageIconsJLabelに追加します。

  • Swing GUIに関連するコードは、から初期化する必要がありinvokeLater()ます

于 2012-03-07T17:26:07.350 に答える