import java.awt.*;
import java.awt.event.*;
public class TankWar {
public static void main(String[] args) {
new MyFrame ("TankWar");
}
}class MyFrame extends Frame {
MyFrame (String s) {
super (s);
setLayout (null);
setBounds (300,300,800,600);
setBackground (Color.white);
addWindowListener (new MyWindowListener());
setVisible (true);
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit (0);
}
}
}
为什么在类MyFrame的左边会显示一个小感叹号啊?是有问题吗?
import java.awt.event.*;
public class TankWar {
public static void main(String[] args) {
new MyFrame ("TankWar");
}
}class MyFrame extends Frame {
MyFrame (String s) {
super (s);
setLayout (null);
setBounds (300,300,800,600);
setBackground (Color.white);
addWindowListener (new MyWindowListener());
setVisible (true);
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit (0);
}
}
}
为什么在类MyFrame的左边会显示一个小感叹号啊?是有问题吗?
加一行版本号的声明就行了
import java.awt.*;
import java.awt.event.*;
public class TankWar {
public static void main(String[] args) {
new MyFrame ("TankWar");
}
}class MyFrame extends Frame {
/**
*
*/
private static final long serialVersionUID = 1L;
MyFrame (String s) {
super (s);
setLayout (null);
setBounds (300,300,800,600);
setBackground (Color.white);
addWindowListener (new MyWindowListener());
setVisible (true);
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit (0);
}
}
}
public abstract class Component implements ImageObserver, MenuContainer,Serializable{}所以MyFrame 是序列化的类。Java的序列化机制是通过在运行时判断类的serialVersionUID来验证版本一致性的。在进行反序列化时,JVM会把传来的字节流中的serialVersionUID与本地相应实体(类)的serialVersionUID进行比较,如果相同就认为是一致的,可以进行反序列化,否则就会出现序列化版本不一致的异常。 因为有些对象是即时序列化了也不需要进行流操作,所以说他报的是警告。你加个:
private static final long serialVersionUID = 1L;警告就会消失。