主题:新手哭求答案啊。。大大们帮忙啊。。小女子这厢有礼了~~
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Random;
public class guoqi extends JFrame
{
public guoqi()
{
setTitle("Hangman");
setSize(750,540);
getContentPane().add(new Gqmb());
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
guoqi p = new guoqi();
}
}
class Gqmb extends JPanel implements ActionListener
{
private int iMissed = 0;
String sCurWord; //secretWord is the word to be guessed
String MASK_CHAR="-";
String maskedWord=" ";
char userGuess; //char the second user guesses //times the user played
private int iMaxMisses = 7; //the maximum chances user has
String x="0",y="0";
xiaomb p=new xiaomb();
public ArrayList alUnusedLetters = null;
public String sGuess = "";
public String sGuessedRightLetters = "";
public boolean bGameComplete = false;
TextField t1=new TextField();
JTextField t2= new JTextField();
JButton btn1=new JButton("提交答案");
Image img;
private static Random r = new Random();
public void start(int iMaxMisses)
{
this.iMaxMisses = iMaxMisses;
iMissed = 0;
bGameComplete = false;
sCurWord = saWordList[r.nextInt(saWordList.length)].toUpperCase();
sGuessedRightLetters = "";
sGuess = "";
for (int count = 0; count < sCurWord.length(); count++) {
sGuess += "_ ";
}
alUnusedLetters = new ArrayList();
String sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int count = 0; count < sLetters.length(); count++) {
alUnusedLetters.add(sLetters.substring(count, count + 1));
}
}
public String getCorrectWord() {
return (sCurWord);
}
public boolean getGameComplete() {
return (bGameComplete);
}
public void setGameComplete(boolean value) {
bGameComplete = value;
}
public String getGuess() {
return (sGuess);
}
public int getMaxMisses() {
return (iMaxMisses);
}
public int getMissed() {
return (iMissed);
}
public ArrayList getUnused() {
return (alUnusedLetters);
}
public void guess(String sLetter) throws HangmanGameException {
//Remove the letter from the "unused letter" list
for (int count = 0; count < alUnusedLetters.size(); count++) {
if (((String) alUnusedLetters.get(count)).equals(sLetter)) {
alUnusedLetters.remove(count);
break;
}
}
//Is the letter in the word?
if (sCurWord.indexOf(sLetter) == -1) {
//This letter is NOT in the word
iMissed++;
throw new HangmanGameException(
"Letter " + sLetter + " is not in the word");
}
//Good letter! Reveal it in the guess
sGuessedRightLetters += sLetter;
//Rebuild the guessed word... make sure
//guessed letters are visible.
sGuess = "";
for (int count = 0; count < sCurWord.length(); count++) {
String sFind = sCurWord.substring(count, count + 1);
if (sGuessedRightLetters.indexOf(sFind) == -1) {
sGuess += "_ ";
} else {
sGuess += sFind + " ";
}
}
}
public boolean getFailed() {
if (iMissed > iMaxMisses) {
return (true);
}
return (false);
}
public boolean getDone() {
if (sGuess.indexOf("_") == -1) {
//All letters guessed right!
return (true);
}
return (false);
}
public Gqmb()
{
setLayout(null);
p.setBounds(20,10,280,500);
add(p);
t1.setBounds(420,60,280,40);
t1.setFocusable(false);
add(t1);
btn1.setBounds(420,420,280,40);
add(btn1);
t2.setBounds(420,110,280,300);
t2.setFocusable(true);
add(t2);
btn1.addActionListener(this);
t1.setText(sCurWord);
}
public class xiaomb extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
img=Toolkit.getDefaultToolkit().getImage("HANG" + iMissed+1 +".gif");
g.drawImage(img,10,48,220,400,this);
}
}
public void actionPerformed(ActionEvent e)
{
Thread th = new Thread();
if(e.getSource().equals(btn1)){
}
if(e.getSource().equals(btn2))
{
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawString(x,540,150);
g.drawString(y,540,190);
}
//The current state of the guessed word
private static String saWordList[] =
{
"access",
"account",
"acquisition",
"acrobat",
"acronym",
"active",
"address",
"adobe",
"affiliate",
"algorithm",
"alias",
"zombie",
"zone" };
}
循环体还没写。。因为程序连词都显示不出来。。图像也没有。。高手们请救命啊。。 [em17][em17][em17]
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Random;
public class guoqi extends JFrame
{
public guoqi()
{
setTitle("Hangman");
setSize(750,540);
getContentPane().add(new Gqmb());
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
guoqi p = new guoqi();
}
}
class Gqmb extends JPanel implements ActionListener
{
private int iMissed = 0;
String sCurWord; //secretWord is the word to be guessed
String MASK_CHAR="-";
String maskedWord=" ";
char userGuess; //char the second user guesses //times the user played
private int iMaxMisses = 7; //the maximum chances user has
String x="0",y="0";
xiaomb p=new xiaomb();
public ArrayList alUnusedLetters = null;
public String sGuess = "";
public String sGuessedRightLetters = "";
public boolean bGameComplete = false;
TextField t1=new TextField();
JTextField t2= new JTextField();
JButton btn1=new JButton("提交答案");
Image img;
private static Random r = new Random();
public void start(int iMaxMisses)
{
this.iMaxMisses = iMaxMisses;
iMissed = 0;
bGameComplete = false;
sCurWord = saWordList[r.nextInt(saWordList.length)].toUpperCase();
sGuessedRightLetters = "";
sGuess = "";
for (int count = 0; count < sCurWord.length(); count++) {
sGuess += "_ ";
}
alUnusedLetters = new ArrayList();
String sLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int count = 0; count < sLetters.length(); count++) {
alUnusedLetters.add(sLetters.substring(count, count + 1));
}
}
public String getCorrectWord() {
return (sCurWord);
}
public boolean getGameComplete() {
return (bGameComplete);
}
public void setGameComplete(boolean value) {
bGameComplete = value;
}
public String getGuess() {
return (sGuess);
}
public int getMaxMisses() {
return (iMaxMisses);
}
public int getMissed() {
return (iMissed);
}
public ArrayList getUnused() {
return (alUnusedLetters);
}
public void guess(String sLetter) throws HangmanGameException {
//Remove the letter from the "unused letter" list
for (int count = 0; count < alUnusedLetters.size(); count++) {
if (((String) alUnusedLetters.get(count)).equals(sLetter)) {
alUnusedLetters.remove(count);
break;
}
}
//Is the letter in the word?
if (sCurWord.indexOf(sLetter) == -1) {
//This letter is NOT in the word
iMissed++;
throw new HangmanGameException(
"Letter " + sLetter + " is not in the word");
}
//Good letter! Reveal it in the guess
sGuessedRightLetters += sLetter;
//Rebuild the guessed word... make sure
//guessed letters are visible.
sGuess = "";
for (int count = 0; count < sCurWord.length(); count++) {
String sFind = sCurWord.substring(count, count + 1);
if (sGuessedRightLetters.indexOf(sFind) == -1) {
sGuess += "_ ";
} else {
sGuess += sFind + " ";
}
}
}
public boolean getFailed() {
if (iMissed > iMaxMisses) {
return (true);
}
return (false);
}
public boolean getDone() {
if (sGuess.indexOf("_") == -1) {
//All letters guessed right!
return (true);
}
return (false);
}
public Gqmb()
{
setLayout(null);
p.setBounds(20,10,280,500);
add(p);
t1.setBounds(420,60,280,40);
t1.setFocusable(false);
add(t1);
btn1.setBounds(420,420,280,40);
add(btn1);
t2.setBounds(420,110,280,300);
t2.setFocusable(true);
add(t2);
btn1.addActionListener(this);
t1.setText(sCurWord);
}
public class xiaomb extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
img=Toolkit.getDefaultToolkit().getImage("HANG" + iMissed+1 +".gif");
g.drawImage(img,10,48,220,400,this);
}
}
public void actionPerformed(ActionEvent e)
{
Thread th = new Thread();
if(e.getSource().equals(btn1)){
}
if(e.getSource().equals(btn2))
{
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.drawString(x,540,150);
g.drawString(y,540,190);
}
//The current state of the guessed word
private static String saWordList[] =
{
"access",
"account",
"acquisition",
"acrobat",
"acronym",
"active",
"address",
"adobe",
"affiliate",
"algorithm",
"alias",
"zombie",
"zone" };
}
循环体还没写。。因为程序连词都显示不出来。。图像也没有。。高手们请救命啊。。 [em17][em17][em17]