// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class AppletSkeleton extends Applet implements ActionListener {
  private boolean isStandalone = false;
  //Declare GUI components
  JRadioButton jRadioButton1 = new JRadioButton();
  JRadioButton jRadioButton2 = new JRadioButton();
  JRadioButton jRadioButton3 = new JRadioButton();
  JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();
  JTextArea jTextArea1 = new JTextArea();
  JTextArea jTextArea2 = new JTextArea();
  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }
  //Construct the applet
  public AppletSkeleton() {
  }
  //Initialize the applet
  public void init() {
    try {
      jbInit();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception {
    //Configure GUI components
    jRadioButton1.setText("jRadioButton1");
    jRadioButton1.setBounds(new Rectangle(27, 5, 91, 23));
    jRadioButton1.addActionListener(this);
    jRadioButton2.setText("jRadioButton2");
    jRadioButton2.setBounds(new Rectangle(123, 5, 91, 23));
    jRadioButton2.addActionListener(this);
    jRadioButton3.setText("jRadioButton3");
    jRadioButton3.setBounds(new Rectangle(219, 5, 91, 23));
    jRadioButton3.addActionListener(this);
    jTextField1.setText("jTextField1");
    jTextField1.setBounds(new Rectangle(18, 60, 129, 21));
    jTextField2.setText("jTextField2");
    jTextField2.setBounds(new Rectangle(162, 60, 113, 21));
    jTextField3.setText("jTextField3");
    jTextField3.setBounds(new Rectangle(286, 61, 98, 21));
    jTextArea1.setText("jTextArea1");
    jTextArea1.setBounds(new Rectangle(18, 111, 170, 172));
    jTextArea2.setText("jTextArea2");
    jTextArea2.setBounds(new Rectangle(216, 112, 171, 175));
    //Add GUI components to applet
    this.setLayout(null);
    this.add(jRadioButton1, null);
    this.add(jRadioButton2, null);
    this.add(jRadioButton3, null);
    this.add(jTextArea1, null);
    this.add(jTextArea2, null);
    this.add(jTextField1, null);
    this.add(jTextField2, null);
    this.add(jTextField3, null);
  }
  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }
  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }
  //Process radio button events
  public void actionPerformed(ActionEvent ev) {
     int rb;
     if(ev.getSource() == jRadioButton1) {
       rb = 1;
     } else if(ev.getSource() == jRadioButton2) {
       rb = 2;
     } else if(ev.getSource() == jRadioButton3) {
       rb = 3;
     } else {
       rb = 0;
     }
     jTextArea1.setText(jTextArea1.getText() + "\n" + rb);
  }
}
