Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel(Container)addImpl(Component,Object,Int) line: not available

 
Tony Rosamilia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello im a new java programmer and i have a problem with my code.

The serializable class Javabt does not declare a static final serialVersionUID field of type long
this error alert pops up on my Javabt class below. PLEASE HELP im goin nuts...

the code


import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JFrame;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

ERROR The serializable class Javabt does not declare a static final serialVersionUID field of type long
public class Javabt extends JFrame { <<<<JPanel(Container)addImpl(Component,Object,Int) line: not available DEBUGERROR

private JTextField tf;
private Font pf;
private Font bf;
private Font itf;
private Font bif;

private JRadioButton pb;
private JRadioButton bb;
private JRadioButton ib;
private JRadioButton bib;

private ButtonGroup group;

public Javabt(){
super("The title");
setLayout(new FlowLayout());

tf = new JTextField("Tony and bunny forever", 25);
add(tf);

pb = new JRadioButton("plain", true);
pb = new JRadioButton("bold", false);
ib = new JRadioButton("italic", false);
bib = new JRadioButton("Bold and italic", false);
add(pb);
add(bb);
add(ib);
add(bib);

group = new ButtonGroup(); // buttons need to be grouped to know if another button in group is checked.
group.add(pb);
group.add(pb);
group.add(ib);
group.add(bib);

pf = new Font("Serif", Font.PLAIN, 14);
bf = new Font("Serif", Font.BOLD, 14);
itf = new Font("Serif", Font.ITALIC, 14);
bif = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
tf.setFont(pf);

pb.addItemListener(new HandlerClass(pf)); //listens for user command, pass in font object to constructor
bb.addItemListener(new HandlerClass(bf)); //takes HandlerClass object as its attributes.
ib.addItemListener(new HandlerClass(itf));
bib.addItemListener(new HandlerClass(bif));


}
private class HandlerClass implements ItemListener{
private Font font;
//the font object get variable font
public HandlerClass(Font f){
font = f;


}

public void itemStateChanged(ItemEvent event){
tf.setFont(font);
}
}

}




>>>>MAIN<<<<


import javax.swing.JFrame;
public class Mainpoop {


public static void main(String[] args) {
Javabt go = new Javabt();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300,200); //size of frame width, height in pixels
go.setVisible(true);

}

}
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it's an error and not merely a warning? Either way, the solution is easy: add the serialVersionUID field.
 
Tony Docherty
Bartender
Posts: 2942
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

This question isn't related to I/O and Streams so I've moved the thread to the Swing forum for you.
 
Campbell Ritchie
Sheriff
Posts: 48436
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Are you sure it's an error and not merely a warning? Either way, the solution is easy: add the serialVersionUID field.
It’s definitely not an error. I wrote about it this morning: here. It is worth reading the two links I quoted, too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic