"(" Expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bugmenot2
    Banned
    New Member
    • Apr 2008
    • 7

    "(" Expected

    Hi, i have a problem with my program not compiling. It says "(" Expected on line 31, when there is in fact a bracket there.

    Thanks in advance.





    import java.awt.*;
    import javax.swing.*;
    import java.awt.event. *;

    public class TicTacToe extends JFrame implements ActionListener {
    JButton[][] x = new JButton[3][3];
    int[][] a = new int[3][3];
    int turn;


    public static void main(String[] args) {
    TicTacToe f = new TicTacToe();
    f.setSize(500,5 00); f.setVisible(tr ue);
    f.setDefaultClo seOperation(JFr ame.EXIT_ON_CLO SE);
    }
    public TicTacToe(){
    setLayout(new GridLayout(3,3) );

    for (int r = 0; r < 3; r++){
    for (int c = 0; c < 3; c++){
    x[r][c] = new JButton();
    add(x[r][c]);
    x[r][c].addActionListe ner(this);
    }
    }
    }
    public void actionPerformed (ActionEvent e){
    for (int r = 0; r < 10; r++){
    for(int c = 0; c < 10; c++){
    if (e.getSource()= = x[r][c]){
    if turn == 0{
    x[r][c].setText("O");
    turn = 1;
    }
    else {
    x[r][c].setText("X");
    turn = 0;
    }

    }
    }
    }
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    I counted those lines for you and found this:

    [code=java]
    if turn == 0{
    [/code]

    That isn't syntactically correct; make it like this:

    [code=java]
    if (turn == 0) {
    [/code]

    to keep the compile from whining at you.

    kind regards,

    Jos

    ps. next time show us the text of the line the compiler is complaining about and
    put code tags around your code (look at the pane to the right of the little form
    where you enter your post text).

    Comment

    • bugmenot2
      Banned
      New Member
      • Apr 2008
      • 7

      #3
      Thanks very much! =)

      Comment

      Working...