关于java监听的疑问

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:20:50
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Temp extends JFrame{
private final int WIDTH=40,HEIGHT=100;
JButton but1=new JButton("exit");

public Temp(){
Container pane=getContentPane();
pane.setLayout(new GridLayout(1,1));
pane.add(but1);

but1.addActionListener(new bl());

this.setSize(WIDTH,HEIGHT);
this.setVisible(true);
this.setDefaultCloseOperation(3);
}

public static void main (String[] args) {
new Temp();
}
}
class bl implements ActionListener{
public void actionPerformed(ActionEvent e){
//System.exit(0);
}
}

bl我把它放到Temp的内部,总是出现问题,编译可以通过,但是运行出错
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
放到外面也是时好时坏

这程序在我的机器上没有问题,运行自如,没有错误报告.
我的机器:
Linux Redhat Core4
Eclipse3.2.1
JDK1.5 Update 6
你程序里面
this.setDefaultCloseOperation(3);
建议改为
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
效力是一样的,但是更加规范.