Java Swing Layout Manager Event Handling Inner Classes Swing Applet Exceptions Threads Java I/O![]() Stream![]() Character Stream classes![]() Byte Stream classes![]() I/O Methods![]() Type of I/O![]() File Streams![]() Data Streams![]() Object Serialization![]() Writing and Read Object![]() Drawing Editor Revisit![]() Drawing Editor Revisit![]() The Draw Class![]() The Graphic Element Classes![]() The Element Implementation classes![]() Transient Fields Network Programming Resources | Transient FieldsSome objects may contain fields that you don't want to persist, for example a Thread and OutputStream and its subclasses. For these fields, you should mark it as transient: import java.io.Serializable;
public class PersistentAnimation implements Serializable, Runnable {
transient private Thread animator;
private int animationSpeed;
public PersistentAnimation(int animationSpeed) {
this.animationSpeed = animationSpeed;
animator = new Thread(this);
animator.start();
}
public void run() {
while(true) {
// do animation here
}
}
} |