This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

displaying problem

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to display a 3X3 grid for a tictactoe game, here's the code so far:



This program actually compiles, but for some reason it won't display anything when I run the program? Any help would be appreciated. Thanks.

Savanna
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing here that will ever call "display()". You could override the paint(Graphics) method of Applet and call it there:



That will get you started.

The next problem you're likely to face is that the dimensions of the board aren't based on those of the applet, so probably you'll only see part of the board. Instead of the sizes being fixed in Board, the Board should get the sizes from the applet, either as constructor arguments, or by being made into a Component itself, added to the applet, which would have its own coordinates.
 
Savanna Ray
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying, Ernest!

I tried adding the paint method, tictac.display(g), but nothing appeared on the display. The "dos" window shows a 'NullPointerException' at Board.display line 63. Maybe there's a problem in passing the values to the draw method?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!