我有 39 个错误,但在同一件事上都是相同的错误(kindve),我不知道出了什么问题!错误都与此类似:
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);
^
这真的很混乱,我不知道出了什么问题请帮助!这是我的代码:
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());
}
});
}
}
任何帮助表示赞赏!谢谢!
注意:此帖子已移至: 此处。 谢谢您的合作