[CODE]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Tim extends JFrame{
JPanel pnl;
JButton btn1=new JButton("开始");
JButton btn2=new JButton("停止");
FlowLayout flowLayout=new FlowLayout();
Class cl;
ActionListener listener=new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.start();
System.out.println("aaaaaaaaaaaaaaaa");
}
};
Timer obj=new Timer(500,listener);
Tim(){
super("Timer");
men();
action();
}
void men(){
pnl=(JPanel)getContentPane();
pnl.setLayout(flowLayout);
setSize(new Dimension(400,300));
pnl.add(btn1);
pnl.add(btn2);
this.setVisible(true);
}
void action(){
btn1.addActionListener(listener);
btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
obj.stop();
}
});
}
public static void main(String[] args){
Tim cc=new Tim();
}
}
[/CODE]
最好还是不要写成这个样子,你激发的时候应该判断一下source是谁好一些
Java,My Love!