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内部的循环,请问各位大侠如何解决这个问题!
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内部的循环,请问各位大侠如何解决这个问题!
解决方案 »
- 求10个数字可能的所有组合,只能用数组基本数据类型
- java jdbc
- [模式]这样的结构算是 Chain of responsibility 么?
- 请问SWING的UI类如何使用,最好有例子。 50分
- 高手看看下面的代码哪里错了
- 我的程序换了一个皮肤后就不能显示中文了为什么?--请教 急急!
- Socket的测试程序,本地echo端口怎么连接不上呢?
- 如何在html中引用applet程序!!!!!!
- forte for java
- 请问谁有Jbuilder5 Enterpeise的注册码,谢谢了!
- swing ,Frame 获取标题栏上最大化和关闭按钮 和 static main()的问题
- 在Java中如何使用异常机制来保证程序的正常运行呢.......拜先
Thread run = new Thread(ExciseExec.this);
这是必须的,为什么这里不能用简单的用"this",那是因为你在构造run的时候,是把它内部类中.