• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking if user input matches any number in the same column  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My eventhandler

Program is 10x10 board, I need to check if the user's input is a duplicate of any number in that same column, but I can't figure it out. When I tried it, it always check the same box. For example, if I entered 4 in [1][1] (going by 10x10 grid), it automatically checks right after I entered that [1][1] is the same as my input and erases it. My professor wants me to check it with the "CheckWinner" method.

I tried the following when someone told me to pass the reference of the JButton being clicked to ignore it.

Discussion with previous person who tried to help, but was unable to help me.
What do I change " for (int i=0; i<=9; i++){ for (int j=0; j<=9; j++)" to? When I tried entering the same number in a different row and column, it says copy. – user3296002 56 mins ago

I would imagine you need to figure out which column the original button is in and only use that as the column value for your check – MadProgrammer 47 mins ago

I tried EventBoard[0][j], to check the first column only, but when I entered same number on the same row, it says copy. Also, when it says copy, it erases the number that was previously entered, not the one that was just entered. – user3296002 43 mins ago

But what column does the original button reside in? This is the important part. From your code, it's difficult to know if its [col][row] or [row][col]... – MadProgrammer 41 mins ago

I just checked, it's [col][row]. – user3296002 33 mins ago
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your checkWinner method looks a little strange. You initialise count and count2 to zero at the start and only return true when they both equal 10, but you never actually change the value of those variables.
If you want to avoid erasing the selected box then you need to pass the coordinates of that box to the checkWinner method and have an extra check that i and j don't match those coordinates.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!