我正在使用netbeans,这是按钮点击功能。我希望单击按钮后立即运行进度条。该模式将是不确定的,因为我正在调用类WriteToFile
并且它在后台运行几分钟并且不返回任何值。
private void createFileButtonActionPerformed(java.awt.event.ActionEvent evt)
{
String str = (String) selectTypeComboBox.getSelectedItem();
createFileButton.setEnabled(false);// Prevent more button presses
String filepaths = fileChooserWindow.getSelectedFile().getAbsolutePath();
String selectType =(String) selectTypeComboBox.getSelectedItem();
WriteToFile writeOBJ;
writeOBJ = new WriteToFile(filepaths,start,selectType);
try
{
writeOBJ.selectType();
}
catch (SQLException | IOException | RuntimeException ex)
{
System.exit(0);
}
}
答案 0 :(得分:0)
让这个工作:
jProgressBar1.setVisible(true);
jProgressBar1.setIndeterminate(true);
Executor executor = java.util.concurrent.Executors.newSingleThreadExecutor();
executor.execute(new Runnable(){
@Override
public void run(){
String str = (String) selectTypeComboBox.getSelectedItem();
createFileButton.setEnabled(false);// Prevent more button presses
String filepaths = fileChooserWindow.getSelectedFile().getAbsolutePath();
String selectType =(String) selectTypeComboBox.getSelectedItem();
WriteToFile writeOBJ;
writeOBJ = new WriteToFile(filepaths,start,selectType);
try
{
writeOBJ.selectType();
}
catch (SQLException | IOException | RuntimeException ex)
{
System.exit(0);
}
jProgressBar1.setVisible(false);
}