//  File:  Dual\Dual.java

//  Show how to run both as an applet and as an application

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Dual extends Applet {

    public void init() {
        setLayout(null);
        setBackground(Color.lightGray);
        setSize(SIZE_X, SIZE_Y);
    }

    // 'Clamp' the applet's minimum display area
    public void paint(Graphics g) {
        Dimension d = getSize();
        final int wMin = 300, hMin = 50;
        if ((d.width < wMin) || (d.height < hMin)) {
            if (d.width < wMin)
                d.width = wMin;
            if (d.height < hMin)
                d.height = hMin;
            setSize(d);
        }
        // Locate the text roughly in the center
        int x = (d.width - 80) / 2;
        int y = d.height / 2 - 5;
        g.drawString(s,  x, y);
        String sA = (bIsApplet) ? "Applet" : "Application";
        g.drawString(sA, x, y + 20);
    }

    // To close the application
    static class CloseListener extends WindowAdapter {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    }

    // A main() for the application
    public static void main(String[] args) {
        Applet applet = new Dual();
        Frame frame = new Frame("Dual");
        frame.addWindowListener(new CloseListener());
        frame.add(applet);
        frame.setSize(SIZE_X, SIZE_Y);
        bIsApplet = false;
        applet.init();
        applet.start();
        frame.setVisible(true);
    }

    private final static String s  = "Run either way";
    private static boolean bIsApplet = true;
    private static final int SIZE_X = 300;
    private static final int SIZE_Y = 100;
}
