Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

TicTacToe Game

 
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;






 
Rancher
Posts: 43016
76
  • 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: 43016
76
  • 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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic