search

Home  >  Q&A  >  body text

java - 程序发布之后swingworker不能正常工作

一个窗体,初始化的时候需要读取数据库,根据查询结果进行进一步操作。代码如下,使用提示框代表窗体的初始化部分。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

<code>public class TestFrame extends JFrame {

    public TestFrame() {

        this.setTitle("测试窗体");

        initGUI();

    }

 

    private void initGUI() {

 

        SwingWorker worker = new SwingWorker<java.util.List<ConditionTerm>, Void>() {

            @Override

            protected java.util.List<ConditionTerm> doInBackground() throws Exception {

                condition.setTypeFlag(ConditionTermType.NORMAL);

                ConditionTermDao dao = new ConditionTermDao();

                return dao.find();

            }

 

            @Override

            protected void done() {

                FlowLayout layout = new FlowLayout();

                layout.setAlignment(FlowLayout.LEFT);

                setLayout(layout);

                try {

                    JOptionPane.showMessageDialog(new JPanel(), "1");

                    java.util.List<ConditionTerm> conditionTerms = get();

                    JOptionPane.showMessageDialog(new JPanel(), conditionTerms.size());

                } catch (InterruptedException e) {

                    e.printStackTrace();

                } catch (ExecutionException e) {

                    e.printStackTrace();

                }

                validate();

                repaint();

            }

        };

        worker.execute();

    }

 

    public static void main(String[] args) {

        SwingUtilities.invokeLater(() -> {

            TestFrame t = new TestFrame();

            t.setVisible(true);

        });

    }

}

</code>

开发环境为intelliJ idea 13 ,debug模式下运行正常,即:能弹出提示框,显示“1”,然后显示查询结果的条数。打包之后只弹出一次提示框显示“1” ,然后就没有反应了。

更新

问题已经解决

解决思路:使用java -jar xx.jar运行打包之后的程序,查看运行过程,发现有异常抛出,根据异常信息,成功解决问题。

迷茫迷茫2950 days ago785

reply all(0)I'll reply

No reply
  • Cancelreply