Java程序无法运行,我不知道出了什么问题
我一直在试图找出为什么我尝试运行的这个 Java 程序无法执行此操作。它还没有完成,但我只是想确保我按照我想要的方式获得了所有 GUI 方面的内容。无论我做什么,Netbeans 都不会告诉我发生了什么,但它会正常运行其他程序。
package TheGameCorner;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class HeartAndSoul extends JFrame implements ActionListener
{
Random rand = new Random();
int bombs = 13;
int newBombCheck = 0;
int bombX, bombY;
String bombCarrier;
String bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen;
int gameOver = 0;
int scoreVal = 0, colOneVal = 0, colTwoVal = 0, colThreeVal = 0, colFourVal = 0, colFiveVal = 0, rowOneVal = 0, rowTwoVal = 0, rowThreeVal = 0, rowFourVal = 0, rowFiveVal = 0;
String oneOneVal = "oneOne", oneTwoVal = "oneTwo", oneThreeVal = "oneThree", oneFourVal = "oneFour", oneFiveVal = "oneFive";
String twoOneVal = "twoOne", twoTwoVal = "twoTwo", twoThreeVal = "twoThree", twoFourVal = "twoFour", twoFiveVal = "twoFive";
String threeOneVal = "threeOne", threeTwoVal = "threeTwo", threeThreeVal = "threeThree", threeFourVal = "threeFour", threeFiveVal = "threeFive";
String fourOneVal = "fourOne", fourTwoVal = "fourTwo", fourThreeVal = "fourThree", fourFourVal = "fourFour", fourFiveVal = "fourFive";
String fiveOneVal = "fiveOne", fiveTwoVal = "fiveTwo", fiveThreeVal = "fiveThree", fiveFourVal = "fiveFour", fiveFiveVal = "fiveFive";
public HeartAndSoul(String title)
{
super(title);
bOne = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen); //<editor-fold>
bTwo = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bThree = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bFour = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bFive = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bSix = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bSeven = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bEight = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bNine = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bTen = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bEleven = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bTwelve = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bThirteen = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen); //</editor-fold>
oneOneVal = SetBomb(oneOneVal); //<editor-fold>
oneTwoVal = SetBomb(oneTwoVal);
oneThreeVal = SetBomb(oneThreeVal);
oneFourVal = SetBomb(oneFourVal);
oneFiveVal = SetBomb(oneFiveVal);
twoOneVal = SetBomb(twoOneVal);
twoTwoVal = SetBomb(twoTwoVal);
twoThreeVal = SetBomb(twoThreeVal);
twoFourVal = SetBomb(twoFourVal);
twoFiveVal = SetBomb(twoFiveVal);
threeOneVal = SetBomb(threeOneVal);
threeTwoVal = SetBomb(threeTwoVal);
threeThreeVal = SetBomb(threeThreeVal);
threeFourVal = SetBomb(threeFourVal);
threeFiveVal = SetBomb(threeFiveVal);
fourOneVal = SetBomb(fourOneVal);
fourTwoVal = SetBomb(fourTwoVal);
fourThreeVal = SetBomb(fourThreeVal);
fourFourVal = SetBomb(fourFourVal);
fourFiveVal = SetBomb(fourFiveVal);
fiveOneVal = SetBomb(fiveOneVal);
fiveTwoVal = SetBomb(fiveTwoVal);
fiveThreeVal = SetBomb(fiveThreeVal);
fiveFourVal = SetBomb(fiveFourVal);
fiveFiveVal = SetBomb(fiveFiveVal); //</editor-fold>
if (oneOneVal.equals("b")) //<editor-fold>
{
rowOneVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (oneTwoVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (oneThreeVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (oneFourVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (oneFiveVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (twoOneVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (twoTwoVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (twoThreeVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (twoFourVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (twoFiveVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (threeOneVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (threeTwoVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (threeThreeVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (threeFourVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (threeFiveVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (fourOneVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (fourTwoVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (fourThreeVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (fourFourVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (fourFiveVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (fiveOneVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (fiveTwoVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (fiveThreeVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (fiveFourVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (fiveFiveVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colFiveVal=colOneVal+1;
} //</editor-fold>
JPanel refRow = new JPanel(), oneRow = new JPanel(), twoRow = new JPanel(), threeRow = new JPanel(), fourRow = new JPanel(), fiveRow = new JPanel(), infoRow = new JPanel(); //<editor-fold>
JTextField colOne = new JTextField(1), colTwo = new JTextField(1), colThree = new JTextField(1), colFour = new JTextField(1), colFive = new JTextField(1), rowOne = new JTextField(1), rowTwo = new JTextField(1), rowThree = new JTextField(1), rowFour = new JTextField(1), rowFive = new JTextField(1), score = new JTextField(9);
colOne.setEditable(false); colTwo.setEditable(false); colThree.setEditable(false); colFour.setEditable(false); colFive.setEditable(false); rowOne.setEditable(false); rowTwo.setEditable(false); rowThree.setEditable(false); rowFour.setEditable(false); rowFive.setEditable(false); score.setEditable(false);
JButton oneOne = new JButton(""), oneTwo = new JButton(""), oneThree = new JButton(""), oneFour = new JButton(""), oneFive = new JButton(""), twoOne = new JButton(""), twoTwo = new JButton(""), twoThree = new JButton(""), twoFour = new JButton(""), twoFive = new JButton(""), threeOne = new JButton(""), threeTwo = new JButton(""), threeThree = new JButton(""), threeFour = new JButton(""), threeFive = new JButton(""), fourOne = new JButton(""), fourTwo = new JButton(""), fourThree = new JButton(""), fourFour = new JButton(""), fourFive = new JButton(""), fiveOne = new JButton(""), fiveTwo = new JButton(""), fiveThree = new JButton(""), fiveFour = new JButton(""), fiveFive = new JButton("");
oneOne.setSize(20,20); oneTwo.setSize(20,20); oneThree.setSize(20,20); oneFour.setSize(20,20); oneFive.setSize(20,20); twoOne.setSize(20,20); twoTwo.setSize(20,20); twoThree.setSize(20,20); twoFour.setSize(20,20); twoFive.setSize(20,20); threeOne.setSize(20,20); threeTwo.setSize(20,20); threeThree.setSize(20,20); threeFour.setSize(20,20); threeFive.setSize(20,20); fourOne.setSize(20,20); fourTwo.setSize(20,20); fourThree.setSize(20,20); fourFour.setSize(20,20); fourFive.setSize(20,20); fiveOne.setSize(20,20); fiveTwo.setSize(20,20); fiveThree.setSize(20,20); fiveFour.setSize(20,20); fiveFive.setSize(20,20);
oneOne.setActionCommand(oneOneVal); oneTwo.setActionCommand(oneTwoVal); oneThree.setActionCommand(oneThreeVal); oneFour.setActionCommand(oneFourVal); oneFive.setActionCommand(oneFiveVal); twoOne.setActionCommand(twoOneVal); twoTwo.setActionCommand(twoTwoVal); twoThree.setActionCommand(twoThreeVal); twoFour.setActionCommand(twoFourVal); twoFive.setActionCommand(twoFiveVal); threeOne.setActionCommand(threeOneVal); threeTwo.setActionCommand(threeTwoVal); threeThree.setActionCommand(threeThreeVal); threeFour.setActionCommand(threeFourVal); threeFive.setActionCommand(threeFiveVal); fourOne.setActionCommand(fourOneVal); fourTwo.setActionCommand(fourTwoVal); fourThree.setActionCommand(fourThreeVal); fourFour.setActionCommand(fourFourVal); fourFive.setActionCommand(fourFiveVal); fiveOne.setActionCommand(fiveOneVal); fiveTwo.setActionCommand(fiveTwoVal); fiveThree.setActionCommand(fiveThreeVal); fiveFour.setActionCommand(fiveFourVal); fiveFive.setActionCommand(fiveFiveVal);
oneOne.addActionListener(this); oneTwo.addActionListener(this); oneThree.addActionListener(this); oneFour.addActionListener(this); oneFive.addActionListener(this); twoOne.addActionListener(this); twoTwo.addActionListener(this); twoThree.addActionListener(this); twoFour.addActionListener(this); twoFive.addActionListener(this); threeOne.addActionListener(this); threeTwo.addActionListener(this); threeThree.addActionListener(this); threeFour.addActionListener(this); threeFive.addActionListener(this); fourOne.addActionListener(this); fourTwo.addActionListener(this); fourThree.addActionListener(this); fourFour.addActionListener(this); fourFive.addActionListener(this); fiveOne.addActionListener(this); fiveTwo.addActionListener(this); fiveThree.addActionListener(this); fiveFour.addActionListener(this); fiveFive.addActionListener(this);
JLabel scoreText = new JLabel("Score:");
refRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
oneRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
twoRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
threeRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
fourRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
fiveRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
infoRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
refRow.setSize(150,40);
oneRow.setSize(150,40);
twoRow.setSize(150,40);
threeRow.setSize(150,40);
fourRow.setSize(150,40);
fiveRow.setSize(150,40);
infoRow.setSize(150,40);
refRow.add(colOne);
refRow.add(colTwo);
refRow.add(colThree);
refRow.add(colFour);
refRow.add(colFive);
oneRow.add(oneOne);
oneRow.add(oneTwo);
oneRow.add(oneThree);
oneRow.add(oneFour);
oneRow.add(oneFive);
oneRow.add(rowOne);
twoRow.add(twoOne);
twoRow.add(twoTwo);
twoRow.add(twoThree);
twoRow.add(twoFour);
twoRow.add(twoFive);
twoRow.add(rowTwo);
threeRow.add(threeOne);
threeRow.add(threeTwo);
threeRow.add(threeThree);
threeRow.add(threeFour);
threeRow.add(threeFive);
threeRow.add(rowThree);
fourRow.add(fourOne);
fourRow.add(fourTwo);
fourRow.add(fourThree);
fourRow.add(fourFour);
fourRow.add(fourFive);
fourRow.add(rowFour);
fiveRow.add(fiveOne);
fiveRow.add(fiveTwo);
fiveRow.add(fiveThree);
fiveRow.add(fiveFour);
fiveRow.add(fiveFive);
fiveRow.add(rowFive);
infoRow.add(scoreText);
infoRow.add(score); //</editor-fold>
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(refRow);
add(oneRow);
add(twoRow);
add(threeRow);
add(fourRow);
add(fiveRow);
add(infoRow);
colOne.setText(colOneVal+"");
colTwo.setText(colTwoVal+"");
colThree.setText(colThreeVal+"");
colFour.setText(colFourVal+"");
colFive.setText(colFiveVal+"");
rowOne.setText(rowOneVal+"");
rowTwo.setText(rowTwoVal+"");
rowThree.setText(rowThreeVal+"");
rowFour.setText(rowFourVal+"");
rowFive.setText(rowFiveVal+"");
score.setText(scoreVal+"");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent evt)
{
//more code will go here, not done yet
repaint();
}
private String BombGen(String bone, String btwo, String bthree, String bfour, String bfive, String bsix, String bseven, String beight, String bnine, String bten, String beleven, String btwelve, String bthirteen)
{
newBombCheck = 0;
while (newBombCheck == 0)
{
bombX = rand.nextInt(5)+1;
bombY = rand.nextInt(5)+1;
if (bombX == 1)
bombCarrier="one";
if (bombX == 2)
bombCarrier="two";
if (bombX == 3)
bombCarrier="three";
if (bombX == 4)
bombCarrier="four";
if (bombX == 5)
bombCarrier="five";
if (bombY == 1)
bombCarrier.concat("One");
if (bombY == 2)
bombCarrier.concat("Two");
if (bombY == 3)
bombCarrier.concat("Three");
if (bombY == 4)
bombCarrier.concat("Four");
if (bombY == 5)
bombCarrier.concat("Five");
if (!bombCarrier.equals(bone) && !bombCarrier.equals(btwo) && !bombCarrier.equals(bthree) && !bombCarrier.equals(bfour) && !bombCarrier.equals(bfive) && !bombCarrier.equals(bsix) && !bombCarrier.equals(bseven) && !bombCarrier.equals(beight) && !bombCarrier.equals(bnine) && !bombCarrier.equals(bten) && !bombCarrier.equals(beleven) && !bombCarrier.equals(btwelve) && !bombCarrier.equals(bthirteen))
newBombCheck = 1;
}
return bombCarrier;
}
private String SetBomb(String suspect)
{
if (suspect.equals(bOne) || suspect.equals(bTwo) || suspect.equals(bThree) || suspect.equals(bFour) || suspect.equals(bFive) || suspect.equals(bSix) || suspect.equals(bSeven) || suspect.equals(bEight) || suspect.equals(bNine) || suspect.equals(bTen) || suspect.equals(bEleven) || suspect.equals(bTwelve) || suspect.equals(bThirteen))
suspect = "b";
return suspect;
}
public static void main(String[] args)
{
HeartAndSoul echo = new HeartAndSoul("The Game Corner") ;
echo.setSize(200,300);
echo.setVisible(true);
}
}
抱歉这么长,但我想把整个事情都放出来,因为我完全不知道我做错了什么。我尝试更具体地添加操作侦听器,我尝试添加 Override 注释,但 Netbeans 拒绝比开始执行程序更进一步。
I've been trying to figure out why this Java program I am trying to run won't do it. It's not finished yet, but I'm just trying to make sure I got all the GUI aspects the way I want them to be. Netbeans wont even tell me whats going on no matter what I do, but it will run other programs just fine.
package TheGameCorner;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class HeartAndSoul extends JFrame implements ActionListener
{
Random rand = new Random();
int bombs = 13;
int newBombCheck = 0;
int bombX, bombY;
String bombCarrier;
String bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen;
int gameOver = 0;
int scoreVal = 0, colOneVal = 0, colTwoVal = 0, colThreeVal = 0, colFourVal = 0, colFiveVal = 0, rowOneVal = 0, rowTwoVal = 0, rowThreeVal = 0, rowFourVal = 0, rowFiveVal = 0;
String oneOneVal = "oneOne", oneTwoVal = "oneTwo", oneThreeVal = "oneThree", oneFourVal = "oneFour", oneFiveVal = "oneFive";
String twoOneVal = "twoOne", twoTwoVal = "twoTwo", twoThreeVal = "twoThree", twoFourVal = "twoFour", twoFiveVal = "twoFive";
String threeOneVal = "threeOne", threeTwoVal = "threeTwo", threeThreeVal = "threeThree", threeFourVal = "threeFour", threeFiveVal = "threeFive";
String fourOneVal = "fourOne", fourTwoVal = "fourTwo", fourThreeVal = "fourThree", fourFourVal = "fourFour", fourFiveVal = "fourFive";
String fiveOneVal = "fiveOne", fiveTwoVal = "fiveTwo", fiveThreeVal = "fiveThree", fiveFourVal = "fiveFour", fiveFiveVal = "fiveFive";
public HeartAndSoul(String title)
{
super(title);
bOne = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen); //<editor-fold>
bTwo = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bThree = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bFour = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bFive = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bSix = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bSeven = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bEight = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bNine = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bTen = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bEleven = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bTwelve = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen);
bThirteen = BombGen(bOne, bTwo, bThree, bFour, bFive, bSix, bSeven, bEight, bNine, bTen, bEleven, bTwelve, bThirteen); //</editor-fold>
oneOneVal = SetBomb(oneOneVal); //<editor-fold>
oneTwoVal = SetBomb(oneTwoVal);
oneThreeVal = SetBomb(oneThreeVal);
oneFourVal = SetBomb(oneFourVal);
oneFiveVal = SetBomb(oneFiveVal);
twoOneVal = SetBomb(twoOneVal);
twoTwoVal = SetBomb(twoTwoVal);
twoThreeVal = SetBomb(twoThreeVal);
twoFourVal = SetBomb(twoFourVal);
twoFiveVal = SetBomb(twoFiveVal);
threeOneVal = SetBomb(threeOneVal);
threeTwoVal = SetBomb(threeTwoVal);
threeThreeVal = SetBomb(threeThreeVal);
threeFourVal = SetBomb(threeFourVal);
threeFiveVal = SetBomb(threeFiveVal);
fourOneVal = SetBomb(fourOneVal);
fourTwoVal = SetBomb(fourTwoVal);
fourThreeVal = SetBomb(fourThreeVal);
fourFourVal = SetBomb(fourFourVal);
fourFiveVal = SetBomb(fourFiveVal);
fiveOneVal = SetBomb(fiveOneVal);
fiveTwoVal = SetBomb(fiveTwoVal);
fiveThreeVal = SetBomb(fiveThreeVal);
fiveFourVal = SetBomb(fiveFourVal);
fiveFiveVal = SetBomb(fiveFiveVal); //</editor-fold>
if (oneOneVal.equals("b")) //<editor-fold>
{
rowOneVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (oneTwoVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (oneThreeVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (oneFourVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (oneFiveVal.equals("b"))
{
rowOneVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (twoOneVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (twoTwoVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (twoThreeVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (twoFourVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (twoFiveVal.equals("b"))
{
rowTwoVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (threeOneVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (threeTwoVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (threeThreeVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (threeFourVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (threeFiveVal.equals("b"))
{
rowThreeVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (fourOneVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (fourTwoVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (fourThreeVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (fourFourVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (fourFiveVal.equals("b"))
{
rowFourVal=rowOneVal+1;
colFiveVal=colOneVal+1;
}
if (fiveOneVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colOneVal=colOneVal+1;
}
if (fiveTwoVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colTwoVal=colOneVal+1;
}
if (fiveThreeVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colThreeVal=colOneVal+1;
}
if (fiveFourVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colFourVal=colOneVal+1;
}
if (fiveFiveVal.equals("b"))
{
rowFiveVal=rowOneVal+1;
colFiveVal=colOneVal+1;
} //</editor-fold>
JPanel refRow = new JPanel(), oneRow = new JPanel(), twoRow = new JPanel(), threeRow = new JPanel(), fourRow = new JPanel(), fiveRow = new JPanel(), infoRow = new JPanel(); //<editor-fold>
JTextField colOne = new JTextField(1), colTwo = new JTextField(1), colThree = new JTextField(1), colFour = new JTextField(1), colFive = new JTextField(1), rowOne = new JTextField(1), rowTwo = new JTextField(1), rowThree = new JTextField(1), rowFour = new JTextField(1), rowFive = new JTextField(1), score = new JTextField(9);
colOne.setEditable(false); colTwo.setEditable(false); colThree.setEditable(false); colFour.setEditable(false); colFive.setEditable(false); rowOne.setEditable(false); rowTwo.setEditable(false); rowThree.setEditable(false); rowFour.setEditable(false); rowFive.setEditable(false); score.setEditable(false);
JButton oneOne = new JButton(""), oneTwo = new JButton(""), oneThree = new JButton(""), oneFour = new JButton(""), oneFive = new JButton(""), twoOne = new JButton(""), twoTwo = new JButton(""), twoThree = new JButton(""), twoFour = new JButton(""), twoFive = new JButton(""), threeOne = new JButton(""), threeTwo = new JButton(""), threeThree = new JButton(""), threeFour = new JButton(""), threeFive = new JButton(""), fourOne = new JButton(""), fourTwo = new JButton(""), fourThree = new JButton(""), fourFour = new JButton(""), fourFive = new JButton(""), fiveOne = new JButton(""), fiveTwo = new JButton(""), fiveThree = new JButton(""), fiveFour = new JButton(""), fiveFive = new JButton("");
oneOne.setSize(20,20); oneTwo.setSize(20,20); oneThree.setSize(20,20); oneFour.setSize(20,20); oneFive.setSize(20,20); twoOne.setSize(20,20); twoTwo.setSize(20,20); twoThree.setSize(20,20); twoFour.setSize(20,20); twoFive.setSize(20,20); threeOne.setSize(20,20); threeTwo.setSize(20,20); threeThree.setSize(20,20); threeFour.setSize(20,20); threeFive.setSize(20,20); fourOne.setSize(20,20); fourTwo.setSize(20,20); fourThree.setSize(20,20); fourFour.setSize(20,20); fourFive.setSize(20,20); fiveOne.setSize(20,20); fiveTwo.setSize(20,20); fiveThree.setSize(20,20); fiveFour.setSize(20,20); fiveFive.setSize(20,20);
oneOne.setActionCommand(oneOneVal); oneTwo.setActionCommand(oneTwoVal); oneThree.setActionCommand(oneThreeVal); oneFour.setActionCommand(oneFourVal); oneFive.setActionCommand(oneFiveVal); twoOne.setActionCommand(twoOneVal); twoTwo.setActionCommand(twoTwoVal); twoThree.setActionCommand(twoThreeVal); twoFour.setActionCommand(twoFourVal); twoFive.setActionCommand(twoFiveVal); threeOne.setActionCommand(threeOneVal); threeTwo.setActionCommand(threeTwoVal); threeThree.setActionCommand(threeThreeVal); threeFour.setActionCommand(threeFourVal); threeFive.setActionCommand(threeFiveVal); fourOne.setActionCommand(fourOneVal); fourTwo.setActionCommand(fourTwoVal); fourThree.setActionCommand(fourThreeVal); fourFour.setActionCommand(fourFourVal); fourFive.setActionCommand(fourFiveVal); fiveOne.setActionCommand(fiveOneVal); fiveTwo.setActionCommand(fiveTwoVal); fiveThree.setActionCommand(fiveThreeVal); fiveFour.setActionCommand(fiveFourVal); fiveFive.setActionCommand(fiveFiveVal);
oneOne.addActionListener(this); oneTwo.addActionListener(this); oneThree.addActionListener(this); oneFour.addActionListener(this); oneFive.addActionListener(this); twoOne.addActionListener(this); twoTwo.addActionListener(this); twoThree.addActionListener(this); twoFour.addActionListener(this); twoFive.addActionListener(this); threeOne.addActionListener(this); threeTwo.addActionListener(this); threeThree.addActionListener(this); threeFour.addActionListener(this); threeFive.addActionListener(this); fourOne.addActionListener(this); fourTwo.addActionListener(this); fourThree.addActionListener(this); fourFour.addActionListener(this); fourFive.addActionListener(this); fiveOne.addActionListener(this); fiveTwo.addActionListener(this); fiveThree.addActionListener(this); fiveFour.addActionListener(this); fiveFive.addActionListener(this);
JLabel scoreText = new JLabel("Score:");
refRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
oneRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
twoRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
threeRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
fourRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
fiveRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
infoRow.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
refRow.setSize(150,40);
oneRow.setSize(150,40);
twoRow.setSize(150,40);
threeRow.setSize(150,40);
fourRow.setSize(150,40);
fiveRow.setSize(150,40);
infoRow.setSize(150,40);
refRow.add(colOne);
refRow.add(colTwo);
refRow.add(colThree);
refRow.add(colFour);
refRow.add(colFive);
oneRow.add(oneOne);
oneRow.add(oneTwo);
oneRow.add(oneThree);
oneRow.add(oneFour);
oneRow.add(oneFive);
oneRow.add(rowOne);
twoRow.add(twoOne);
twoRow.add(twoTwo);
twoRow.add(twoThree);
twoRow.add(twoFour);
twoRow.add(twoFive);
twoRow.add(rowTwo);
threeRow.add(threeOne);
threeRow.add(threeTwo);
threeRow.add(threeThree);
threeRow.add(threeFour);
threeRow.add(threeFive);
threeRow.add(rowThree);
fourRow.add(fourOne);
fourRow.add(fourTwo);
fourRow.add(fourThree);
fourRow.add(fourFour);
fourRow.add(fourFive);
fourRow.add(rowFour);
fiveRow.add(fiveOne);
fiveRow.add(fiveTwo);
fiveRow.add(fiveThree);
fiveRow.add(fiveFour);
fiveRow.add(fiveFive);
fiveRow.add(rowFive);
infoRow.add(scoreText);
infoRow.add(score); //</editor-fold>
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(refRow);
add(oneRow);
add(twoRow);
add(threeRow);
add(fourRow);
add(fiveRow);
add(infoRow);
colOne.setText(colOneVal+"");
colTwo.setText(colTwoVal+"");
colThree.setText(colThreeVal+"");
colFour.setText(colFourVal+"");
colFive.setText(colFiveVal+"");
rowOne.setText(rowOneVal+"");
rowTwo.setText(rowTwoVal+"");
rowThree.setText(rowThreeVal+"");
rowFour.setText(rowFourVal+"");
rowFive.setText(rowFiveVal+"");
score.setText(scoreVal+"");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent evt)
{
//more code will go here, not done yet
repaint();
}
private String BombGen(String bone, String btwo, String bthree, String bfour, String bfive, String bsix, String bseven, String beight, String bnine, String bten, String beleven, String btwelve, String bthirteen)
{
newBombCheck = 0;
while (newBombCheck == 0)
{
bombX = rand.nextInt(5)+1;
bombY = rand.nextInt(5)+1;
if (bombX == 1)
bombCarrier="one";
if (bombX == 2)
bombCarrier="two";
if (bombX == 3)
bombCarrier="three";
if (bombX == 4)
bombCarrier="four";
if (bombX == 5)
bombCarrier="five";
if (bombY == 1)
bombCarrier.concat("One");
if (bombY == 2)
bombCarrier.concat("Two");
if (bombY == 3)
bombCarrier.concat("Three");
if (bombY == 4)
bombCarrier.concat("Four");
if (bombY == 5)
bombCarrier.concat("Five");
if (!bombCarrier.equals(bone) && !bombCarrier.equals(btwo) && !bombCarrier.equals(bthree) && !bombCarrier.equals(bfour) && !bombCarrier.equals(bfive) && !bombCarrier.equals(bsix) && !bombCarrier.equals(bseven) && !bombCarrier.equals(beight) && !bombCarrier.equals(bnine) && !bombCarrier.equals(bten) && !bombCarrier.equals(beleven) && !bombCarrier.equals(btwelve) && !bombCarrier.equals(bthirteen))
newBombCheck = 1;
}
return bombCarrier;
}
private String SetBomb(String suspect)
{
if (suspect.equals(bOne) || suspect.equals(bTwo) || suspect.equals(bThree) || suspect.equals(bFour) || suspect.equals(bFive) || suspect.equals(bSix) || suspect.equals(bSeven) || suspect.equals(bEight) || suspect.equals(bNine) || suspect.equals(bTen) || suspect.equals(bEleven) || suspect.equals(bTwelve) || suspect.equals(bThirteen))
suspect = "b";
return suspect;
}
public static void main(String[] args)
{
HeartAndSoul echo = new HeartAndSoul("The Game Corner") ;
echo.setSize(200,300);
echo.setVisible(true);
}
}
Sorry it's so long, but I wanted to put the entire thing up because I have absolutely no idea what I'm doing wrong. I've tried being more specific with adding the action listener, I've tried adding Override annotation, but Netbeans refuses to get further than starting the execution of the program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题就在这里:
这个 if 从未被输入,因此 newBombCheck 永远不会被设置为 1,因此循环将永远运行。
你应该考虑一下。对我来说,在构造函数中做这么多也是错误的。
这段代码的维护将是一场噩梦,您可能需要稍微重命名一些内容,并添加注释以明确您想要实现的目标以及原因,
干杯,尤金。
The problem is here:
This if is never entered, thus newBombCheck is never set to 1, thus the loop runs forever.
You should think a bit stuff over. Also doing SO MUCH in a constructor is just wrong, to me.
This code is going to be a nightmare to maintain, you might want to rename things a bit, and add comments to make is clear what you want to achieve and why may be
Cheers, Eugene.
这里有一个无限循环:
在这个循环中放入
System.out.println(bombCarrier);
并检查这些值是否符合您的预期。无论值是什么,您的代码永远不会命中此循环中的if
语句,因此newBombCheck
永远不会设置为 1。You have an infinite loop here:
Inside this loop put
System.out.println(bombCarrier);
and check whether the values are as you would expect them to be. Whatever the values are, your code never hits theif
statement in this loop and thusnewBombCheck
is never set to 1.它在
BombGen
方法中处于无限循环中。newBombCheck
始终为 0。您应该做的是在调试器中运行,然后暂停应用程序。它总是会在你的循环中停止,这应该告诉你出了什么问题。It is in an infinite loop in the
BombGen
method.newBombCheck
is always 0. What you should do is run in the debugger, and then pause the app. It will always stop in your loop, which should tell you something is wrong.我认为您尝试将其从 5*5 缩放到 13*13,但忘记添加炸弹X=6...13 以及炸弹Y。这就是为什么它在bombGen6之后卡住了。
然后你的条件永远不会成立并继续生成黑白 1-5 的运行数字。
I think You tried to scale it from 5*5 to 13*13, but forgot to add bombX=6...13 and for bombY too. that's why it stuck after bombGen6.
and then your condition is never true and keep generating ran numbers b/w 1-5.