public void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this button. Action events occur when a user presses or releases the mouse over this button. If l is null, no exception is thrown and no action is performed.Parameters:l - the action listener
参数的问题,把this改成null试试。运行时可能仍有异常,但是能通过编译
my1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ //执行操作 }
Adds the specified action listener to receive action events from this button. Action events occur when a user presses or releases the mouse over this button. If l is null, no exception is thrown and no action is performed.Parameters:l - the action listener
public void actionPerformed(ActionEvent e){
//执行操作
}
})
然后还要给yfsymain类定义一个public void actionPerformed(ActionEvent e)方法。