我必须在java swing actionperformed方法中调用一个方法。但是当我点击按钮时没有任何反应。如何解决这个问题?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
hellocalled();
}
}
答案 0 :(得分:6)
您需要向按钮添加动作侦听器才能响应click事件:
Button b = new Button();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
jButton1ActionPerformed(evt);
// call the method jButton1ActionPerformed
// or you can call the one you have defined `hellocalled();` here
}
}
}