Greeting, I'm trying to do this:
public float a=0;
for(a=1 ; a<100;a++){
String fuent="font"+String.valueOf((int)a);
JMenuItem fuent=new JMenuItem(String.valueOf(a));
fuent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){texto.setFont(texto.getFont().deriveFont(a)); current=a;}});
tamano.add(fuent);
}
But it throws these errors:
cambiar.java:71: error: variable fuent is already defined in constructor cambiar()
JMenuItem fuent=new JMenuItem(String.valueOf(a));
^
cambiar.java:72: error: cannot find symbol
fuent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){texto.setFont(texto.getFont().deriveFont(a)); current=a;}});
^
symbol: method addActionListener(<anonymous ActionListener>)
location: variable fuent of type String
2 errors
[Finished in 0.5s with exit code 1]
I've trying to do this:
JMenuItem (String)fuent=new JMenuItem(String.valueOf(a));
JMenuItem System.out.println(fuent)=new JMenuItem(String.valueOf(a));
but none works.
---EDIT---- I think some are confuse about what I want:
String fuent="font"+String.valueOf((int)a);
JMenuItem fuent=new JMenuItem(String.valueOf(a));//(Here sould go the value of the String, Example "font1")
fuent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){texto.setFont(texto.getFont().deriveFont(a)); current=a;}});
tamano.add(fuent); //(Same Here)