0

I have 39 errors but the are all the same error on the same thing (kindve) and I don't know what's wrong! The errors are all similar to this one:

Setup.java:31: error: ')' expected
                                                Selected[0] = (0,0,0);
                                                                ^
Setup.java:31: error: not a statement
                                                Selected[0] = (0,0,0);
                                                                 ^
Setup.java:31: error: ';' expected
                                                Selected[0] = (0,0,0);
                                                                  ^

This is really confusing and I don't know whats wrong Please help! Here is my code:

import java.awt.color.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Setup {
    public static void main(String[] args) {
        JFrame f = new JFrame("Test Setup wizard");
        Container a = f.getContentPane();
        a.setBackground(Color.white);
        a.setLayout(new  FlowLayout());
        JLabel question1 = new JLabel("What would you like the background color to be?");
        JButton Next = new JButton("Next");
        String Colors[];
        Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};
        JList colors = new JList(Colors);
        colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        colors.setLayoutOrientation(JList.VERTICAL);
        JScrollPane listScroller = new JScrollPane(colors);
        f.add(question1);
        f.add(colors);
        f.add(Next);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(500,500);
        f.setVisible(true);
        final ImageIcon img = new ImageIcon(HardDisk.jpg);
        f.setIconImage(img.getImage());
        Next.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent Ev) {
                    final String selected = colors.getSelectedItem().toString();
                    final Color[] Selected = new Color[1];
                    if (selected == "black") {
                        Selected[0] = (0,0,0);
                    }
                    else if (selected == "blue") {
                        Selected[0] = (0,0,255);
                    }
                    else if (selected == "cyan") {
                        Selected[0] = (0,225,225);
                    }
                    else if (selected == "darkGray") {
                        Selected[0] = (169,169,169);
                    }
                    else if (selected == "gray") {
                        Selected[0] = (128,128,128);
                    }
                    else if (selected == "green") {
                        Selected[0] = (0,255,0);
                    }
                    else if (selected == "lightGray") {
                        Selected[0] = (211,211,211);
                    }
                    else if (selected == "magenta") {
                        Selected[0] = (255,0,255);
                    }
                    else if (selected == "orange") {
                        Selected[0] = (255,165,0);
                    }
                    else if (selected == "pink") {
                        Selected[0] = (255,20,147)
                    }
                    else if (selected == "red") {
                        Selected[0] = (255,0,0);
                    }
                    else if (selected == "white") {
                        Selected[0] = (255,255,255);
                    }
                    else if (selected == "yellow") {
                        Selected[0] = (255,255,0);
                    }
                f.dispose();
                JLabel complete = new JLabel("You are now complete.");
                JFrame f = new JFrame("Complete");
                Container a = f.getContentPane();
                a.setBackground(Selected[0]);
                f.add(complete);
                f.setSize(500,500);
                f.setVisible(true);
                f.setIconImage(img.getImage());
            }
            });
    }
}

Any help appreciated! Thanks!

ATTENTION: THIS POST HAS BEEN MOVED TO: HERE. Thank you for your cooperation

Community
  • 1
  • 1

3 Answers3

3

I suspect you wanted something like:

Selected[0] = new Color(0,0,0);

But you should also read this question, as you're currently comparing string references using ==. To be honest, you'd be better off populating a Map<String, Color> rather than using all of those if statements.

There's also no obvious reason why you're using an array instead of just a simple variable of type Color.

Community
  • 1
  • 1
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I'm using an array or else you get a compile error like: `variable accessed from inner class, must be declared final`. –  Jul 09 '13 at 17:18
2

Well, (0, 0, 0) by itself isn't a statement.

I think you meant to create a new Color object, e.g.

Selected[0] = new Color(0, 0, 0);

Additionally, don't compare String values with the == operator, which compares object references to determine if they are the same object. Use the equals method in String to compare String values.

rgettman
  • 176,041
  • 30
  • 275
  • 357
2

You are missing the Color class to call the constructor using RGB values:

replace this

Selected[0] = (0,0,0);

with

Selected[0] = new Color(0,0,0);
jball
  • 24,791
  • 9
  • 70
  • 92
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136