Results 1 to 13 of 13
Thread: TicTacToe Error Message
- 03-30-2011, 03:40 PM #1
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
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
- 03-30-2011, 03:42 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
It's "private" not "Private"; pay attention to the case of the keywords, they're all in lowercase.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-30-2011, 03:47 PM #3
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
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);
^
- 03-30-2011, 04:05 PM #4
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
can anyone else figure out the next error that i had ^^^^ i can't.
- 03-30-2011, 04:38 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-30-2011, 04:45 PM #6
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
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
- 03-30-2011, 04:50 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
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:
And please stick to the accepted naming (and capitalization) conventions; as it is now it is a mess.Java Code:ButtonValue1= new Button( ... );
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-30-2011, 04:56 PM #8
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
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.
- 03-30-2011, 05:05 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
- 03-30-2011, 05:06 PM #10
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
it still doesnt work either way..
- 03-30-2011, 05:08 PM #11
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
- 03-30-2011, 05:09 PM #12
Senior Member
- Join Date
- Mar 2011
- Posts
- 144
- Rep Power
- 0
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.
- 03-30-2011, 05:51 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,407
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
TicTacToe error
By noahwhygodwhy in forum New To JavaReplies: 3Last Post: 03-10-2011, 07:14 PM -
error message
By tri.yudhanto in forum JDBCReplies: 0Last Post: 01-13-2011, 01:20 PM -
Error Message ..
By Hamodi18 in forum New To JavaReplies: 15Last Post: 07-11-2010, 03:31 AM -
Error Message????
By Cubba27 in forum New To JavaReplies: 11Last Post: 11-21-2009, 02:46 PM -
error message on jsp
By sandor in forum Web FrameworksReplies: 1Last Post: 04-11-2007, 02:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks