I have a program where I want to set the color of a JPanel
when its object is created through its constructor. Right now this is what I have.
However this is obviously quite inefficient. I was wondering if there was some way I could pass the string parameter directly into the setBackground() method to set the color?
MyPanel(String bcolor) {
super();
if (bcolor.equals("red"))
setBackground(Color.RED);
if (bcolor.equals("blue"))
setBackground(Color.BLUE);
if (bcolor.equals("green"))
setBackground(Color.GREEN);
if (bcolor.equals("white"))
setBackground(Color.WHITE);
if (bcolor.equals("black"))
setBackground(Color.BLACK);
}