The ActionListener. It will call the setText() method, as it appears you already did. It just wasn't doing it because the JLabel had been null.
Type: Posts; User: javapenguin
The ActionListener. It will call the setText() method, as it appears you already did. It just wasn't doing it because the JLabel had been null.
This code below, a slight alteration of your code, worked for me.
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import...
Try initializing the variable "display".
Then add it to your GUI.
Also, try setting p1 to be your content pane or something.
import javax.swing.*;
I was able to make something similar work, though I had the HashMap be a class variable rather than a final variable like you had it.
import java.util.HashMap;
import...
To make FF0000 show, do something like this
System.out.println(map.get("Red"));
The get method returns the value, if there is one, associated with that key.
Because Strings have to be enclosed by literals. It's taking them as variables.
Try this
map.put("Red", "FF0000");