/* draw11: ability to create image items */ import java.net.*; import java.awt.*; import java.util.*; public class Draw11 extends Draw10 { // AN IMAGE ITEM NEEDS TO KNOW ABOUT THE APPLET IN ORDER TO DRAW ITSELF. Item newItem() { Item11 it = new Item11(); it.parent = this; return (Item)it; } Item11 item11(int i) { return (Item11)item[i]; } // KEEP TRACK OF WHETHER APP. IS IN "DRAGGING A NEW IMAGE FROM THE PALETTE" MODE. boolean isCreatingImage = false; // MOUSE DOWN TO BEGIN DRAGGING A NEW IMAGE OFF THE IMAGE PALETTE public boolean mouseDown(Event e, int x, int y) { if (imageAt(x, y) >= 0) { isCreatingImage = true; iSelected = nItems; item[nItems++] = (Item)newItem(); Item11 it = item11(nItems-1); it.image = img[imageAt(x, y)]; it.imageName = imgName[imageAt(x, y)]; it.ix = x; it.iy = y; mx = x; my = y; damage = true; return true; } return super.mouseDown(e, x, y); } // MOUSE UP TO DEPOSIT THE NEW IMAGE ITEM AT ITS DEFAULT POSITION public boolean mouseUp(Event e, int x, int y) { if (isCreatingImage) { isCreatingImage = false; Item11 it = item11(nItems-1); it.ix += it.x0; it.iy += it.y0; it.x0 = 0; it.y0 = 0; } return super.mouseUp(e, x, y); } }