Author: Davanum Srinivas
Author's WebSite: http://dims.someone.net/
This Code can be compiled with any version of Java. It checks which version of Swing is installed.
public class SwingSniffer extends java.applet.Applet
{
public void init() {
Class swingOldJButtonClass = null;
Class swingNewJButtonClass = null;
// Try to check for the Old Version of Swing
try {
swingOldJButtonClass = Class.forName("com.sun.java.swing.JButton");
if(swingOldJButtonClass != null)
System.out.println("Old Version of Swing is present");
}
catch(NoClassDefFoundError e) {
}
catch(ClassNotFoundException e) {
}
// Try to check for the New Version of Swing
try {
swingNewJButtonClass = Class.forName("javax.swing.JButton");
if(swingNewJButtonClass != null)
System.out.println("New Version of Swing is present");
}
catch(NoClassDefFoundError e) {
}
catch(ClassNotFoundException e) {
}
// Print Message if both are absent.
if(swingOldJButtonClass == null && swingNewJButtonClass == null)
System.out.println("Swing Absent");
}
}
HTML
<HTML><HEAD></HEAD><BODY>
<APPLET CODE="SwingSniffer.class"
HEIGHT=1 WIDTH=1>
<A HREF="/nojava.html">
Oups! You don't have JAVA enabled, click here.</A>
</APPLET>
</BODY></HTML>
Posted On: 8-Jul-1999