Basic JApplet Starting Button - top of Musings page

By: Nicholas Duchon


// File: PCEditor.java
// Date: Mar 28, 2012
// Author: Nicholas Duchon
// Purpose: pseudo-code editor and simulator

import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PCEditor extends JApplet {
  final static String copyrightNotice = "Program Copyright 2012 by Nicholas Duchon";
  int curx = 160, cury = 160, delta = 30;
 
  public static void main (String args []) {
    PCEditor pce = new PCEditor ();
    pce.init();
    pce.start();
    JFrame jf = new JFrame ("Standalone PCEditor");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.add(pce);
    jf.setSize(250, 60);
    jf.setVisible(true);
    jf.setLocation(100, 100);
  } // end main
 
  public void init () {
    JOptionPane.showMessageDialog (null, copyrightNotice);
   
    JButton jbN = new JButton ("New PseudoCode Editor");
    add (jbN);
   
    jbN.addActionListener (new ActionListener () {
      public void actionPerformed (ActionEvent e) {
        new PCEditorFrame (curx, cury);
        curx += delta; cury += delta;
      }
    }); // end actionListener on JButton

   
  } // end JApplet method init

} // end class PCEditor

class PCEditorFrame extends JFrame implements ActionListener {
  static final long serialVersionUID = 1655789275237718736L;
  //  Container cp;
 
  public PCEditorFrame () {
    makeFrame ();
    setLocationRelativeTo (null);
  } // end constructor
 
  public PCEditorFrame (int locationx, int locationy) {
    makeFrame ();
    setLocation(locationx, locationy);
  } // end constructor
 
  void makeFrame () {
    add (new JButton ("one"), BorderLayout.PAGE_START);
    add (new JButton ("two"), BorderLayout.LINE_START);
    add (new JButton ("three"), BorderLayout.CENTER);
    add (new JButton ("four"), BorderLayout.LINE_END);
    add (new JButton ("five"), BorderLayout.PAGE_END);
    setTitle("PseudoCode Editor");
    setSize(250, 200);
    validate ();
    setVisible(true);
  } // end method makeFrame
 
  public void actionPerformed (ActionEvent e) {
  } // end method actionListener
} // end class PCEditorFrame

ND.