Thread在内部类中的使用

good_shi good_shi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
private JButton getClassNameButton() {
if (classNameButton == null) {
classNameButton = new JButton();
classNameButton.setText("运行应用程序");
classNameButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
/*if(!(run.isAlive())){
run = new Thread(new ExciseExec());
}*/
try{
run.start();
}catch(Exception e1){

}
//card.show(getAreaPanel(),"dosTextArea");
}
});
}
return classNameButton;
}
该JButton内部类中的Thread类实现时用this参数不行,如果用自身主类(new ExciseExec())参数则重新创建了一个JFram的试图,相应的Run方法
public void run() {
System.out.println("run");
if(Thread.currentThread() == compiler){
getCompilerTextArea().setText("");
String temp = getInputTextArea().getText().trim();
System.out.println("temp :"+temp);
byte[] b = temp.getBytes();
int leng = b.length;
String fileName = getFileNameTextField().getText().trim();

try {
loadFile = new File(fileName);
String name = loadFile.getAbsolutePath();
System.out.println("name"+name);
FileOutputStream fos = new FileOutputStream(loadFile);
fos.write(b,0,leng);
fos.close();
} catch (IOException e) {}
}
却不能执行if内部的循环,请问各位大侠如何解决这个问题!
...全文
评论 2
收藏 已收藏
分享
返回顶部
good_shi
Java SE 62,620 成员 307,251 内容