• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TicTacToe Game

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;






 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic