Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    From a method in the GamePanel class call it like this: show();

    From in a method in another class you need a reference to the GamePanel class. For example:
    refToGamePanel.show();
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    Originally Posted by tonynsx
    so how do I call it? I'm out of ideas, everything else is working.
    i did a system.out.println on the playerWin(), and it's not showing anything then either, so I guess that's the beginning of the problem.
  4. #18
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    If you don't call the methods, they are not executed.
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    Originally Posted by tonynsx
    i did a system.out.println on the playerWin(), and it's not showing anything then either, so I guess that's the beginning of the problem.
    I called playerWin() function inside show() function
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    Originally Posted by tonynsx
    I called playerWin() function inside show() function
    as far as I know, the playerWin() function doesn't work, so it can't decide who wins the game, so that must be why the show() function doesn't work either.
  10. #21
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    What does "doesn't work" mean?
    Does the method execute?
    Is the results wrong?
    Are there execution errors?


    I called playerWin() function inside show() function
    I don't see it in the posted code.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    I called the playerWin() and show() in the main method, now the label is working, but it shows the computer winning even though player won the game.


    Code:
    package tictactoe;
    
    import javax.swing.JFrame;
    
    public class Tictactoe {
    
        public static void main(String[] args) {
            
            JFrame frame = new JFrame("Tic Tac Toe");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gamePanel game = new gamePanel();
            game.playerWin();
            game.show();
            frame.getContentPane().add(game);
            frame.pack();
            frame.setVisible(true);
            
        }
    }
  14. #23
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    is my syntax for the if statements correct, because I used the equals() method before, I was having this same problem before.

    how do I compare two strings using the equals()?
  16. #24
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Here is the syntax for calling a method and passing it a reference to another object:
    classRef1.method(classRef2)

    classRef1 is a reference to an instance of a class
    method is the name of a method. for example: equals
    classRef2 is a reference to an instance of a class

    If the method returns a value, then it should be saved or used in if statement if it returns a boolean value
    varRef = classRef1.method(classRef2); // save value returned in a variable
    or
    if(classRef1.method(classRef2)) { // test the boolean value that is returned
  18. #25
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    78
    Rep Power
    1
    thanks sir for your help so far, I"ll try it later
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo