Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Warning on class with JFrame inheritance (extends)

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Warning on class with JFrame inheritance (extends)

    I'll start off by showing my full code:

    Main class
    import javax.swing.JFrame;
     
    public class groupingTest {
    	public static void main (String[] args) {
    		groupWindow test = new groupWindow();
     
    		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		test.setBounds(400, 400, 500, 100);
    		test.setVisible(true);
    	}
    }

    Window class
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.ButtonGroup;
    import javax.swing.JCheckBox;
    import java.awt.Font;
    import java.awt.event.ItemListener;
    import java.awt.event.ItemEvent;
    import javax.swing.JLabel;
     
    public class groupWindow extends JFrame {
     
    	private JLabel testText = new JLabel ("Some writing for test");
     
    	private JCheckBox plain;
    	private JCheckBox bold;
    	private JCheckBox italic;
    	private JCheckBox bolditalic;
     
    	private Font myFont;
     
    	public groupWindow() {
    		super("GUI Grouping Test");
    		setLayout(new FlowLayout());
     
    		// set our default font to plain
    		testText.setFont(new Font("Serin", Font.PLAIN, 15));
     
    		// make our check boxes
    		plain = new JCheckBox("plain", true);
    		bold = new JCheckBox("bold", false);
    		italic = new JCheckBox("italic", false);
    		bolditalic = new JCheckBox("bolditalic", false);
     
    		// add the check boxes to the main window
    		add(testText);
    		add(plain);
    		add(bold);
    		add(italic);
    		add(bolditalic);
     
    		// add our check boxes to a group so only one can be selected
    		ButtonGroup groupFontAttrib = new ButtonGroup();
    		groupFontAttrib.add(plain);
    		groupFontAttrib.add(bold);
    		groupFontAttrib.add(italic);
    		groupFontAttrib.add(bolditalic);
     
    		// add a listener to our check boxes
    		handler listener = new handler();
    		plain.addItemListener(listener);
    		bold.addItemListener(listener);
    		italic.addItemListener(listener);
    		bolditalic.addItemListener(listener);
    	}
     
    	// create our listener class
    	public class handler implements ItemListener {
    		public void itemStateChanged(ItemEvent e) {
    			// check what box is selected
    			if (bolditalic.isSelected())
    				myFont = new Font("Serin", Font.BOLD + Font.ITALIC, 15);
    			else if (bold.isSelected())
    				myFont = new Font("Serin", Font.BOLD, 15);
    			else if (italic.isSelected())
    				myFont = new Font("Serin", Font.ITALIC, 15);
    			else
    				myFont = new Font("Serin", Font.PLAIN, 15);
     
    			// change our label font now
    			testText.setFont(myFont);
    		}
    	}
    }

    At the start of the groupWindow it turns yellow and it says "The serializable class groupWindow does not declare a static final serialVersionUID field of type long".

    I've been following a tutorial and he hasn't had this issue (it does look like I can suppress this warning but it could be useful to learn).

    Thank you in advance,

    - Nicky

    EDIT:

    I'm using Eclipse IDE.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: Warning on class with JFrame inheritance (extends)

    does not declare a static final serialVersionUID field of type long
    Try defining the variable that is mentioned in the message.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Warning on class with JFrame inheritance (extends)

    Quote Originally Posted by Norm View Post
    Try defining the variable that is mentioned in the message.
    I have now and it has gotten rid of the error message...But why, what's the point of that being there? If you're going to say do my own research fair enough, I will eventually learn why

    - Nicky

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Warning on class with JFrame inheritance (extends)

    JFrame implements the interface Serializable. All classes that implement this interface need such a variable. Since your class extends JFrame your class does also implement this interface. As such, it needs to implement this variable.
    This is not forced upon you, it is not an error if you dont declare this variable, its just a warning.

Similar Threads

  1. Class Extends JFrame and implements Runnable - Where to put the code
    By mds1256 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 12th, 2013, 08:51 AM
  2. [SOLVED] how to send variable to different class by using extends
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 2nd, 2012, 05:05 PM
  3. is it possible to extends java class with another class from different package?
    By fredsilvester93 in forum Java Theory & Questions
    Replies: 6
    Last Post: July 20th, 2012, 03:51 PM
  4. Help removing JFrame inheritance
    By SendBorg in forum AWT / Java Swing
    Replies: 3
    Last Post: January 28th, 2012, 07:10 PM
  5. Teach me about inheritance and extends?
    By tripline in forum Java Theory & Questions
    Replies: 7
    Last Post: November 26th, 2011, 03:24 PM