-1

Running my java code works in debugger but not in run. In the eclipse debugger it shows my jframes.

However when I run it, my frame doesn't appear whatsoever.

I believe I messed up my EventListener and all that.

private class ButtonHandler implements ActionListener{
    JButton button;

    public void actionPerformed(ActionEvent event) {
        find(event.getSource());

        button = buttonHolder[indexK[kCount-1]][indexJ[jCount-1]];

        if((button.getIcon() == red && choice1 == 1) || (button.getIcon() == green && choice1 == 0)){
            JOptionPane.showMessageDialog(null, "You chose the wrong color!");
            return;
        }

        if(turn ==1){
            if(clicks != 1){
                if(button.getIcon() == red){
                    clicks++;
                    temp = button;
                }else if (button.getIcon() == green){
                    clicks++;
                    temp = button;
                }else{
                    kCount=0;
                    jCount=0;
                }
            }else{
                if((button.getIcon() == green) ||  (button.getIcon() == red)){
                    //do nothing
                }else if(temp.getIcon() == green && (grid[indexK[1]][indexJ[1]] == 2 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 4) && button.getIcon() != green && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]-1 == indexJ[1])) ){
                    temp.setIcon(null);
                    button.setIcon(green);
                    grid[indexK[1]][indexJ[1]] = 2;

                    if(indexK[0] == 0 || indexK[0]== 9){
                        grid[indexK[0]][indexJ[0]] = 4;
                    }else{
                        grid[indexK[0]][indexJ[0]] =3;
                    }
                    found = 2;

                }else if(temp.getIcon() == red && (grid[indexK[1]][indexJ[1]] == 1 || grid[indexK[1]][indexJ[1]] == 3 || grid[indexK[1]][indexJ[1]] == 5) && button.getIcon() != red && ((indexK[0]+1 ==indexK[1] && indexJ[0] == indexJ[1]) || (indexK[0] ==indexK[1] && indexJ[0]+1 == indexJ[1]) || (indexK[0]-1 ==indexK[1] && indexJ[0] == indexJ[1]))){
                    temp.setIcon(null);
                    button.setIcon(red);
                    grid[indexK[1]][indexJ[1]] = 1;

                    if(indexJ[0] == 0 || indexJ[0]== 9){
                        grid[indexK[0]][indexJ[0]] = 5;
                    }else{
                        grid[indexK[0]][indexJ[0]] =3;
                    }
                    found = 2;
                }

                clicks=0;
                kCount=0;
                jCount=0;
            }

        }
    }

}

}

if you don't see any problems, can you think of a reason why it might be messing up?

oers
  • 18,436
  • 13
  • 66
  • 75
Kelsey Abreu
  • 1,094
  • 3
  • 17
  • 42

1 Answers1

0

First, double check that you're running it in the same mode. A program made for Applet mode is not the same as Application.

If that doesn't work:

If running as an Applet: Check that you have an init function.

If running as an Application: Check that you define a main class in your run configuration. If you did, make sure you are running a main() method within it.

Sean
  • 254
  • 2
  • 10