• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);

}

}
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic