The Eclipse Visual Editor for Java
by Michael Pilone

Listing One

import javax.swing.JFrame;
/**
 * A simple JFrame-based application to show the basics of using the Visual
 * Editor for Java Eclipse plugin. The frame contains a label and a button.
 */
public class MyFrame extends JFrame {

  /**
   * The counter field that tracks the number of times the button was clicked.
   */
  private int counter = 0;

  /**
   * The content pane of the JFrame. This was generated by the Visual Editor.
   */
  private javax.swing.JPanel jContentPane = null;

  /**
   * The label displayed in the frame. Generated by the Visual Editor.
   */
  private javax.swing.JLabel jLabel = null;

  /**
   * The button displayed in the frame. Generated by the Visual Editor.
   */
  private javax.swing.JButton jButton = null;

  /**
   * The main method. The stub was generated by the new class wizard, and
   * then implemented to simply display the frame.
   * @param args
   *          command line arguments, ignored
   */
  public static void main(String[] args) {
    MyFrame f = new MyFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.show();
  }
  /**
   * Constructs the frame by initializing the content.
   */
  public MyFrame() {
    super();
    initialize();
  }
  /**
   * Initializes the content of the frame and sets the title. The default
   * implementation was generated by the Visual Editor, although it was
   * customized to provide a title.
   */
  private void initialize() {
    this.setSize(300, 200);
    this.setContentPane(getJContentPane());
    this.setTitle("Click Counter");
  }
  /**
   * Returns the content pane for this frame. This code was generated by
   * the Visual Editor.
   * @return the content pane for this frame
   */
  private javax.swing.JPanel getJContentPane() {
    if (jContentPane == null) {
      jContentPane = new javax.swing.JPanel();
      jContentPane.setLayout(new java.awt.BorderLayout());
      jContentPane.add(getJLabel(), java.awt.BorderLayout.CENTER);
      jContentPane.add(getJButton(), java.awt.BorderLayout.SOUTH);
    }
    return jContentPane;
  }
  /**
   * Returns label for this frame. Code was generated by the Visual Editor.
   * @return the label for this frame
   */
  private javax.swing.JLabel getJLabel() {
    if (jLabel == null) {
      jLabel = new javax.swing.JLabel();
      jLabel.setText("Hello World. My First GUI Application!");
    }
    return jLabel;
  }
  /**
   * Returns the button for this frame. Generated by the Visual Editor.
   * @return the button for this frame
   */
  private javax.swing.JButton getJButton() {
    if (jButton == null) {
      jButton = new javax.swing.JButton();
      jButton.setText("Push Me");
      jButton.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent e) {
          ++counter;
          getJLabel().setText("The button was clicked "+ counter +" times.");
        }
      });
    }
    return jButton;
  }
}






5



