我有一个用netbeans构建的简单GUI,以及打开相应pdf的四个按钮数组。我有一个动作监听器,它监听所有四个按钮,如下所示:
private void creditMemoButActionPerformed(java.awt.event.ActionEvent evt) {
Desktop dt = Desktop.getDesktop();
String buttonText = this.getText(); //obviously, this is the problem.
File pdf = new File("data/"+buttonText+".pdf");
dt.open(pdf);
}
问题是注释行。显然,该功能不存在,但它简单地说明了在统一的事件监听器中我不知道如何实现的功能。令人惊讶的是,至少对我来说,这并不容易转让。
如何获取触发动作事件的按钮文本?