JFrame does not wait for JOptionPane to execute - java

I am working on a project in which I create a simple game of Ping Pong. If a player wins, I would like that a JOptionPane pop up asking if the user would like to play a new Game or stop playing. When I add the JOptionPane, the method does not wait for the user to select a button, but keeps going and keeps creating JOptionPanes until it returns a Stack Overflow Error. The code that controls it is
int rightMinLeft = Right_Player_Score.getNumber()-Left_Player_Score.getNumber();
boolean rightWon = Right_Player_Score.getNumber() > 20 && rightMinLeft > 1;
if(rightWon)
{
Object[] options = {"New Game", "Finish"};
int i = JOptionPane.showOptionDialog(null, "Right Player has won", "Game Over", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if(i == 0)
{
reset();
}
else
{
GameOver = true;
}
}
else if(Left_Player_Score.getNumber() > 20 && Left_Player_Score.getNumber()-Right_Player_Score.getNumber()>1)
{
Object[] options = {"New Game", "Finish"};
int i = JOptionPane.showOptionDialog(null, "Right Player has won", "Game Over", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if(i == 0)
{
reset();
}
else
{
GameOver = true;
}
}
Any suggestions?
Edit:
Here is the full method:
public void update(Graphics window)
{
paint(window);
}
public void paint(Graphics window)
{
try{
if(pause)
{
Right_Player_Score.draw("Right Player Score", window, 600, 20);
Left_Player_Score.draw("Left Player Score", window, 0, 20);
leftPaddle.draw(window);
rightPaddle.draw(window);
if(U.LELatch(keys[4]))
{
pause = false;
}
}
else
{
ball.moveAndDraw(window);
leftPaddle.draw(window);
Right_Player_Score.draw("Right Player Score", window, Color.WHITE, 600, 20);
Left_Player_Score.draw("Left Player Score", window, Color.WHITE, 0, 20);
int LeftPaddleBottom = leftPaddle.getY()+(leftPaddle.getHeight());
int RightPaddleBottom = rightPaddle.getY()+(rightPaddle.getHeight());
int LeftPaddleTop = leftPaddle.getY();
int RightPaddleTop = rightPaddle.getY();
boolean inRangeLeft = ball.getY() > LeftPaddleTop && ball.getY() < LeftPaddleBottom;
boolean inRangeRight = ball.getY() > RightPaddleTop && ball.getY() < RightPaddleBottom;
if(ball.getX()<=10)
{
ball.setXSpeed(-ball.getXSpeed());
Right_Player_Score.increment();
}
else if(ball.getX()>=790)
{
ball.setXSpeed(-ball.getXSpeed());
Left_Player_Score.increment();
}
else if((inRangeLeft && ball.getX()<=leftPaddle.getX()+leftPaddle.getWidth()))
{
ball.setXSpeed(-ball.getXSpeed());
numTimes ++;
}
else if(inRangeRight && ball.getX()>=rightPaddle.getX())
{
ball.setXSpeed(-ball.getXSpeed());
numTimes ++;
}
if(!(ball.getY()>=10 && ball.getY()<=450))
{
ball.setYSpeed(-ball.getYSpeed());
}
if(keys[0] == true)
{
leftPaddle.moveUpAndDraw(window);
}
else if(keys[1] == true)
{
leftPaddle.moveDownAndDraw(window);
}
else
{
leftPaddle.draw(window);
}
if(keys[2] == true)
{
rightPaddle.moveUpAndDraw(window);
}
else if(keys[3] == true)
{
rightPaddle.moveDownAndDraw(window);
}
else
{
rightPaddle.draw(window);
}
int rightMinLeft = Right_Player_Score.getNumber()-Left_Player_Score.getNumber();
boolean rightWon = Right_Player_Score.getNumber() > 20 && rightMinLeft > 1;
if(rightWon)
{
Object[] options = {"New Game", "Finish"};
int i = JOptionPane.showOptionDialog(frame, "Right Player has won", "Game Over", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
//window.setColor(Color.BLACK);
//window.drawString("Right Player has won",200,400);
//Thread.currentThread().sleep(2000);
//int i = 1;
if(i == 0)
{
reset();
}
else
{
GameOver = true;
}
}
else if(Left_Player_Score.getNumber() > 20 && Left_Player_Score.getNumber()-Right_Player_Score.getNumber()>1)
{
Object[] options = {"New Game", "Finish"};
int i = JOptionPane.showOptionDialog(frame, "Left Player has won", "Game Over", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
//window.setColor(Color.BLACK);
//window.drawString("Left Player has won",200,400);
//Thread.currentThread().sleep(2000);
//int i = 1;
if(i == 0)
{
reset();
}
else
{
GameOver = true;
}
}
Right_Player_Score.draw("Right Player Score", window, 600, 20);
Left_Player_Score.draw("Left Player Score", window, 0, 20);
if(numTimes == 10)
{
numTimes = 0;
if(ball.getXSpeed() == Math.abs(ball.getXSpeed()))
{
ball.setXSpeed(ball.getXSpeed() + 1);
}
else
{
ball.setXSpeed(ball.getXSpeed() - 1);
}
if(ball.getXSpeed()>MAXSPEED)
{
ball.setXSpeed(MAXSPEED);
}
}
pause = U.LELatch(keys[4]);
}
}
catch(Exception e)
{
}
}
This is used in "public class GUI_Controller extends Canvas implements KeyListener, Runnable"
Note: The commented portions are a stopgap way of getting the user to at least see something.

The behavior you are seeing is because you are overloading the paint(Graphics g) method.
From the paint(Graphics g) JavaDoc
This method is called when the contents of the component should be painted; such
as when the component is first being shown or is damaged and in need
of repair.
In your case, what is likely happening is the call to JOptionPane.showOptionDialog() results in a JDialog showing over your Canvas which triggers another call to paint(). That in turn causes another call to JOptionPane.showOptionDialog() triggering another a call to paint() and so on... This will continue until you get a StackOverflowError or OutOfMemoryError.
In practice, paint() gets called quite frequently so it should be very efficient. Typically only your custom drawing should be done in the paint() method.
Other logic should live in different methods. You should move the logic for your scoring and user interaction outside of the paint() method and leave just the drawing in place.
Edit: Without seeing more of the code I can't give you a specific recommendation of where to move the logic which is not directly concerned with painting. You might find it helpful to review the Java Swing tutorial section on Performing Custom Painting.

It might help to give the JOptionPane your current frame as the first parameter instead of null.

Related

How to make the application to remember the boolean value?

Hi I am trying to add a sort of option window to my application using JOptionPane. If you click yes, a boolean is true. If you click no, a boolean is false and if you click the last button, I want another boolean to say false. And whenever that last button is clicked, I want that window to never be popped up again.
This is my code at the moment.
if (Configuration.LOGIN_MUSIC) {
Object[] options = {"Yes",
"No",
"No, don't ask me again!"};
int n = JOptionPane.showOptionDialog(null,
"Would you like to play the login music?",
"Login music",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);
if (n == 0) {
Configuration.LOGIN_MUSIC = true;
} else if (n == 1){
Configuration.LOGIN_MUSIC = false;
} else {
Configuration.LOGIN_MUSIC_NEVER = true;
Configuration.LOGIN_MUSIC = false;
System.out.println("cancel");
System.out.println(Configuration.LOGIN_MUSIC_NEVER);
}
}
}
public static void main(String args[]) {
try {
if (Configuration.LOGIN_MUSIC_NEVER == false) {
checkForLoginMusic();
}
//System.out.println("The login music has been " + (Configuration.LOGIN_MUSIC ? "enabled" : "disabled"));
nodeID = 10;
portOff = 0;
setHighMem();
signlink.startpriv(InetAddress.getLocalHost());
clientSize = 0;
instance = new Client();
instance.createClientFrame(clientWidth, clientHeight);
//instance = new Jframe(args, clientWidth, clientHeight, false); uncomment if i want to add back the menu bar at top
} catch (Exception exception) {
}
}

drawed image on jpanel can't be showed after adding border, even if it is redrawed

I am trying to make a chess game, to show chess pieces on board, I made a main JPanel which has a gridlayout containing every tiles which are all JPanels too. I then draw pieces on the board using this function:
public void drawPiece(Graphics g) {
try {
g.drawImage(ImageIO.read(Queen.class.getResource(path)), 18, 10, 75, 90, null);
} catch (IOException e) {
e.printStackTrace();
}
g.dispose();
}
This works fine, the problem I am having comes when I try to set a border on the JPanel in which there is already a piece. I have a color code to put borders on tiles to show illegal moves, kill moves and normal moves when a piece is selected. When I place a border where there is a chess piece, then the image dissapears and even if I draw it again right after adding the border, it doesnt show.
For a solution I tried placing a second JPanel on top of my tile panel, which I called graphicsPanel, this panel is where I now draw my chess piece, and then I change the border of the tile containing the panel where the image is and this didn't fix anything, the problem stays the same.
I am out of ideas and don't know how to fix it, so if anyone can help me, that would be great, thank you!
public void mouseClicked(MouseEvent e) {
Tile tile = (Tile) e.getSource();
ArrayList<Point> possibleMoves = new ArrayList<Point>();
if(tile.piece != null) {
switch(currentTurn) {
case white:{
for(Piece current: this.white.pieceList) {
if(current.x + current.y * 8 == tile.number) {
if(current.isSelected == false) {
current.isSelected = true;
possibleMoves = current.possibleMoves();
for(Point currentPoint: possibleMoves) {
if(board.tileList.get(currentPoint.x + currentPoint.y * 8).piece == null) {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(legalMoveBorder);
}else if(board.tileList.get(currentPoint.x + currentPoint.y * 8).piece.color == 'b') {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(killBorder);
}else {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(illegalMoveBorder);
}
}
}else {
current.isSelected = false;
board.removeAllBorders();
}
break;
}
}
}
case black:{
for(Piece current: this.black.pieceList) {
if(current.x + current.y * 8 == tile.number) {
if(current.isSelected == false) {
current.isSelected = true;
possibleMoves = current.possibleMoves();
for(Point currentPoint: possibleMoves) {
if(board.tileList.get(currentPoint.x + currentPoint.y * 8).piece == null) {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(legalMoveBorder);
}else if(board.tileList.get(currentPoint.x + currentPoint.y * 8).piece.color == 'w') {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(killBorder);
}else {
board.tileList.get(currentPoint.x + currentPoint.y * 8).setBorder(illegalMoveBorder);
}
}
}else {
current.isSelected = false;
board.removeAllBorders();
}
break;
}
}
}
}
}
}
This the code where I add borders and removes borders when piece gets either selected or stop being selected.
If anyone can help me, thanks a lot!

Java pong ball not moving in the other direction when hitting the paddle

i am trying to make the game Pong in Java. Now i have a problem with the collision on the paddle. It is not moving the other direction. It does work when it hits the sides of the panel.
For now i just needs to go the other way when it hits the X value of the paddle.
I made a function to check the collision.
What am i doing wrong here. Can someone please explain me this?
Thanks in advance
public void checkCollision()
{
if (ball.getY() == 0)
{
moveDown = true;
moveUp = false;
}
if ((ball.getY() + ball.getHeight()) == height)
{
moveDown = false;
moveUp = true;
}
if (ball.getX() == computer.getX())
{
moveRight = false;
moveLeft = true;
}
}
class TimerHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (counter == 0)
{
Random rand = new Random();
int random = rand.nextInt(2) + 1 ;
if (random == 1)
{
moveUp = true;
moveRight = true;
counter++;
}
else if (random == 2)
{
moveDown = true;
moveLeft = true;
counter++;
}
}
controlMovement();
checkCollision();
repaint();
}
}
I believe that your checkCollision function is incomplete... somehow, the function must have access to both paddle current positions to check if the ball hits one of the paddles...
Another suggestion is to use only one flag to indicante the movement in one axis, for example, boolean monvingUp = true indicantes that the ball is moving up at the Y-axis, when false, such flag indicates that is moving down at the Y-axis...
I changed the = to > and it fixed the problem

MineCraft Forge How to stop mobs from being invulnerable after hit (Java) 1.10.2

I have made a custom bow that fires really quickly, and I have learned that all mobs are invulnerable for a short period of time after they get hit. This renders my bow pretty much useless. I was wondering if there is any way to change the duration that the mobs are invulnerable for, or even remove it at all.
Code for bow firing method:
#Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
// int charge = 1;
// charge = ForgeEventFactory.onArrowLoose(stack, worldIn, playerIn, charge, true);
player123 = playerIn;
if (!worldIn.isRemote) {
final ItemArrow itemArrow = (ItemArrow) (Items.ARROW instanceof ItemArrow ? Items.ARROW : Items.ARROW);
final ItemStack ammo = new ItemStack(Items.ARROW, 1);
final float arrowVelocity = 1;
final EntityArrow entityArrow = itemArrow.createArrow(worldIn, ammo, playerIn);
entityArrow.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYawHead, 0.0F, arrowVelocity * 3.5F, 0F);
entityArrow.setDamage(2);
entityArrow.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
// entityArrow.setVelocity(0.2F, 0.1F, 0.2F);
final ItemStack magicarrow = new ItemStack(TheGalaxyMod.magicarrow, 1);
EntityLivingBase living = (playerIn);
if (FastMode.fastmode == 1){
int index = GetItemSlot(playerIn, magicarrow);
if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
{
entityArrow.setDamage(5000);
worldIn.spawnEntityInWorld(entityArrow);
}
else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
{
worldIn.spawnEntityInWorld(entityArrow);
}
else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
{
damageItem(playerIn, magicarrow, 1);
worldIn.spawnEntityInWorld(entityArrow);
ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
if(stack2.getItemDamage() > 500)
{
playerIn.inventory.setInventorySlotContents(index, null);
}
}
else if(playerIn.inventory.hasItemStack(ammo) ){
worldIn.spawnEntityInWorld(entityArrow);
removeItem(playerIn, ammo);
}
}
else if
(FastMode.fastmode == 2)
{
final ItemArrow itemArrow2 = (ItemArrow) (Items.ARROW instanceof ItemArrow ? Items.ARROW : Items.ARROW);
final ItemStack ammo2 = new ItemStack(Items.ARROW);
final float arrowVelocity2 = 1;
final EntityArrow entityArrow2 = itemArrow2.createArrow(worldIn, ammo2, playerIn);
entityArrow2.setAim(playerIn, playerIn.rotationPitch, playerIn.rotationYawHead, 0.0F, arrowVelocity2 * 3.5F, 0F);
entityArrow2.setDamage(2);
entityArrow2.pickupStatus = EntityArrow.PickupStatus.DISALLOWED;
int index = GetItemSlot(playerIn, magicarrow);
if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
{
entityArrow.setDamage(5000);
worldIn.spawnEntityInWorld(entityArrow);
entityArrow2.setDamage(5000);
worldIn.spawnEntityInWorld(entityArrow2);
}
else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
{
worldIn.spawnEntityInWorld(entityArrow);
worldIn.spawnEntityInWorld(entityArrow2);
}
else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
{
damageItem(playerIn, magicarrow, 2);
worldIn.spawnEntityInWorld(entityArrow);
worldIn.spawnEntityInWorld(entityArrow2);
ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
if(stack2.getItemDamage() > 500)
{
playerIn.inventory.setInventorySlotContents(index, null);
}
}
else if(playerIn.inventory.hasItemStack(ammo) ){
worldIn.spawnEntityInWorld(entityArrow);
worldIn.spawnEntityInWorld(entityArrow2);
removeItem(playerIn, ammo);
}
}
else if
(FastMode.fastmode == 3)
{
entityArrow.setFire(50);
int index = GetItemSlot(playerIn, magicarrow);
if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.creativequiver)))
{
entityArrow.setDamage(5000);
worldIn.spawnEntityInWorld(entityArrow);
}
else if (playerIn.inventory.hasItemStack(new ItemStack(TheGalaxyMod.magicquiver)))
{
worldIn.spawnEntityInWorld(entityArrow);
}
else if (!(playerIn.inventory.getStackInSlot(index).getItem() == null) && playerIn.inventory.getStackInSlot(index).getItem() == TheGalaxyMod.magicarrow)
{
damageItem(playerIn, magicarrow, 2);
worldIn.spawnEntityInWorld(entityArrow);
ItemStack stack2 = playerIn.inventory.getStackInSlot(index);
if(stack2.getItemDamage() > 500)
{
playerIn.inventory.setInventorySlotContents(index, null);
}
}
else if(playerIn.inventory.hasItemStack(ammo) ){
worldIn.spawnEntityInWorld(entityArrow);
removeItem(playerIn, ammo);
}
}
}
return super.onItemRightClick(stack, worldIn, playerIn, hand);
}
EDIT:
Solution Found:
Thanks to #Draco18s I have figured out the solution.
All I had to do was add the line
entityArrow.hurtResistantTime = 0
You need this:
entityHit.hurtResistantTime = 0;
Note: exact field name may change depending on Minecraft version and the build number of Forge.
Call it either just before you hurt the entity (bypassing the hurt resistance timers inflicted by all other sources of damage) or after (your damage is ignored if there's a timer, but if it inflicts damage, the next source is not ignored due to the timer). This line needs to be in the arrow class. If you don't have a custom arrow class, now's a good time to make one.
There's no (good) way to conditionally set the timer to 0 based on what the prior damage type was, unfortunately. If you are on 1.10 or newer, you could use capabilities, although possibly unwieldy.

how do I make this run constructor work right?

I have the following code:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class TTT extends JFrame implements ActionListener { //DO NOT TOUCH!!!
//makes the array for the buttons
JButton spots[ ] = new JButton[ 9];
//keeps track of who's turn it is
int turn = 0;
//lets it go again
boolean go = true;
//gets the images for the X's and O's
ImageIcon red = new ImageIcon("x.PNG");
ImageIcon blue = new ImageIcon("o.PNG");
ImageIcon blank = new ImageIcon("blank.PNG");
public static void main (String []args ) {
TTT frame = new TTT(); //DO NOT TOUCH!!!
frame.setVisible(true);
}
public TTT( ) { //DO NOT TOUCH!!!
//set the frame default properties
setTitle ("Tic Tac Toe");
setSize ( 308, 308 );
setLocationRelativeTo ( null );
setResizable(false);
//register 'Exit upon closing' as a default close operation
setDefaultCloseOperation( EXIT_ON_CLOSE );
changeBkColor( );
}
private void changeBkColor() {
while (go) {
//declares some variables that we will use later
int newLine = 0;
int lineCount = 0;
//change background color to white
Container contentPane = getContentPane();
contentPane.setBackground(Color.WHITE);
contentPane.setLayout(null);
//puts the buttons on the screen
for (int i = 0; i < spots.length; i++) {
//make it first appear as a blank image
spots[ i] = new JButton (blank);
//checks if it needs a new row
if (i == 3 || i == 6) {
newLine++;
lineCount = 0;
}
//sets the positions of the buttons
spots[ i].setBounds(lineCount*100, newLine*100, 100, 100);
//add it to the container
contentPane.add(spots[ i]);
spots[ i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*** Line 62 ***/ public void run() {
//check button pressed
for (int i = 0; i < spots.length; i++) {
if(e.getSource()==spots[ i]) {
//check turn
if (turn%2==0) {
spots[ i].setIcon(red);
} else {
spots[ i].setIcon(blue);
}
//disable the button so it can't be re-pressed
spots[ i].removeActionListener(this);
}
}
turn++;
//checks for wins
for(int i = 0; i < 3; i++) {
if (spots[ i].getIcon()==red && //checks for verticle x win
spots[ i+3].getIcon()==red &&
spots[ i+6].getIcon()==red) {
int again1 = JOptionPane.showConfirmDialog(null, "X Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again1 == JOptionPane.YES_OPTION) {
go = true;
} if (again1 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}else if (spots[ i].getIcon()==blue && //checks for verticle o win
spots[ i+3].getIcon()==blue &&
spots[ i+6].getIcon()==blue) {
int again2 = JOptionPane.showConfirmDialog(null, "O Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again2 == JOptionPane.YES_OPTION) {
go = true;
} if (again2 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}else if (spots[ i*3].getIcon()==red && //checks for horizontal x win
spots[ (i*3)+1].getIcon()==red &&
spots[ (i*3)+2].getIcon()==red) {
int again3 = JOptionPane.showConfirmDialog(null, "X Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again3 == JOptionPane.YES_OPTION) {
go = true;
} if (again3 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}else if (spots[ i*3].getIcon()==blue && //checks for horizontal o win
spots[ (i*3)+1].getIcon()==blue &&
spots[ (i*3)+2].getIcon()==blue) {
int again4 = JOptionPane.showConfirmDialog(null, "O Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again4 == JOptionPane.YES_OPTION) {
go = true;
} if (again4 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}else if (spots[ i].getIcon()==red && //checks for diagnol x win
spots[ 4].getIcon()==red &&
spots[ 8-i].getIcon()==red) {
int again5 = JOptionPane.showConfirmDialog(null, "X Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again5 == JOptionPane.YES_OPTION) {
go = true;
} if (again5 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}else if (spots[ i].getIcon()==blue && //checks for diagnol o win
spots[ 4].getIcon()==blue &&
spots[ 8-i].getIcon()==blue) {
int again6 = JOptionPane.showConfirmDialog(null, "O Wins! Do you want to play again?", "Play again?", JOptionPane.YES_NO_OPTION);
if (again6 == JOptionPane.YES_OPTION) {
go = true;
} if (again6 == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Okay then. Bye!");
go = false;
}
}
}
lineCount++;
}
}
});
}
} if (!go) {
System.exit(0);
}
}
}
my compile hates line 62 - public void run() { - and I need help fixing it. I copied and pasted the line for an already-working program, so I don't know how it doesn't work.
EDIT
sorry guys, here's my errors:
TTT.java:62: error: illegal start of expression
public void run() {
^
TTT.java:62: error: illegal start of expression
public void run() {
^
TTT.java:62: error: ';' expected
public void run() {
^
It appears that you have defined a method within another method declaration, namely run() within actionPerformed(ActionEvent e).
This is not allowed in Java.
It also appears that you have a misunderstanding about the declaration of static void run() this is not a constructor; it is a method declaration with a return type of void.
changeBkColor is an infinite loop so after the constructor is called frame.setVisible(true) is never called. Might be an issue.

Categories

Resources