几个小时前我问这个question,但我想我没有很好地解释自己。 这里是我的代码:从字符串创建对象名称
for (a = 1; a < 14; a++) {
JMenuItem "jmenu"+a = new JMenuItem(String.valueOf(a));
"jmenu"+a.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
rrr[a] = a;
texto.setFont(texto.getFont().deriveFont((float) a));
current = a;
}
});
tamano.add("jmenu"+a);
}
我需要做的就是用这些名字创建几个JMenuItem
S:
jmenu1
jmenu2
jmenu3
jmenu4
etc...
---编辑----
我要的是每个JMenuitem
具有不同的名称:
JMenuItem "jmenu"+a //with this I can't create the JMenuItem; it's not permitted
= new JMenuItem(); //I dont care about this
您的意图是什么?你为什么想给你的变量命名? – whirlwin