我正在努力学习使我的Java编程更进一步。我有大部分的基础知识,除了一个,这让我疯了。给我一个问题的是JComboBox。在我的示例代码中,我得到的编译错误是错误的构造,应该参数化。我在这里做错了什么?
http://docs.oracle.com/javase/7/docs/api/javax/swing/JComboBox.html#JComboBox(E [])
这是我想用JComboBox的方法,但它没有帮助我。 再次感谢您的帮助。
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
public class Test extends JFrame {
JPanel p=new JPanel();
String choices[]={
"Hello",
"Hey",
"How's it going?"
};
JComboBox cb=new JComboBox(choices);
public static void main(String[] args) {
new Test();
}
public Test() {
super("Test");
setSize(400,300);
setResizable(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
p.add(cb);
add(p);
setVisible(true);
}
}
错误消息是
3 warnings found:
File: /home/connor/Documents/Java Programming/test/Test.java [line: 14]
Warning: javax.swing.JComboBox is a raw type. References to generic type
javax.swing.JComboBox<E> should be parameterized
File: /home/connor/Documents/Java Programming/test/Test.java [line: 14]
Warning: Type safety: The constructor javax.swing.JComboBox(java.lang.Object[]) belongs
to the raw type javax.swing.JComboBox. References to generic type
javax.swing.JComboBox<E> should be parameterized
File: /home/connor/Documents/Java Programming/test/Test.java [line: 14]
Warning: javax.swing.JComboBox is a raw type. References to generic type
javax.swing.JComboBox<E> should be parameterized