// Java Rocket by Exner Enterprises C. 1999 import java.applet.*; import java.awt.*; import java.awt.event.*; import java.net.URL; import java.util.*; import java.applet.AudioClip; public class Bob extends Applet implements Runnable { Image offscreenImage; Graphics h; int appSizeX, appSizeY; Vector objVect; boolean threadRun=true; Thread runner; //AudioClip launch; public void init(){ appSizeX=this.size().width; // appSizeX = 300; appSizeY=this.size().height; //launch = getAudioClip(getCodeBase(),"launch.au"); offscreenImage = createImage(appSizeX, appSizeY); h = offscreenImage.getGraphics(); Back.loadImages(this); objVect = new Vector(); objVect.addElement(new Back()); objVect.addElement(new RocketControl(appSizeX,appSizeY,300)); repaint(); } public void paint(Graphics g) { Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.show(h); } g.drawImage(offscreenImage,0,0,this); } public boolean mouseDown(Event evt, int x, int y) { System.out.println("x: "+(x)+"y: "+(y)); // Debug position Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.setMousePoint(x,y); } repaint(); return true; } public boolean mouseUp(Event evt, int x, int y) { Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.unsetMousePoint(x,y); } repaint(); return true; } public boolean mouseDrag(Event evt, int x, int y) { Enumeration e = objVect.elements(); while(e.hasMoreElements()) { ShowableObject c = (ShowableObject)e.nextElement(); c.dragMousePoint(x,y); } repaint(); return true; } public void update(Graphics g) { paint(g); } /// Start Thread stuff public void start() { if (runner == null) { runner= new Thread(this); runner.start(); threadRun = true; } } public synchronized void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { while (true) { //execute try { Thread.sleep(50); repaint(); } catch (InterruptedException e) {} } // End While } // End Run } // End class Rocket /////////////////// ExnerSlideBar Class /////////////////////////////// class ExnerSlideBar extends ShowableObject { private int xPos=0,yPos=0,width=100,valuePos=0; private boolean selected=false; public ExnerSlideBar() { valuePos = width/2; } public ExnerSlideBar(int x, int y){ xPos=x; yPos=y; valuePos = width/2; } public void show(Graphics g){ g.setColor(Color.white); g.fillRect(xPos,yPos+1,width,2); // x line g.setColor(Color.black); g.drawRect(xPos,yPos+1,width,2); // x line g.setColor(Color.white); g.fill3DRect(xPos+valuePos,yPos-4,6,12,true); // value line } public int getValue() { return (valuePos); //System.out.println("ValuePos= "+valuePos+"."); } public boolean getSelected(){ return selected; } public void setMousePoint(int x, int y) { if (x>=(xPos+valuePos) && x <=(xPos+valuePos+6)) { if (y>=(yPos-4) && y<=(yPos+8)) { selected=true; } } return; } public void unsetMousePoint(int x, int y) { selected=false; } public void dragMousePoint(int x, int y) { if (selected) { if (y >= (yPos-5) && y <= (yPos+9)) { if (x >= (xPos+width)) valuePos=width; if (x <= xPos) valuePos= 0; if (x < (xPos+width) && x > xPos) valuePos=Math.abs(xPos-x); } } } } // End Class ExnerSlideBar /////////////////// ShowableObject Class //////////////////////////// class ShowableObject extends Applet { static boolean launch=false; public void show (Graphics g) { return; } public void keyPress(Event evt, int key) { return; } public void setMousePoint(int x ,int y) { return; } public void unsetMousePoint(int x, int y) { return; } public void dragMousePoint(int x, int y) { return; } } /////////////////// Back Class /////////////////////////////// class Back extends ShowableObject { static Image imageStrip; int rocketX=252, rocketY=139; int height=300, width=300; public Back() { //Constructor } public static void loadImages(Applet parent){ imageStrip = parent.getImage(parent.getCodeBase(),"data.gif"); } public void show(Graphics g) { // Draw Sky // drawStripImage(g, imageStrip,0, 0,10,height); for (int i=0; i -300) rocketY-=3; } public void drawStripImage(Graphics g, Image imagePtr, int drawX, int drawY,int imageWidth, int imageHeight,int newX, int newY) { Graphics subArea = g.create(newX, newY, imageWidth, imageHeight); subArea.drawImage(imagePtr,-drawX,-drawY, this); subArea.dispose(); } public void drawStripImage(Graphics g, Image imagePtr, int drawX, int drawY,int imageWidth, int imageHeight) { Graphics subArea = g.create(drawX, drawY, imageWidth, imageHeight); subArea.drawImage(imagePtr,-drawX,-drawY, this); subArea.dispose(); } } // End Class Back