ListEvent2.java

# ListEvents.java Uses the following classes:

    * CloseableFrame.java
    * SelectionReporter.java
    * ActionReporter.java
/././././././././././././
import java.awt.event.*;

/././././././

public class ListEvents2 extends ListEvents {
  public static void main(String[] args) {
    new ListEvents2();
  }

  /** Extends ListEvents with the twist that
   *  typing any of the letters of "JAVA" or "java"
   *  over the language list will result in "Java"
   *  being selected
   */

  public ListEvents2() {
    super();
    // Create a KeyAdapter and attach it to languageList.
    // Since this is an inner class, it has access
    // to nonpublic data (such as the ListEvent's
    // protected showJava method).
    KeyAdapter javaChooser = new KeyAdapter() {
      public void keyPressed(KeyEvent event) {
        int key = event.getKeyChar();
        if ("JAVAjava".indexOf(key) != -1) {
          showJava();
        }
      }
    };
    languageList.addKeyListener(javaChooser);
  }
}

***************************
import java.awt.*;
import java.awt.event.*;

/** A class to demonstrate list selection/deselection
 *  and action events.
 *
 /*******************/.>

public class ListEvents extends CloseableFrame {
  public static void main(String[] args) {
    new ListEvents();
  }

  protected List languageList;
  private TextField selectionField, actionField;
  private String selection = "[NONE]", action;

  /** Build a Frame with list of language choices
   *  and two textfields to show the last selected
   *  and last activated items from this list.
   */
  public ListEvents() {
    super("List Events");
    setFont(new Font("Serif", Font.BOLD, 16));
    add(makeLanguagePanel(), BorderLayout.WEST);
    add(makeReportPanel(), BorderLayout.CENTER);
    pack();
    setVisible(true);
  }

  // Create Panel containing List with language choices.
  // Constructor puts this at left side of Frame.
  
  private Panel makeLanguagePanel() {
    Panel languagePanel = new Panel();
    languagePanel.setLayout(new BorderLayout());
    languagePanel.add(new Label("Choose Language"), 
                      BorderLayout.NORTH);
    languageList = new List(3);
    String[] languages =
      { "Ada", "C", "C++", "Common Lisp", "Eiffel",
        "Forth", "Fortran", "Java", "Pascal",
        "Perl", "Scheme", "Smalltalk" };
    for(int i=0; i

Permanent link to this article: http://bangla.sitestree.com/listevent2-java/

Leave a Reply