Results 1 to 13 of 13
  1. #1
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default TicTacToe Error Message

    I have my code all set and ready but im getting some errors that i cannot seem to figure out if anyone can lead me into the right direction that would be great here is my code for you guys to see.

    This is one of the errors that comes up.
    F:\TicTacToeGame.java:17: ';' expected
    Private Button ButtonValue1;

    ^
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
          public class TicTacToeGame extends Frame
    
          {
    
          // Declaring the variables
    
         private Button keys[];
    
          private Panel keypad;
    
          private TextField winner, player1, player2;
    
          Private Button ButtonValue1;
          Private Button ButtonValue2;
          Private Button ButtonValue3;
          Private Button ButtonValue4;
          Private Button ButtonValue5;
          Private Button ButtonValue6;
          Private Button ButtonValue7;
          Private Button ButtonValue8;
          Private Button ButtonValue9;
    
    
    
          public TicTacToeGame()
    
          {
    
          // Creating the components of the menu bar.
    
          MenuBar mnuBar = new MenuBar();
    
          setMenuBar(mnuBar);
    
    
    
          // Creating the components of the File menu.
    
          Menu mnuFile = new Menu("File", true);
    
          mnuBar.add(mnuFile);
    
         MenuItem mnuFileExit = new MenuItem("Exit");
    
          mnuFile.add(mnuFileExit);
    
    
    
          // Creating the components of the Edit menu.
    
         Menu mnuEdit = new Menu("Edit", true);
    
          mnuBar.add(mnuEdit);
    
          MenuItem mnuEditClear = new MenuItem("Clear");
    
          mnuEdit.add(mnuEditClear);
    
          mnuEdit.insertSeparator(1);
    
          MenuItem mnuEditCopy = new MenuItem("Copy");
    
          mnuEdit.add(mnuEditCopy);
    
          MenuItem mnuEditPaste = new MenuItem("Paste");
    
          mnuEdit.add(mnuEditPaste);
    
    
    
          // Creating the components of the About menu.
    
          Menu mnuAbout = new Menu("About", true);
    
          mnuBar.add(mnuAbout);
    
          MenuItem mnuAboutCalculator = new MenuItem("About Tic Tac Toe");
    
          mnuAbout.add(mnuAboutCalculator);
    
    
    
          // Creating the components ofthe game board.
    
          keypad = new Panel();
    
          keys = new Button[10];
    
          winner = new TextField("Player ");
    
    
    
          // construction and assigning of the buttons.
    
          for (int i=1; i<=9; i++)
    
          keys[i] = new Button();
    
    
    
          // Constructing the layout.
    
          setLayout(new BorderLayout());
    
          keypad.setLayout(new GridLayout(3,3,1,1));
    
    
    
          // Button assignments and color, buttuns will eventually be replaced by an image when selected.
    
          for (int i=1; i<=3; i++) // The first row.
    
          keypad.add(keys[i]).setBackground(Color.white);
    
    
    
          for (int i=4; i<=6; i++) // The second row.
    
          keypad.add(keys[i]).setBackground(Color.white);
    
    
    
          for (int i=7; i<=9; i++) // The third row.
    
          keypad.add(keys[i]).setBackground(Color.white);
    
    
    
          // determining the location of the keypad and the text field.
    
          setBackground(Color.black); // The back ground color to get that true gride look.
    
          add(keypad, BorderLayout.CENTER);
    
          add(winner, BorderLayout.SOUTH);
    
          }
    
          public static void main(String[] args)
    
          {
    
          TicTacToe f = new TicTacToe();
    
         f.setTitle("Tic Tac Toe");
    
          f.setBounds(400,200,300,300);
    
          f.setVisible(true);
    
          }
    
    
    
          static ButtonValue f = new ButtonValue();
    
    
    
          ButtonValueGroup options = new ButtonValueGroup();
    
    
    
          Value1 = new Button ButtonValue1("",false,options);
    	  Value2 = new Button ButtonValue2("",false,options);
          Value3 = new Button ButtonValue3("",false,options);
    	  Value4 = new Button ButtonValue4("",false,options);
    	  Value5 = new Button ButtonValue5("",false,options);
    	  Value6 = new Button ButtonValue6("",false,options);
    	  Value7 = new Button ButtonValue7("",false,options);
    	  Value8 = new Button ButtonValue8("",false,options);
    	  Value9 = new Button ButtonValue9("",false,options);
    
    
    
          public static String ColorButtons()
    
          {
    
          this.setLayout(new FlowLayout());
    
          add(Button1);
    
          add(Button2);
    
          add(Button3);
    
          add(Button4);
    
          add(Button5);
    
          add(Button6);
    
          add(Button7);
    
          add(Button8);
    
          add(Button9);
    
          Button1.addItemListener(this);
    
          Button2.addItemListener(this);
    
          Button3.addItemListener(this);
    
          Button4.addItemListener(this);
    
          Button5.addItemListener(this);
    
          Button6.addItemListener(this);
    
          Button7.addItemListener(this);
    
          Button8.addItemListener(this);
    
          Button9.addItemListener(this);
    
    
    
          //override windowClosing() allows user to click Close button
    
          addWindowListener(
    
          new WindowAdapter()
    
          {
    
          public void windowClosing(WindowEvent e)
    
          {
    
          System.exit(0);
    
          }
    
          }
    
          );
    
          } //end of construct method
    
    
          public void itemStateChanged(ItemEvent choice)
    
          {
    
          if (Player1.getState()) f.setBackground(JPEG_X);
    
          else if (Player2.getState()) f.setBackground(JPEG_O);
    
    
    
          repaint();
    
          } //end of actionPerformed method
    
    
    
          } //end of class

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    It's "private" not "Private"; pay attention to the case of the keywords, they're all in lowercase.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    Thanks for that..didn't even catch it. Now thats fixed i have another one and this is what it says:

    F:\TicTacToeGame.java:167: <identifier> expected
    Value1 = new Button ButtonValue1("",false,options);
    ^

  4. #4
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    can anyone else figure out the next error that i had ^^^^ i can't.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Ryan10 View Post
    Thanks for that..didn't even catch it. Now thats fixed i have another one and this is what it says:

    F:\TicTacToeGame.java:167: <identifier> expected
    Value1 = new Button ButtonValue1("",false,options);
    ^
    What is that supposed to mean? The 'new' operator needs a constructor from a certain class; you supply a class name and something else; the compiler didn't like it as you have noticed.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    I have 9 total errors: and its saying i need an identifier but i have no clue where i have gone wrong.

    F:\TicTacToe\TicTacToe2.java:177: <identifier> expected
    ButtonValue1 = new ButtonValue1("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:179: <identifier> expected
    ButtonValue2 = new ButtonValue2("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:181: <identifier> expected
    ButtonValue3 = new ButtonValue3("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:183: <identifier> expected
    ButtonValue4 = new ButtonValue4("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:185: <identifier> expected
    ButtonValue5 = new ButtonValue5("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:187: <identifier> expected
    ButtonValue6 = new ButtonValue6("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:189: <identifier> expected
    ButtonValue7 = new ButtonValue7("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:191: <identifier> expected
    ButtonValue8 = new ButtonValue8("",false,options);
    ^
    F:\TicTacToe\TicTacToe2.java:193: <identifier> expected
    ButtonValue9 = new ButtonValue9("",false,options);
    ^
    9 errors

    Tool completed with exit code 1

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    ButtonValue1 (and the others) are variables of type Button. You can create a new Button but you can't create a new variable. Check your text book for the correct syntax; it should be something like:

    Java Code:
    ButtonValue1= new Button( ... );
    And please stick to the accepted naming (and capitalization) conventions; as it is now it is a mess.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    I changed it to this but still getting the same errors...is "",false,options supposed to be there?


    ButtonValue1= new Button("",false,options);
    ButtonValue2= new Button("",false,options);
    ButtonValue3= new Button("",false,options);
    ButtonValue4= new Button("",false,options);
    ButtonValue5= new Button("",false,options);
    ButtonValue6= new Button("",false,options);
    ButtonValue7= new Button("",false,options);
    ButtonValue8= new Button("",false,options);
    ButtonValue9= new Button("",false,options);

    or should i put ButtonValue1= new Button Button1(...)
    Last edited by Ryan10; 03-30-2011 at 04:59 PM.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Ryan10 View Post
    I changed it to this but still getting the same errors...is "",false,options supposed to be there?
    I don't know; it's your code, not mine, you should know what is supposed to be where, not me.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    it still doesnt work either way..

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Ryan10 View Post
    it still doesnt work either way..
    Of course not because it isn't even syntactically correct Java. You can't just type in your guesses and hope that it works; that's not how programming works.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    Ryan10 is offline Senior Member
    Join Date
    Mar 2011
    Posts
    144
    Rep Power
    0

    Default

    im new to java sorry i dont know everything..do you know what im doing wrong? can you point me in the right direction as to what to fix.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Ryan10 View Post
    im new to java sorry i dont know everything..do you know what im doing wrong? can you point me in the right direction as to what to fix.
    I tried to point you to what you are doing wrong but I'm not going to write your code for you for a couple of reasons: 1) I don't know what you want your code is supposed to do and 2) you teacher is not going to grade me.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. TicTacToe error
    By noahwhygodwhy in forum New To Java
    Replies: 3
    Last Post: 03-10-2011, 07:14 PM
  2. error message
    By tri.yudhanto in forum JDBC
    Replies: 0
    Last Post: 01-13-2011, 01:20 PM
  3. Error Message ..
    By Hamodi18 in forum New To Java
    Replies: 15
    Last Post: 07-11-2010, 03:31 AM
  4. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:46 PM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 02:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •