//Kite1.java //First try at Kite //Load up images import java.awt.*; import java.applet.*; import java.awt.event.*; public class Kite1 extends Applet { public static final int NORTH = 0; public static final int NORTHEAST = 1; public static final int EAST = 2; public static final int SOUTHEAST = 3; public static final int SOUTH = 4; public static final int SOUTHWEST = 5; public static final int WEST = 6; public static final int NORTHWEST = 7; Image kite[] = new Image[8]; int direction = NORTH; EventHandler evt = new EventHandler(); public void init(){ //get the kite images kite[NORTH] = getImage (getDocumentBase(), "kiteN.gif"); kite[NORTHEAST] = getImage (getDocumentBase(), "kiteNE.gif"); kite[EAST] = getImage (getDocumentBase(), "kiteE.gif"); kite[SOUTHEAST] = getImage (getDocumentBase(), "kiteSE.gif"); kite[SOUTH] = getImage (getDocumentBase(), "kiteS.gif"); kite[SOUTHWEST] = getImage (getDocumentBase(), "kiteSW.gif"); kite[WEST] = getImage (getDocumentBase(), "kiteW.gif"); kite[NORTHWEST] = getImage (getDocumentBase(), "kiteNW.gif"); this.addKeyListener(evt); this.requestFocus(); } // end init public void paint(Graphics g){ g.drawImage(kite[direction], 50, 50, this); } // end paint private class EventHandler extends KeyAdapter { public void keyPressed(KeyEvent e){ if (e.getKeyCode() == KeyEvent.VK_LEFT){ direction--; if (direction < NORTH) { direction = NORTHWEST; } // end if } else if (e.getKeyCode() == KeyEvent.VK_RIGHT){ direction++; if (direction > NORTHWEST){ direction = NORTH; } // end if } // end key checking if repaint(); } // end key press event } // end eventHandler class def } // end kite class def