Hi,
I have a super class and an inherited class. What it is supposed to do is display random images in one applet. The images dont match the words and images dont match the wording. What am I doing wrong? Probably a few errors. Thanks.
Super Class:
import java.awt.Color;; public class Dukes { private Color noseColor = Color.red; // default Dukes have red noses private String action = "../../images/duke/dukeWave.gif"; //default Dukes are friendly private String whatDoing = "Give me something to do"; private String message= ""; public Dukes() { int rint = (int)(Math.random() * 3); // randomly generates a 0, 1, or 2 if (rint == 0) { noseColor = Color.blue; // more often red by default action = "../../images/duke/dukeWave2.gif"; message = "What's up with the blue nose!"; } } public String getAction() { return whatDoing; } public String getActionImage() { return action; } public Color getNoseColor() { return noseColor; } public String getMessage() { return message; } public String write() { whatDoing = "I am a writing Duke"; if (noseColor == Color.red) { action = "../../images/duke/penduke.gif"; message = ""; } else { action = "../../images/duke/writing.gif"; message = "My nose feels funny"; } return action; } public String think() { whatDoing = "I am a thinking Duke"; if (noseColor == Color.red) { action = "../../images/duke/thinking.gif"; message = ""; } else { action = "../../images/duke/thinking2.gif"; message = "My nose feels funny"; } return action; } public String wave() { whatDoing = "I am a waving Duke"; if (noseColor == Color.red) { action = "../../images/duke/dukeWave.gif"; message = ""; } else { action = "../../images/duke/dukeWave2.gif"; message = "My nose feels funny"; } return action; } }
Inherited class:
import java.applet.Applet; import java.awt.*; public class ThreeDukesApplet extends Applet { Dukes myDuke, yourDuke, theirDuke; String Action, yourAction, theirAction; public void init() { myDuke = new Dukes(); Action = myDuke.getActionImage(); yourDuke =new Dukes(); yourAction =yourDuke.write(); theirDuke =new Dukes(); theirAction =theirDuke.getActionImage(); resize(600,400); } public void paint(Graphics g) { switch ((int)(Math.random() * 3)) { case 0: Action= yourDuke.write(); break; case 1: Action= theirDuke.think(); break; case 2: Action= myDuke.wave(); break; } Image myChoice = getImage(getDocumentBase(), Action); g.drawString(myDuke.getAction(), 10,165); g.drawString(myDuke.getMessage(), 10,180); g.drawImage(myChoice, 20, 50, Color.white, this); g.drawString(yourDuke.getAction(), 200,165); g.drawString(yourDuke.getMessage(), 200,180); Image yourChoice = null; g.drawImage(yourChoice, 200, 50, Color.white, this); Image theirChoice = getImage(getDocumentBase(), theirAction); g.drawString(theirDuke.getAction(), 400, 165); g.drawString(theirDuke.getMessage(),400, 180); g.drawImage(theirChoice, 400, 50, Color.white, this); } }