Domanda

I am trying this code below but it is giving me warning message but when I execute it runs without error.

import javax.swing.JFrame;
class MyFrame extends JFrame {
    public  MyFrame() {
        setTitle("Besm Allah Ya Allah");
        setSize(300,300);
        setLocation(10,100);
    }
    public static void main(String[] args){
        JFrame f = new MyFrame();
        f.show();
    }
}

javac -Xlint MyFrame.java gives me:

MyFrame.java:13: warning: [deprecation] show() in Window has been deprecated
f.show();
 ^
MyFrame.java:3: warning: [serial] serializable class MyFrame has no definition of serialVersionUID
class MyFrame extends JFrame {
^
2 warnings

What is the problem? Why I'm getting warning messages?

È stato utile?

Soluzione

See Window#show:

enter image description here

You should use Window#setVisible(true).

For your second warning, see Serializable:

A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top