我有一個窗體用JButton編寫,我點擊完成一個動作。但是當我點擊它時,我的框架會掛起。我不能退出它,直到我使用任務欄結束它。問題是什麼?這是我的代碼:當我點擊按鈕時,爲什麼我的揮杆會掛起?
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String[] stopwords = {"a", "sometime", "sometimes", "somewhere", "still",
"such", "system", "take", "ten", "than", "that", "the", "their",
"them", "themselves", "then", "thence", "there", "thereafter",
"thereby", "therefore", "therein", "thereupon", "these", "they",
"thickv", "thin", "third", "this", "those", "though", "three",
"through", "throughout", "thru", "thus", "to", "together", "too",
"top", "toward", "towards", "twelve", "twenty", "two", "un",
"under", "until", "up", "upon", "us", "very", "via", "was", "we",
"well", "were", "what", "whatever", "when", "whence", "whenever",
"where", "whereafter", "whereas","whereby", "wherein", "whereupon",
"wherever", "whether", "which", "while","whither", "who", "whoever",
"whole", "whom", "whose", "why", "will", "with", "within", "without",
"would", "yet", "you", "your", "yours", "yourself", "yourselves",
"contact", "grounds", "buyers", "tried", "said,", "plan", "value",
"principle.", "forces", "sent:", "is,", "was", "like", "discussion",
"tmus", "diffrent.", "layout", "area.", "thanks", "thankyou",
"hello", "bye", "rise","fell","fall","psqft.","http://","km","miles"};
try {
Scanner fip1 = new Scanner(new File(selectedFile));
FileOutputStream out=new FileOutputStream("d:/StopWords.txt");
while(fip1.hasNext()) {
int flag=1;
String s1=fip1.next();
s1=s1.toLowerCase();
for(int i=0;i<stopwords.length;i++){
if(s1.equals(stopwords[i])) {
flag=0;
}
}
if(flag!=1) {
// System.out.println(s1);
// jTextArea1.append("\n"+s1);
PrintStream p=new PrintStream(out);
p.println(s1);
p.close();
}
}
JOptionPane.showMessageDialog(null,"STOP WORD REMOVAL IS DONE");
} catch(Exception e){
System.err.println("cannot read file");
}
}
'selectedFile'包含什麼?這可能只是一堆令牌,操作很長。 – 2013-03-07 14:45:49
你的輸入文本文件有多大? – yaens 2013-03-07 14:46:17
由於Swing是單線程的,因此當您使用長時間運行的操作阻塞線程時,它無法更新UI。 – Robin 2013-03-07 14:46:28