:?: :?: I dont understand what jbuilder is trying to tell me .. by all right my code seims fine I spent 4 days working it up (yes I am a beginer) I know there are most likly better ways to do what I am doing.
The point is compiled the code tells me that it cant find bootstrap loader and several others. This is the 5th program I have done on jbuilder (most extensive and I think I followed the information in book and Online correctly) I have gone over it twice. please any assistance would help me at this point.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class Hangman extends JFrame {
JLabel wordLabel;
JButton letterButtons[] = new JButton[26];
boolean guessed[] = new boolean[26];
GallowsPanel gallows;
JButton newGameButton;
JButton quitButton;
String theWord;
boolean won; // true if the user won
boolean lost; // true if the user lost
final static int BAD_GUESS_LIMIT = 7;
int badGuessCount;
Font largeFont = new Font("Monospaced", Font.BOLD, 30);
Font smallFont = new Font("Serif", Font.PLAIN, 18);
Color backColor = Color.lightGray;
Words dictionary;
Color plainColor = backColor;
Color correctColor = Color.green;
Color wrongColor = Color.red;
public Hangman() {
Container contents = getContentPane();
gallows = new GallowsPanel();
gallows.setBackground(backColor);
contents.add(gallows, BorderLayout.CENTER);
JPanel rightPanel = new JPanel(new BorderLayout());
wordLabel = new JLabel("", JLabel.CENTER);
wordLabel.setFont(largeFont);
wordLabel.setBackground(backColor);
wordLabel.setForeground(Color.black);
rightPanel.add(wordLabel, BorderLayout.NORTH);
JPanel buttonPanel = new JPanel(new GridLayout(9, 4));
for (int i = 0; i < 26; i++) {
letterButtons[i] = new LetterButton(i);
letterButtons[i].setFont(new Font("SansSerif", Font.PLAIN, 14));
buttonPanel.add(letterButtons[i]);
}
for (int i = 0; i < 6; i++)
buttonPanel.add(new JLabel(""));
quitButton = new JButton("quit");
quitButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
}
);
buttonPanel.add(quitButton);
newGameButton = new JButton("new game");
newGameButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
initialize();
}
}
);
buttonPanel.add(newGameButton);
JPanel wrapper = new JPanel();
wrapper.add(buttonPanel);
rightPanel.add(wrapper, BorderLayout.SOUTH);
contents.add(rightPanel, BorderLayout.EAST);
dictionary = new Words();
initialize();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle("Hangman Demo Game 2");
pack();
setVisible(true);
}
void setWordLabelText() {
String theText = new String();
for (int i = 0; i < theWord.length(); i++) {
char ch = theWord.charAt(i);
if (guessed[ch - 'A'])
theText = theText + ch + " ";
else
theText = theText + "_ ";
} // end for loop
wordLabel.setText(theText);
}
void initialize() {
theWord = dictionary.getWord();
won = false;
lost = false;
for (int i = 0; i < 26; i++) {
guessed[i] = false;
letterButtons[i].setEnabled(true);
letterButtons[i].setBackground(plainColor);
}
badGuessCount = 0;
setWordLabelText();
repaint();
}
boolean allGuessed() {
for (int i = 0; i < theWord.length(); i++) {
char ch = theWord.charAt(i);
if (!guessed[ch - 'A'])
return false;
}
return true;
}
public static void main(String args[]) {
Hangman window = new Hangman();
}
class GallowsPanel extends JPanel {
public GallowsPanel() {
super();
setPreferredSize(new Dimension(400, 410));
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
// No matter what, draw the gallows (blue)
g.setColor(Color.blue);
g.drawLine(10,10, 10,350);
g.drawLine(10,350, 100,350);
g.drawLine(100,350, 100,375);
g.drawLine(100,375, 125,375);
g.drawLine(125,375, 125,400);
g.drawLine(125,400, 150,400);
g.drawLine(10,10, 150, 10);
g.drawLine(150,10, 150, 30);
g.setColor(Color.black); // back to black for person
if (badGuessCount > 0)
g.drawOval(110,30, 80,80);
if (badGuessCount > 1)
g.drawLine(150,110, 150,150);
if (badGuessCount > 2)
g.drawLine(150,150, 100,200);
if (badGuessCount > 3)
g.drawLine(150,150, 200,200);
if (badGuessCount > 4)
g.drawLine(150,150, 150,250);
if (badGuessCount > 5)
g.drawLine(150,250, 80,320);
if (badGuessCount > 6)
g.drawLine(150,250, 220,320);
String msg = "YOU WON!";
if (won) {
g.setColor(Color.red);
g.drawArc(120,40, 60,60, 0,-180);
}
if (lost) {
msg = "YOU LOST!";
g.setColor(Color.red);
g.setFont(smallFont);
g.drawString("(the word was " + theWord + ")", 40,230);
g.setColor(Color.red);
g.drawArc(120,80,60,60, 30,120);
}
if (won || lost) {
g.setColor(Color.black);
g.drawOval(110,30, 80,80);
g.setColor(Color.red);
g.setFont(largeFont);
g.drawString(msg,20,200);
g.setColor(Color.blue);
g.fillOval(130,50,10,10);
g.fillOval(160,50,10,10);
g.setColor(Color.black);
g.fillOval(147,65,8,8);
}
}
}
private class LetterButton extends JButton implements ActionListener {
private char theLetter;
private int letterIndex;
public LetterButton(int letterIndex) {
theLetter = (char) (letterIndex + 'A');
this.letterIndex = letterIndex;
String buttonLabel = theLetter + "";
setText(buttonLabel);
addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
guessed[letterIndex] = true;
boolean found = false;
for (int i = 0; i < theWord.length(); i++) {
if (theWord.charAt(i) == theLetter) {
found = true;
}// end if statment
}
if (found) {
setWordLabelText();
letterButtons[letterIndex].setBackground(correctColor);
}
else {
badGuessCount++;
letterButtons[letterIndex].setBackground(wrongColor);
} // end if statment
letterButtons[letterIndex].setEnabled(false);
if (allGuessed()) {
won = true;
}
else if (badGuessCount >= BAD_GUESS_LIMIT) {
lost = true;
} // end if statment
if (won || lost) {
for (int i = 0; i < 26; i++)
letterButtons[i].setEnabled(false);
} // end if statment
gallows.repaint();
}
}
public class Words {
private ArrayList wordList;
public Words() {
wordList = new ArrayList();
wordList.add("COMPUTER");
wordList.add("COMPILER");
wordList.add("INSTRUCTOR");
wordList.add("JAVA");
wordList.add("INTERACTIVE");
wordList.add("PROGRAMING");
wordList.add("POPULATION");
wordList.add("DELIGATION");
wordList.add("BACKDRAFT");
wordList.add("GRAPHICS");
wordList.add("CHILDREN");
wordList.add("CHURCH");
wordList.add("HOLYSPIRIT");
wordList.add("PRINTER");
wordList.add("AFRICA");
wordList.add("CHINA");
wordList.add("FUNGI");
wordList.add("DOCTOR");
wordList.add("NETWORKCARD");
wordList.add("TCIP");
}
public String getWord() {
int size = wordList.size();
int randomIndex = (int) (Math.random() * size);
return (String) wordList.get(randomIndex);
}
}
}
:?: