// //Brian Jahns //Java 290 //Cat applet // import java.applet.*; import java.awt.*; public class Cat extends Applet implements Runnable { private Thread m_Cat = null; Image catpics[]=new Image[9]; String catsrc[]={"right1.gif","right2.gif","stop.gif","yawn.gif", "scratch1.gif","scratch2.gif","sleep1.gif","sleep2.gif","awake.gif"}; Image currentimg; int xpos; int ypos=50; public Cat() { } public String getAppletInfo() { return "Name: Cat\r\n" + "Author: Brian Jahns\r\n" + "Created with Microsoft Visual J++ Version 1.1"; } public void init() { resize(320, 120); } public void destroy() { } public void paint(Graphics g) { g.drawImage(currentimg, xpos, ypos,this); } public void start() { if (m_Cat == null) { m_Cat = new Thread(this); m_Cat.start(); } } public void stop() { if (m_Cat != null) { m_Cat.stop(); m_Cat = null; } } public void run() { for(int i=0;i0;i--) { currentimg=catpics[4]; repaint(); pause(150); currentimg=catpics[5]; repaint(); pause(150); } } void catsleep(int numtimes) { for (int i=numtimes; i>0;i--) { currentimg=catpics[6]; repaint(); pause(250); currentimg=catpics[7]; repaint(); pause(250); } } void pause(int time) { try{Thread.sleep(time);} catch(InterruptedException e){} } }