package awb; import java.awt.*; // Steve Ruby public class HangmanScreen extends Canvas { private int myPartNum; private int myWidth; private int myHeight; private char[] myWord; private boolean complete; private boolean doWord; public HangmanScreen() { myWidth = 300; myHeight = 300; myPartNum = 0; setBackground(Color.white); doWord = false; } public Dimension preferredSize() { return new Dimension(myWidth,myHeight); } public Dimension minimumSize() { return new Dimension(myWidth,myHeight); } public void setWord(char[] word) { myWord = word; doWord = true; repaint(); } private void drawGallows(Graphics g) { g.drawLine(myWidth/2+myWidth/6,myHeight/8,myWidth/2+myWidth/6,myHeight/2+myHeight/8); //main post g.drawLine(myWidth/2+myWidth/6,myHeight/8,myWidth/2,myHeight/8); // horizontal headpiece g.drawLine(myWidth/2,myHeight/8,myWidth/2,myHeight/8+myHeight/16); // vertical headpiece g.drawLine(myWidth/2,myHeight/2+myHeight/8,myWidth/2+myWidth/5,myHeight/2+myWidth/8); //base } private void drawHead(Graphics g) { g.drawOval(myWidth/2-myWidth/16,myHeight/8+myHeight/16,myWidth/8,myHeight/8); } private void drawBody(Graphics g) { g.drawLine(myWidth/2,myHeight/4+myHeight/16,myWidth/2,myHeight/2); } private void drawArm(Graphics g,String side) { if (side.equals("left")) { g.drawLine(myWidth/2,myHeight/4+myHeight/8,myWidth/2-myWidth/8,myHeight/4+myHeight/16); } else g.drawLine(myWidth/2,myHeight/4+myHeight/8,myWidth/2+myWidth/8,myHeight/4+myHeight/16); } private void drawLeg(Graphics g,String side) { if (side.equals("left")) { g.drawLine(myWidth/2,myHeight/2,myWidth/2-myWidth/8,myHeight/2+myHeight/16); } else g.drawLine(myWidth/2,myHeight/2,myWidth/2+myWidth/8,myHeight/2+myHeight/16); } private void drawWord(Graphics g) { String s = new String(""); int k=0; complete = true; while (k= 1) { drawHead(g); } if (myPartNum >= 2) { drawBody(g); } if (myPartNum >= 3) { drawArm(g,"left"); } if (myPartNum >= 4) { drawArm(g,"right"); } if (myPartNum >= 5) { drawLeg(g,"left"); } if (myPartNum >= 6) { drawLeg(g,"right"); doLoser(g); } } }