目前的界面是这样的:
点击Start之后会调用之前写的爬虫去爬取新闻评论,但是在点击了之后,整个界面就卡住了。。。什么按钮都不能用,刚才和professor说了一下,他说应该把界面的线程和程序的逻辑的线程分开。
回实验室之后在网上查了一下,根据这篇博客 http://www.java3z.com/cwbwebhome/article/article20/200011.html?id=4781 有了如下修改。在监听中加入了一个新线程,问题解决~
StartButton = new JButton("Start");
StartButton.addActionListener(this);
StartButton.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
Runnable runnable = new Runnable() {
public void run() {
try {
new ThreadPool();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
};
new Thread(runnable).start();
}
});
刚才测试,界面又可以最小化到托盘了,可是点击最小化的时候出现如下报错:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding TrayIcon that is already added
at java.awt.SystemTray.add(Unknown Source)
at UserInterface.MainPage$3.windowIconified(MainPage.java:491)
意思应该是说已经加入不用再加入了。未解决