Java 执行方法的困难
嗨,伙计们,当点击提交按钮时,我开始增加,当它是2时,我想要它更改图片,当我是4时,我想要更改到另一张图片,但它不这样做,如果有人有想法,这将是伟大的。我正在使用eclipse,程序正在编译和运行。这是密码Java 执行方法的困难,java,swing,concurrency,jbutton,actionlistener,Java,Swing,Concurrency,Jbutton,Actionlistener,嗨,伙计们,当点击提交按钮时,我开始增加,当它是2时,我想要它更改图片,当我是4时,我想要更改到另一张图片,但它不这样做,如果有人有想法,这将是伟大的。我正在使用eclipse,程序正在编译和运行。这是密码 /** Here is the GUI of the program * class name SlideShowGui.java * @author Kiril Anastasov * @date 07/03/2012 */ import java.awt.*; import j
/** 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, Runnable
{
JLabel name, comments, images;
JTextField namejtf, commentsjtf, captionjtf;
JButton submit;
ImageIcon pictures;
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);
this.add(images);
pictures = new ImageIcon("galileo2.jpg");
this.add(images);
captionjtf = new JTextField(24);
this.add(captionjtf);
}
public void actionPerformed(ActionEvent ae)
{
Thread t = new Thread(this);
t.start();
if(ae.getSource() == submit)
{
int i = 0;
boolean go = true;
while(go)
{
i++;
System.out.println(i);
try
{
Thread.sleep(2000);
if(i == 2)
{
pictures = new ImageIcon("galileo2.jpg");
images.setIcon(pictures);
}
}
catch (InterruptedException ie)
{
System.out.println("thread exception");
}
// pictures = new ImageIcon("galileo2.jpg");
// images.setIcon(pictures);
System.out.println("test");
}
}
}
public void run()
{
}
}
/**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);
}
}
决不,真的决不在Swing中使用
线程.sleep()
,也不从Swing侦听器初始化,此代码行导致在JComponent中重新绘制时冻结或停止,使用Swing计时器
,其余在my中,清除此代码
编辑--->@Binyamin Sharet我很高兴在这里见到你:-)也许我被绑定了,但是什么是pictures=new-ImageIcon(“galileo2.jpg”)代码>,这个文件放在哪里,在Java包中,硬盘上的某个地方???或者???,因为您的图标/图像图标可能为空:-)