[2358] in java-interest

home help back first fref pref prev next nref lref last post

When does a graphics class get added to?

daemon@ATHENA.MIT.EDU (Elliotte Rusty Harold)
Fri Sep 29 18:42:51 1995

From: "Elliotte Rusty Harold" <Elliotte@blackstar.com>
To: java-interest@java.sun.com
Date:          Fri, 29 Sep 1995 16:18:07 EST
Reply-To: Elliotte@blackstar.com
Cc: elharo@inch.com


I think the follwoing code demonstrates a fundamental 
misunderstanding I have about applets. I'd appreciate it if someone 
would explain to me what I'm doing wrong.  

The goal is to be able to print a string into the applet window with 
the name of the event whenever the applet receives an event (like 
mouse moved).  However it seems the only event I ever get is a paint 
event.  Furthermore if I obscure a window and then unobscure it, I 
only get that paint event and any previous graphics that weren't 
obscured.  

Does the Graphics context of an applet not store what has 
gone before?  i.e. do I need to keep the contents of a Graphics pane
in a separate data structure and then redraw the entire data 
structure any time I get a paint event?

If that's the case is there any clipping done so I only redraw those 
parts of an applet that were obscured?


--Code follows

import browser.Applet;    
import awt.Graphics; 
              
class EventTutor extends Applet {

  int line = 1;

  public void init() {
    g.drawString("init event", 50, 25 * line++);
    resize(150, 2500);
    repaint();
  }
  
  public void paint(Graphics g) {
    g.drawString("paint event.", 50, 25 * line++);
  }
    
  public void stop(Graphics g) {
    g.drawString("stop event", 50, 25 * line++);
    repaint();
  }

  public void destroy(Graphics g) {
    g.drawString("destroy event", 50, 25 * line++);
    repaint();
  }
 
  public void update(Graphics g) {
    g.drawString("update event", 50, 25 * line++);
    repaint();
  }
  
  public void mouseUp(Graphics g) {
    g.drawString("mouseUp event", 50, 25 * line++);
    repaint();
  }
  
  public void mouseDown(Graphics g) {
   g.drawString("mouseDown", 50, 25 * line++);
   repaint();
  }
  
  public void mouseDrag(Graphics g) {
    g.drawString("mouseDrag event", 50, 25 * line++);
    repaint();
  }
  
  public void mouseEnter(Graphics g) {
    g.drawString("mouseEnter event", 50, 25 * line++);
    repaint();
  }
  
  public void getFocus(Graphics g) {
    g.drawString("getFocus event", 50, 25 * line++);
    repaint();
  }
  
  public void gotFocus(Graphics g) {
    g.drawString("gotFocus event", 50, 25 * line++);
    repaint();
  }
  
  public void lostFocus(Graphics g) {
    g.drawString("lostFocus event", 50, 25 * line++);
    repaint();
  }
  
  public void keyDown(Graphics g) {
    g.drawString("keyDown event", 50, 25 * line++);
    repaint();
  }
  
}

--
Elliotte Rusty Harold    Black Star Publishing Co., Inc.
elliotte@blackstar.com   116 East 27th Street
elharo@escape.com        NY NY 10016
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post