-
Notifications
You must be signed in to change notification settings - Fork 0
/
Desktop.java
121 lines (99 loc) · 3.14 KB
/
Desktop.java
1
import java.awt.*;import java.applet.*;import java.awt.image.*;import java.awt.graphics.*;import java.util.*;public class Desktop extends Canvas{ MAE theApplet; Image offScreenImage,theDesktop; Graphics offScreenImageGC,g; int DesktopWidth,DesktopHeight; NewMenuBar MenuBar; static final byte pattern[] = {(byte)0x00,(byte)0xFF,(byte)0x00,(byte)0xFF,(byte)0x00,(byte)0xFF,(byte)0x00,(byte)0xFF}; private static final byte bmap[] = {(byte)000,(byte)255}; public Desktop(MAE app) { byte[] pixels = new byte [40*40]; theApplet = app; DesktopWidth = theApplet.size().width; DesktopHeight = theApplet.size().height; MenuBar = null; IndexColorModel model; offScreenImage = theApplet.createImage(DesktopWidth,DesktopHeight); offScreenImageGC = offScreenImage.getGraphics(); model = new IndexColorModel(1,2,bmap,bmap,bmap,3); for (int index=0,y=0;y<40;y++) { for (int x=0;x<40;x=x+2) { if (y%2==0) { pixels[index++] = (byte)0; pixels[index++] = (byte)1; } else { pixels[index++] = (byte)1; pixels[index++] = (byte)0; } } } theDesktop = createImage (new MemoryImageSource (40,40,model,pixels,0,40)); DrawDesktop(); } public boolean mouseDown(Event e, int x, int y) { theApplet.ApplicationThread.AFC.xMousePos = (short)x; theApplet.ApplicationThread.AFC.yMousePos = (short)y; theApplet.ApplicationThread.AFC.PostNewEvent((short)1); theApplet.ApplicationThread.AFC.mouseDown = true; return true; } public boolean mouseUp(Event e, int x, int y) { theApplet.ApplicationThread.AFC.xMousePos = (short)x; theApplet.ApplicationThread.AFC.yMousePos = (short)y; theApplet.ApplicationThread.AFC.PostNewEvent((short)2); theApplet.ApplicationThread.AFC.mouseDown = false; return true; } public boolean mouseMove(Event e, int x, int y) { theApplet.ApplicationThread.AFC.xMousePos = (short)x; theApplet.ApplicationThread.AFC.yMousePos = (short)y; return true; } public boolean mouseDrag(Event e, int x, int y) { theApplet.ApplicationThread.AFC.xMousePos = (short)x; theApplet.ApplicationThread.AFC.yMousePos = (short)y; return true; } public boolean keyDown(Event e, int key) { if (theApplet.ApplicationThread.AFC.keydown) theApplet.ApplicationThread.AFC.PostNewEvent((short)5,key); // (autokey event) else theApplet.ApplicationThread.AFC.PostNewEvent((short)3,key); // (key down event) theApplet.ApplicationThread.AFC.keydown = true; return true; } public boolean keyUp(Event e, int key) { theApplet.ApplicationThread.AFC.PostNewEvent((short)4,key); theApplet.ApplicationThread.AFC.keydown = false; return true; } public void paint(Graphics graph) { graph.drawImage(offScreenImage,0,0,null); } public void DrawDesktop() { for (int i=21;i<DesktopHeight;i=i+40) for (int j=0;j<DesktopWidth;j=j+40) offScreenImageGC.drawImage(theDesktop,j,i,null); } public void Redraw() { g = getGraphics(); g.drawImage(offScreenImage,0,0,null); }}