我試圖用的ActionListener打開從一個JButton B1的應用程序:ActionListener編譯錯誤 - ;預計
public void actionPerformed(ActionEvent ae)// outside the class
{
if(ae.getSource() == b1)//b1 is the button
{
try
{
d.open(f);//f has the path to the exe file
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(OpenApps.this,ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
但是當我添加動作監聽:
b1.add ActionListener(this);// inside the class
它給出了一個錯誤:
; expected in line b1.add ActionListener(this);
請幫忙。
你能告訴我們全班同學嗎?你記得'實現ActionListener'嗎? – Vallentin