0
如何为列表中的每个按钮执行ActionListener?我正在使用JGraphMenu
&想要显示每个项目的警报。使用JGraphMenu的菜单项的ActionListener
这里是我的代码:
public static void main(String[] args){
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
List<String> MenuItem = new ArrayList<String>();
MenuItem.add("Choose The XML File");
MenuItem.add("Generate the tree");
MenuItem.add("Generate the latex code");
MenuItem.add("Generate automata");
List<ActionListener> listeners = new ArrayList<ActionListener();
for(int i=0; i<4; i++){
listeners.add(null);
}
JGraphMenu menu = new JGraphMenu(
ConstantesStyles.NOIR,
JGraphMenu.VERTICAL,
MenuItem, listeners
);
JPanel panel = new JPanel();
panel.add(menu);
panel.setSize(50, 100);
f.add(panel, BorderLayout.WEST);
f.setSize(500, 400);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}