import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;

import javax.swing.*;

public class PropertiesApplet extends JApplet {
	private FormPanel form;

    public void init() {
	    form = new FormPanel();
	    
	    addProperty("java.version");
	    addProperty("java.class.version");
	    addProperty("java.vendor");
	    addProperty("java.vendor.url");
	    addProperty("java.home");
	    addProperty("os.name");
	    addProperty("os.arch");
	    addProperty("os.version");
	    addProperty("java.specification.version");
	    addProperty("java.specification.vendor");
	    addProperty("java.specification.name");
	    addProperty("java.vm.specification.version");
	    addProperty("java.vm.specification.vendor");
	    addProperty("java.vm.specification.name");
	    addProperty("java.vm.version");
	    addProperty("java.vm.vendor");
	    addProperty("java.vm.name");

	    /*
		// check for classes expected to be in JDK 1.1.x
		Label classL = new Label(
			"Classes expected to be present in a JDK 1.1.x release");
		gbl.setConstraints(classL, titleGBC);
		classL.setFont(titleF);
		add(classL);

		checkClass("java.awt.AWTEvent");
		checkClass("java.awt.Cursor");
		checkClass("java.awt.EventQueue");
		checkClass("java.awt.PrintJob");
		checkClass("java.awt.ScrollPane");
		checkClass("java.beans.Beans");
		checkClass("java.io.CharArrayReader");
		checkClass("java.lang.Byte");
		checkClass("java.lang.reflect.Constructor");
		checkClass("java.math.BigDecimal");
		checkClass("java.net.HttpURLConnection");
		checkClass("java.rmi.server.RemoteObject");
		checkClass("java.security.Identity");
		checkClass("java.sql.Types");
		checkClass("java.text.DateFormat");
		checkClass("java.util.Calendar");
		checkClass("java.util.zip.ZipFile");
	     */
	    
	    addTimeZoneStuff();
	    
	    JPanel formWrapper = new JPanel(new BorderLayout());
	    formWrapper.add(form, BorderLayout.NORTH);
	    
	    JPanel mainP = new JPanel(new BorderLayout());
	    mainP.add(new JLabel("Java Runtime Environment", JLabel.CENTER), 
	        BorderLayout.NORTH);
	    mainP.add(new JScrollPane(formWrapper), BorderLayout.CENTER);
	    setContentPane(mainP);
	}

    private void addProperty(String key) {
        String value = "unavailable";
        try {
            value = System.getProperty(key);
            value = (value == null) ? "null" : value;
        } catch ( Exception x ) {
            System.err.println(x);
        }
        
        form.add(new JLabel(key + ": "));
        form.add(new JLabel(value));
    }
	
    private void addTimeZoneStuff() {
        Date now = new Date(System.currentTimeMillis());

        DateFormat df = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss.SSS zzz", Locale.US);

        TimeZone localTz = TimeZone.getDefault();
        df.setTimeZone(localTz);

        form.add(new JLabel("Local TimeZone: "));
        form.add(new JLabel(localTz.getID()));
        form.add(new JLabel("Local Time: "));
        form.add(new JLabel(df.format(now)));
    }
    

    /*
	private void checkClass(String fullClassName) {
		String result;

		try {
			// Try to load specified class into runtime
			// if it is missing, an exception will be thrown
			Class c = Class.forName(fullClassName);
			result = "class present";
		}
		catch (Throwable e) {
			result = "class not found";
		}

		addPair(fullClassName + ":", result, 20);
	}
     */
    
    public static void main(String[] args) {
        PropertiesApplet applet = new PropertiesApplet();
        applet.init();
        applet.start();
        
        JPanel contentPane = new JPanel(new GridLayout());
        contentPane.add(applet);

        JFrame f = new JFrame("PropertiesApplet");
        f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        f.setContentPane(contentPane);

        f.setSize(600, 450);
        //GuiTools.packAndCenterOnScreen(f);
        //GuiTools.setSizeAndCenterOnScreen(f, 600, 450);
        //GuiTools.setSizeToMax(f);
        f.setVisible(true);

        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}
