SwingWorker 用于以下目的:
done()方法在任务结束时使用长时间运行的任务生成的结果更新GUI .publish()和process()方法生成和发布的中间结果不时更新GUI .SwingUtilities.invokeLater() 可以执行以下任务:
SwingWorker.execute()我们可以执行,而不是从EDT 执行方法,ExecutorService.submit(new MyRunnable())因为它还将创建另一个可以执行长时间运行任务的线程.done()case1的方法编写)SwingUtilites.invokeLater(new RunnableToExecuteDoneMethodCode()).process()case1的方法编写)SwingUtilites.invokeLater(new RunnableToExecuteProcessMethodCode())放在我们publish()在case1中调用方法的地方.我问这个问题是因为Java-SwingWorker中指定的问题- 我们可以从其他SwingWorker调用一个SwingWorker而不是EDT可以通过SwingUtilities.invokeLater()但是无法解决SwingWorker
美好的一天 .我想使用pepraredStatement插入数据库.但是每当我添加数据库部分(连接和pepraredStatement)时,"UPLOAD"按钮就会没有响应.但当我删除任何与数据库相关的内容时,我的所有按钮都正常工作.你可以在这里找到代码http://pastebin.com/euKdWhr2.
我将非常感谢任何帮助或建议.可能我在数据库部分缺少一些东西.
public void actionPerformed(ActionEvent ev)
{
String file = fileField.getText();
SetGetQuestionFileName pattern = new SetGetQuestionFileName(file);
ConnectToDatabase database = new ConnectToDatabase();
try
{
///////// check whether textfile is empty or not
if( ev.getActionCommand().equals("UPLOAD"))
{
if(fileField.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"File field can not be empty!!! Please try again.","ALERT", JOptionPane.ERROR_MESSAGE);
}
else
{
File fi = new File(fileField.getText());
//////////////// perform upload
try
{
String sql = "INSERT INTO testsystem.questionnaire (category_questions, questions, correct_answer)" + "VALUES (?, ?, ?)";
PreparedStatement st = null; …Run Code Online (Sandbox Code Playgroud)