Q:

java paint applet - need help adding action on radio buttons

I need to make a java applet that allows the user to paint with the mouse.  When the applet is launched, a second window opens that allows the user to select one of 6 different colors to paint with. 
First, I wrote code to construct a toolbar window which contains a getcurrentcolor method.  I can't seem to link the button press with the color change. 
If I launch the applet, the toolbarwindow opens successfully and I'm able to paint in black, so my only problem is selecting a color on the toolbar window and painting in that color. 
toolbar code:https://gist.github.com/anonymous/3c053c69112f46d17440
painting applet code: https://gist.github.com/anonymous/aca7929dbcfc08008f30

A:

I gave an approach here for 3 buttons, you can add the rest.  The idea is that you keep a currently selected color field and update it each time a button is selected via the ActionListener.  A map from the button to the color it represents is not necessary, but makes the code more manageable. 
public class ToolBarWindow extends JFrame {

    private static Map<JRadioButton, Color> colors = new HashMap<>();
    private static Color currentColor = Color. BLACK;

    public static void main(String[] args) {

        ToolBarWindow frame = new ToolBarWindow();
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
        frame.setTitle("Colors");
        frame.setVisible(true);
    }

    public ToolBarWindow() {

        JPanel jpRadioButtons = new JPanel();
        jpRadioButtons.setLayout(new GridLayout(3, 1));

        // put the other colors
        JRadioButton red = new JRadioButton("red");
        JRadioButton black = new JRadioButton("black");
        JRadioButton magenta = new JRadioButton("magenta");

        red.addActionListener(new MyActionListener());
        black.addActionListener(new MyActionListener());
        magenta.addActionListener(new MyActionListener());

        jpRadioButtons.add(red);
        jpRadioButtons.add(black);
        jpRadioButtons.add(magenta);

        colors.put(red, Color. RED);
        colors.put(black, Color. BLACK);
        colors.put(magenta, Color. MAGENTA);

        add(jpRadioButtons, BorderLayout. WEST);

        ButtonGroup bg = new ButtonGroup();
        bg.add(red);
        bg.add(black);
        bg.add(magenta);
    }

    Color getCurrentColor() {

        return currentColor;
    }

    private class MyActionListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {

            currentColor = colors.get(e.getSource());
        }
    }
}

