Closed. This question does not meet
Stack Overflow guidelines。它当前不接受答案。
想改善这个问题吗?更新问题,以便将其作为
on-topic用于堆栈溢出。
7年前关闭。
Improve this question
我正在尝试使用actionlistener从jbutton b1打开一个应用程序:
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);
}
}
}
但是当我添加 Action 监听器时:
b1.add ActionListener(this);// inside the class
它给出一个错误:
; expected in line b1.add ActionListener(this);
请帮忙。