Hello.

I am running a program form my book and i get this warning from eclipse that says:
"The serializable class ColorWindow does not declare a static final serialVersionUID field of type long"

import javax.swing.*; //Needed for Swing classes
import java.awt.*;    //Needed for COlor class
import java.awt.event.*;//Needed for event listener interface
/*
 * This class demonstates how to set the background color of a
 * panel and the foregorund color of a label
 */

public class ColorWindow extends JFrame{

	/**
	 * 
	 */
	private JLabel messageLabel; //To display a message
	private JButton redButton; //changes color to red
	private JButton blueButton; //changes color to blue
	private JButton yellowButton; //change color to yellow
	private JPanel panel; //a panel to build components
	private final int WINDOW_WIDTH=200;//Window width
	private final int WINDOW_HEIGHT=125;//Window hegith
	
	/*
	 * Constructor
	 */
	
	public ColorWindow(){
		//set the title bar text.
		setTitle("Colors");
		
		//set the size of the window
		setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
		
		//Specify an action for the close button
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		//create a label
		messageLabel=new JLabel("Click a button to"+
				"select a color");
		
		//create the three buttons
		redButton=new JButton ("Red");
		blueButton=new JButton("Blue");
		yellowButton=new JButton("Yellow");
		
		//register an event listener with all three buttons
		redButton.addActionListener(new RedButtonListener());
		blueButton.addActionListener(new BlueButtonListener());
		yellowButton.addActionListener(new YellowButtonListener());
		
		//Create a panel and add the components to it
		panel= new JPanel();
		panel.add(messageLabel);
		panel.add(redButton);
		panel.add(blueButton);
		panel.add(yellowButton);
		
		//Add the panel to the content pane
		add(panel);
		
		//Dsiplay the window
		setVisible(true);
		
	}
	
	/*
	 * Private inner class that handles the event
	 * when the user clicks the red button.
	 */
	
	private class RedButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			//set the panel's background to red
			panel.setBackground(Color.RED);
			
			//set the label's text to blue
			messageLabel.setForeground(Color.BLUE);
		}
	}
	
	/*
	 * Private inner class that handles the event when
	 * the user clicks the blue button
	 */
	private class BlueButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			//set the panel's background to blue
			panel.setBackground(Color.BLUE);
			
			//set the label's text to yellow
			messageLabel.setForeground(Color.YELLOW);			
		}
	}
	/*
	 * Private inner class that handles the event when
	 * the user clicks the Yellow button
	 */
	
	private class YellowButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			//set the panel's background to yellow
			panel.setBackground(Color.YELLOW);
			
			//set the label's text to black
			messageLabel.setForeground(Color.BLACK);
			}
	}
	
	
	
	
	
}

If anyone could help me?

Cheers-
haxtor

The warning comes up when a class whose objects are capable of being serialized is missing an explicit version ID (very much similar to giving version numbers to your software releases). This must be because either JFrame or the superclass/super-interfaces of JFrame implement the Serializable interface.

You can do away with this warning by adding a version ID to your class;

public class Test implements Serializable {
  
  [public|protected|private|default] static final long serialVersionUID = 1L;

}

This doesn't mean that when no serial version UID is provided, none is used during serialization. It just means that the compiler would then generate a version ID for your class which is subject to the physical structure of your source code and can change by adding/deleting/moving around methods and variables. Serial version UID is especially critical when objects of a given class are persisted or sent along the wire. By keeping the serial version UID same, you can make non-interface breaking changes to your class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.