/* 3magic Coffee Table Tutorial 9 Tutorial9.java - Event Handling with GridEvent. © 1997-1999 3magic. All rights reserved worldwide. */ import java.awt.*; import java.applet.*; import java.util.*; import CoffeeTable.Grid.*; public class Tutorial9 extends Applet { // Our grid. GridPanel fGrid; // Rows and Columns; int fNumCols = 50; int fNumRows = 50; // Message area. TextArea fMsg = new TextArea("Manipulate the grid with the mouse.\n", 10, 1); /** * Initialize. */ public void init() { // Let's use a BorderLayout to help us with the user input areas. setLayout(new BorderLayout()); // Instantiate a new Grid Panel with the specified rows and columns // and other defaults like cell selection, row and column headers, // row and column lines enabled and with scrollbars. fGrid = new GridPanel(fNumRows, fNumCols); // Add in the DEMO_TEXT mode. fGrid.setFlags(fGrid.getFlags() | GridPanel.DEMO_TEXT); // Enable editing. fGrid.setGridAttributes(new GridAttributes(fGrid, new Font("Courier", Font.PLAIN, 12), null, null, 0, GridPanel.EDIT_TEXT), true); // Enable sorting for all columns fGrid.setSortEnable(true); // Set sort column color to a very light gray. fGrid.setSortColumnColor(new Color(0xEFEFEF)); // Show the row headers. fGrid.setRowHeaderWidth(40); fGrid.setRowNumbers(true); // Let's use Times, plain, 9-point. fGrid.setGridFont(new Font("TimesRoman", Font.PLAIN, 9)); // Add the grid into the applet panel add("Center", fGrid); // Add the message area. add("South", fMsg); } /** * handleEvent. */ public boolean handleEvent(Event event) { // Look for grid action events. if (event.target == fGrid && event.id == Event.ACTION_EVENT) { // Show the event info in the message area. if (event instanceof GridEvent) { fMsg.appendText(event.toString() + "\n"); } } // Be sure to call super to get the default grid behaviors! return super.handleEvent(event); } }