home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap33 / ArcApplet.java < prev    next >
Encoding:
Java Source  |  1996-03-22  |  1.7 KB  |  69 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. /**
  5.  * ArcApplet demonstrates drawing arcs by enabling the user
  6.  * to input the arc's parameters.
  7.  *
  8.  * @version 1.0, 1/15/96
  9.  * @author Clayton Walnum
  10.  */
  11. public class ArcApplet extends Applet
  12. {
  13.     TextField textField1, textField2;
  14.  
  15.     /**
  16.      * Creates the applet's textfield controls and adds
  17.      * the controls to the applet's display.
  18.      *
  19.      * @return None
  20.      */
  21.     public void init()
  22.     {
  23.         textField1 = new TextField(10);
  24.         textField2 = new TextField(10);
  25.  
  26.         add(textField1);
  27.         add(textField2);
  28.  
  29.         textField1.setText("0");
  30.         textField2.setText("360");
  31.     }
  32.  
  33.     /**
  34.      * Retrieves the user-defined parameters from the text
  35.      * boxes, converts them to integers, and uses them
  36.      * to display an arc.
  37.      *
  38.      * @return None
  39.      * @param g The applet's Graphics object
  40.      * @see #action
  41.      */
  42.     public void paint(Graphics g)
  43.     {
  44.         String s = textField1.getText();
  45.         int start = Integer.parseInt(s);
  46.  
  47.         s = textField2.getText();
  48.         int sweep = Integer.parseInt(s);
  49.  
  50.         g.drawArc(35, 50, 125, 180, start, sweep);
  51.     }
  52.  
  53.     /**
  54.      * Responds when the user presses Enter from one of the
  55.      * applet's text boxes. Calls repaint() to force the applet
  56.      * to redraw its display with the new parameters.
  57.      *
  58.      * @return A boolean value indicating whether the
  59.      *         event was handled.
  60.      * @param event The action's event object
  61.      * @param arg Event-dependent information
  62.      */
  63.     public boolean action(Event event, Object arg)
  64.     {
  65.         repaint();
  66.         return true;
  67.     }
  68. }
  69.