Adding a ActionPerformed Array to a String Array

Posted by user267490 on Stack Overflow See other posts from Stack Overflow or by user267490
Published on 2010-04-16T11:40:09Z Indexed on 2010/04/16 11:43 UTC
Read the original article Hit count: 198

Filed under:

Hey,

Before you guys ask, yes I've searched online for the answer, but everything I found just leaves a lil confuse and nothing is recent so asking in those forums won't really help.

My problems is this:

I have an array that holds my name for a menu.

String[] fontColor = new String[] {"Red", "Blue", "Green"};

for (int i = 0; i < fontColors.length; i++) {
     JMenuItem fontC = new JMenuItem(fontColors[i]);
     fontC.addActionListener(new fontColorAction());
     changeFontColor.add(fontC);
}

Then I have an array that holds my color change in a class called fontColorAction

in that class I have another array that does the same thing as my string array except all thats in the statement is textarea.setForeground(colorArr[i]);

that will set the setForeground() in order, but now how do I successfully attact the action listner in my class to my menuItems?

my class looks like this

private class fontColorAction implements ActionListener {
     Color[] colorArr - new Color[] {"Color.RED","Color.BLUE","Color.GREEN"};
     public void actionPerformed(ActionEvent e){
          for(i = 0; i < collorArr.length; i++){
               textarea.setForeground(colorArr[i]);
          }
     }
}

© Stack Overflow or respective owner

Related posts about java