设置向导的编译错误错误 - 找不到符号 [英] Bad compile errors for a setup wizard-Cannot find symbol

查看:860
本文介绍了设置向导的编译错误错误 - 找不到符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为税务申请建立设定精灵,我收到我不知道如何解决的错误。请帮忙!
我的错误是:

I am making a setup wizard for a tax application and I get errors that I don't know how to solve. Please help! My Error is:

Setup.java:16: error: cannot find symbol
                Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};
                ^
  symbol:   variable Colors
  location: class Setup
Setup.java:17: error: cannot find symbol
                final JList colors = new JList(Colors);
                                               ^
  symbol:   variable Colors
  location: class Setup
Setup.java:24: error: cannot find symbol
                        Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};
                        ^
  symbol: variable Colors
Setup.java:25: error: cannot find symbol

如果任何人知道答案,并使用StackOverflow,请问他们awnser这个问题!
这是我的代码:

If anybody knows the answer, and uses StackOverflow, please ask them to awnser this question! Here is my code:

import java.awt.event.*;
import javax.swing.event.*;
public class Setup {
    @SuppressWarnings("unchecked")
    private static String colorSelected;
    public static void main(String[] args) {
        final 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");
        Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};
        final JList colors = new JList(Colors);
        colors.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        colors.setLayoutOrientation(JList.VERTICAL);
        JScrollPane listScroller = new JScrollPane(colors);
        colors.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    int index = e.getFirstIndex();
                    Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};
                    String colorSelected = Colors[index];
                    }
                });
        f.add(question1);
        f.add(listScroller);
        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 Color[] Selected = new Color[1];
                    if (colorSelected .equals("black")) {
                        Selected[0] = new Color(0,0,0);
                    }
                    else if (colorSelected .equals("blue")) {
                        Selected[0] = new Color(0,0,255);
                    }
                    else if (colorSelected .equals("cyan")) {
                        Selected[0] = new Color(0,225,225);
                    }
                    else if (colorSelected .equals("darkGray")) {
                        Selected[0] = new Color(169,169,169);
                    }
                    else if (colorSelected .equals("gray")) {
                        Selected[0] = new Color(128,128,128);
                    }
                    else if (colorSelected .equals("green")) {
                        Selected[0] = new Color(0,255,0);
                    }
                    else if (colorSelected .equals("lightGray")) {
                        Selected[0] = new Color(211,211,211);
                    }
                    else if (colorSelected .equals("magenta")) {
                        Selected[0] = new Color(255,0,255);
                    }
                    else if (colorSelected .equals("orange")) {
                        Selected[0] = new Color(255,165,0);
                    }
                    else if (colorSelected .equals("pink")) {
                        Selected[0] = new Color(255,20,147);
                    }
                    else if (colorSelected .equals("red")) {
                        Selected[0] = new Color(255,0,0);
                    }
                    else if (colorSelected .equals("white")) {
                        Selected[0] = new Color(255,255,255);
                    }
                    else if (colorSelected .equals("yellow")) {
                        Selected[0] = new Color(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());
            }
            });
    }
}


P.S:只解决第一个错误!

Any help is appreciated! P.S: Only solve the first error!!! That fixes the others too!!!

推荐答案

尝试在声明中留下数组的大小,并使用花括号代替方括号。如:

try leaving off the size of the array in the declaration and using curly braces instead of square braces. Such as:

Colors = new String[]{"black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"};

这篇关于设置向导的编译错误错误 - 找不到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆