/* ** Released into the public domain. ** PROVIDED AS-IS. NO WARRANTY. USE AT YOUR OWN RISK. */ import java.applet.*; import java.awt.*; /** ** Identify platform using system properties, displayed in Labels. */ public class SimpleID extends Applet { /** ** As an Applet, only do minimal amount in constructor, ** since no AppletStub assigned yet, hence no parameters are available. */ public SimpleID() { super(); } /** ** Applet life-cycle method. ** Builds its own content. */ public void init() { // Get identifiers for JVM and OS, with overrides given by applet's params. String jvm = getProp( "java.version", "?" ); jvm = getProp( "java.runtime.version", jvm ); String os = getProp( "os.name", "OS" ); String osv = getProp( "os.version", "?" ); String arch = getProp( "os.arch", "?" ); // Arrange content within applet. setBackground( getColor( "bgcolor", 0xFFFFFF ) ); setLayout( new FlowLayout() ); // default is CENTER, 5x5 gaps add( platform( jvm, os, osv, arch ) ); // Minor voodoo mentioned in Sun's Applet Tutorial (plain-AWT, not Swing) this.validate(); } /** Returns a Component with platform-identifying info. */ protected Component platform( String jvm, String os, String osv, String arch ) { Panel holder = new Panel( new GridLayout( 0, 1, 0, 0 ) ); // rows, cols, hgap, vgap holder.add( new Label( "Java: " + jvm, Label.CENTER ) ); holder.add( new Label( os + ": " + osv + " " + arch, Label.CENTER ) ); return ( holder ); } /** Get a value from Applet param, or from System properties. */ public Color getColor( String propName, int fallbackRGB ) { return ( new Color( getInteger( propName, fallbackRGB ).intValue() ) ); } /** Get a value from Applet param, or from System properties. */ public Integer getInteger( String propName, int fallback ) { String value = getProp( propName ); if ( value != null ) { try { return Integer.decode( value.trim() ); } catch ( NumberFormatException fallsThru ) { ; } } return ( new Integer( fallback ) ); } /** Get a value, or use fallback. */ public String getProp( String propName, String fallback ) { String value = getProp( propName ); if ( value != null ) return ( value ); return ( fallback ); } /** ** Get a value from applet parameters, or from System properties, or null. ** Protected with try/catch, so a properties security-exception returns null. */ public String getProp( String propName ) { String value = getParameter( propName ); if ( value != null ) return ( value ); try { return ( System.getProperty( propName ) ); } catch ( SecurityException fallsThru ) { ; } return ( null ); } }