我正在尝试将动作侦听器添加到添加到 JMenu 的字符串中...不知道如何执行此操作,JavaDoc 并没有使查找方法变得更容易。这是我的代码:
import javax.swing.*;
import java.awt.event.*;
public class GUI extends JFrame implements ActionListener{
private static final long serialVersionUID = 234614L;
private static final JMenuBar menbar = new JMenuBar();
private static final JMenu blocks = new JMenu("name");
private static final JMenu items = new JMenu("name2");
private static final JMenu edit = new JMenu("Edit");
public GUI(){
this.setSize(300, 200);
this.setTitle("");
this.setJMenuBar(menbar);
menbar.add(blocks);
menbar.add(items);
menbar.add(edit);
blocks.add("Stone");
blocks.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
}
}