• Post Reply Bookmark Topic Watch Topic
  • New Topic

TicTacToe Game  RSS feed

 
Danny Roberts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, i'm having problems understanding why one class isn't working properly with another. When i run the classes by themselves everything works properly. However, when i run the MainClass(which should initialized the next class which then initialized the next class?) i get a blank screen. Why is this?


TAB 1:

import java.awt.event.MouseListener;

import acm.program.GraphicsProgram;



TAB 2:

import java.awt.event.MouseListener;

import acm.program.GraphicsProgram;


import java.awt.Color;

import acm.graphics.GLine;
import acm.graphics.GOval;
import acm.graphics.GRect;
import acm.program.GraphicsProgram;



TAB 3:


import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import acm.graphics.GOval;
import acm.program.GraphicsProgram;






 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure you can click on it, but if you expect some kind of response then you will have to write a GUI listener to make that happen. It looks as if the ClickToPlayPiece class is meant to do that, but from the code it's not clear whether it is being used - does calling the addMouseListeners method cause the object to be added as listener to the component that receives clicks? Is the mouseClicked method ever actually invoked at runtime? (Add logging to it to find out.)
 
Danny Roberts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The addMouseListeners method automatically calls the mouseClicked method when the mouse is clicked(asynchronous event i think it's called). So i don't think theres anything wrong with the code, it's just like the question i had yesterday in the other thread, why doesn't MainClass initialize the GameBoard class which then should initialize the ClickToPlayPiece class??? They all should work together,no? Because that's the point of OOP if i'm not mistaken?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and I have the same answer as in that thread: that depends on how the GraphicsProgram class is supposed to work, and we have no clue about that. For example, I would guess that it is wrong to have more than one class extend it (as this code here does), but we just don't know.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!