You can read all over the web that AWT is old and deprecated and Swing is old but newer than AWT and should be preferred over AWT whenever possible. But how can I identify when it is possible to replace AWT components with its Swing pendants? Several examples in the web use still AWT components where Swing could be used instead. So is there a clear advice what to use from AWT and what not? I know that the java compiler will give a short note when I use officially deprecated components, e.g.:
import java.awt.*;
public class Hello {
public static void main( String[] args ) {
Frame f = new Frame( "Hello" );
f.setSize( 300, 300 );
f.show();
}
}
will produce an warning like this:
Note: Hello.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
and with -Xlint
:
Hello.java:9: warning: [deprecation] show() in Window has been deprecated
f.show();
^
1 warning
But as far as I understood the web and oracle, I prefer to use JComponents over AWT components. But the following code will not notice me to use JFrame instead of Frame:
import java.awt.*;
public class Hello {
public static void main( String[] args ) {
Frame f = new Frame( "Hello" );
f.setSize( 300, 300 );
f.setVisible( true );
}
}
All in all I am curious when I read code in the web, if it is up to date and follows the principle to use Swing where ever possible, or if I need to improve.
In other words: What are the safe parts of java.awt.*
and its subpackages?
Thanks for your thoughts and advisory.