gpt4 book ai didi

java - 为什么单击按钮时我的挥杆会挂起?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:30:12 24 4
gpt4 key购买 nike

我有一个用 Swing 编码的带有 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");
}
}

最佳答案

这听起来像是一个循环,Java 有非常好的调试服务,通常内置在您的 IDE 中。你应该尝试那些,看看你是否可以追踪正在发生的事情。在您处理按钮的地方停下来,然后按照此处的代码进行操作。

您也可以将 Hashmap 用于停用词列表,但这不是您的错误,只是一种改进。

编辑:正如@robin 指出的那样,Swing Action 必须迅速结束。

关于java - 为什么单击按钮时我的挥杆会挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15274075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com