我以为这对我来说会简单得多,但是我没有想到这个概念。简而言之,我提出了一种淡化音频的方法,并使用Thread.Sleep在for循环中使其“等待”。在调用该方法之前,我将几个标签和文本字段设置为不可见,但它们要等到线程睡眠更改之后才能进行。我试图将标签包装在do-while循环中以强制使用它们,甚至尝试在其后调用redraw,但是它没有解决任何问题。任何意见,将不胜感激:
编辑为包括ActionPerformed:
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == quit)
{
System.exit(0);
}
else if(e.getSource() == play)
{
System.out.println("PLAY");
quit.setVisible(false);
quit.setEnabled(false);
play.setVisible(false);
play.setEnabled(false);
GameActivated();
}
else if(e.getSource() == submitTeams)
{
teamOneName = teamOneTF.getText();
teamTwoName = teamTwoTF.getText();
Swinpublic void actionPerformed(ActionEvent e)
{
if(e.getSource() == quit)
{
System.exit(0);
}
else if(e.getSource() == play)
{
System.out.println("PLAY");
quit.setVisible(false);
quit.setEnabled(false);
play.setVisible(false);
play.setEnabled(false);
GameActivated();
}
else if(e.getSource() == submitTeams)
{
teamOneName = teamOneTF.getText();
teamTwoName = teamTwoTF.getText();
SwingUtilities.invokeLater(new Runnable(){
public void run(){
teamOneLabel.setVisible(false);
teamOneTF.setVisible(false);
teamTwoLabel.setVisible(false);
teamTwoTF.setVisible(false);
submitTeams.setVisible(false);
}
});
}
else
System.out.println("Error: Button pressed with no known source.");
}
以下是被调用的AudioHandler1的内部:
for(int count = 0; count < 71; count++)
{
gainControl.setValue((float) count*-1);
System.out.println("Waiting!" + Math.random());
try
{
Thread.sleep(50);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
最佳答案
您在此处阻止了EDT。使用SwingWorker调用AudioHandler1
new SwingWorker<Void,Void>()
{
@Override
protected Void doInBackground() throws Exception
{
AudioHandler1("Theme.wav",false,true);
return null;
}
}.execute();