我有一个用Swut编码的表单和一个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");
}
}
答案 0 :(得分:1)
这听起来像一个循环,Java有很好的调试服务,通常内置在你的IDE中。您应该尝试这些,看看您是否可以追踪正在发生的事情。停止处理按钮的位置,并按照此处的代码进行操作。
您也可以使用Hashmap作为停用词列表,但这不是您的错误,只是一种改进。
编辑:正如@robin指出的那样,Swing动作必须快速结束。
答案 1 :(得分:1)
我认为这是因为扫描仪的使用情况。为什么不使用outputStream? 无论出现什么问题,您都应该使用SwingWorker来执行脏IO工作,并保持UI响应。