| Оглавление | Назад // ==========================================
// PutDisk.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web:    http://www.glasnet.ru/~frolov 
// ========================================== import java.applet.Applet;
import java.awt.*;
public class PutDisk extends Applet
{
  Image imFloppy;
  int imHeight;
  int imWidth;
  Dimension dm;
  
  // ============================================
  // init
  // ============================================
  public void init()
  {
    MediaTracker tr = new MediaTracker(this);
    
    imFloppy = getImage(getCodeBase(),
      "disk.gif");
    tr.addImage(imFloppy, 0);
    try
    {
      tr.waitForAll();
    }
    catch (InterruptedException e) {}
    
    imHeight = imFloppy.getHeight(this);
    imWidth = imFloppy.getWidth(this);
    
    dm = size();
    
    setBackground(Color.white);
    setForeground(Color.black);
  }
  
  // ============================================
  // getAppletInfo
  // ============================================
  public String getAppletInfo()
  {
    return "Name: PutDisk";
  }
  
  // ============================================
  // paint
  // ============================================
  public void paint(Graphics g)
  {
    g.drawRect(0, 0, 
      dm.width - 1, dm.height - 1);
  }
  
  // ============================================
  // mouseEnter
  // ============================================
  public boolean mouseEnter(Event e, 
    int x, int y)
  {
    return true;
  }
  
  // ============================================
  // mouseExit
  // ============================================
  public boolean mouseExit(Event e, 
    int x, int y)
  {
    return true;
  }
  
  // ============================================
  // mouseDown
  // ============================================
  public boolean mouseDown(Event e, 
    int x, int y)
  {
    Graphics g = getGraphics();
    
    if(e.clickCount > 1)
    {
      g.drawImage(imFloppy, x, y, 
	imWidth * 2, imHeight * 2, this);
    }
    
    else if(e.modifiers == Event.META_MASK)
    {
      repaint();
    }
    else
      g.drawImage(imFloppy, x, y, this);
      
    return true;
  }
}
 |