I have been learning Java from thenewboston on YouTube, and after following the two JComboBox tutorials here and here, I have found three warnings in my program.
FirstClass.java
import javax.swing.JFrame;
public class FirstClass {
public static void main(String args[]) {
Scrabble go = new Scrabble();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300,200);
go.setVisible(true);
}
}
Scrabble.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Scrabble extends JFrame {
private JComboBox box;
private JLabel picture;
private static String[] filename = {"Coraline_Small.jpg", "fish.jpg"};
private Icon[] pics = {new ImageIcon(getClass().getResource(filename[0])), new ImageIcon(getClass().getResource(filename[1]))};
public Scrabble() {
super("JComboBox");
setLayout(new FlowLayout());
box = new JComboBox(filename);
box.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange() == ItemEvent.SELECTED);
picture.setIcon(pics[box.getSelectedIndex()]);
};
}
);
add(box);
picture = new JLabel(pics[0]);
add(picture);
}
}
The first warning appears on line 5 of Scrabble.java,
public class Scrabble extends JFrame {
saying:
The serializable class Scrabble does not declare a static final serialVersionUID field of type long
The second warning appears on line 7 of Scrabble.java,
private JComboBox box;
saying:
JComboBox is a raw type. References to generic type JComboBox should be > > parameterized
The third and final warning appears on line 18 of Scrabble.java,
box = new JComboBox(filename);
saying:
Multiple markers at this line - Type safety: The constructor JComboBox(Object[]) belongs to the raw type JComboBox. References to generic type JComboBox should be
parameterized - JComboBox is a raw type. References to generic type JComboBox should be parameterized
Also, the program runs successfully.
All help is appreciated and thanks in advance,
Jeremy