home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 1.7 KB | 87 lines |
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- import javax.swing.*;
- import javax.swing.text.*;
-
- /*
- * the applet class
- */
- public class SpreadSheet extends Applet implements KeyListener{
-
- /*
- * the text entry field
- */
- TextField textField;
-
- /*
- * instance of the sheet panel
- */
- Sheet sheet;
-
- /*
- * initialize the applet
- */
- public void init () {
-
- setBackground(Color.lightGray);
- setLayout(new BorderLayout());
-
- textField = new TextField ("", 80);
- sheet = new Sheet (10, 5, 400, 200, textField);
- add ("North", textField);
- add ("Center", sheet);
- textField.addKeyListener(this);
- }
-
- /*
- * check for return keypresses
- */
- public void keyTyped(KeyEvent e){}
- public void keyReleased(KeyEvent e){}
- public void keyPressed(KeyEvent e)
- {
- char character;
- int x;
-
-
- character = e.getKeyChar();
- x=e.getKeyCode();
-
- //Check whether the user pressed Return
- if (x == 10)
- {
- sheet.enter (textField.getText ());
- }
- }
- /*
- * application entry point
- * not used when run as an applet
- * @param args - command-line arguments
- */
- public static void main (String args[]) {
-
- Frame f = new Frame ("SpreadSheet");
- SpreadSheet spreadSheet = new SpreadSheet ();
-
- spreadSheet.init ();
-
- f.addWindowListener(new WindowCloser());
- f.setSize (440, 330);
- f.add ("Center", spreadSheet);
- f.show ();
- }
- }
-
- class WindowCloser extends WindowAdapter
- {
- public void windowClosing(WindowEvent e)
- {
- Window win = e.getWindow();
- win.setVisible(false);
- win.dispose();
- System.exit(0);
- }
- }
-