aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes board not Drawing... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "board not Drawing..." Watch "board not Drawing..." New topic
Author

board not Drawing...

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
for some reason, when I am calling "InitializeBoard(g)" and
reDrawBoard(g), It's not painting to the JPanel...

is there something I am missing?

code is below...








thanks,


Justin


You down with OOP? Yeah you know me!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
we can't copy/paste/compile/run your code due to the missing classes,
particularly Square.

as your problem is to do with the display, create a sample program revolving
around just adding the one square.

Get rid of everything unrelated to the problem of showing a single square
when the program opens i.e. get rid of the listeners, the methods update/find/redraw etc

include a class Square, again get rid of everything from the square class
if it is not related to its display.

you should now be able to post a very short 'working' program that displays the problem
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok, I fixed the problem...


in my battleship class, in the paintComponent() I have the
following code:



I'm guessing that there is something wrong with me
calling "board = new Board()" when I repaint...

so I just got rid of the "InitializeBoard()" method,
and put that code in the constructor...

and it worked fine.

and when I click on a square, I called a "findSquare" routine
which looks for a square on the board that contains the same
X,Y coords captured by the mouseClicked() in BattleShip class.

then i UpdateBoard, and Color that Square white.

I just have one question regarding my ship objects...

ok:

1. my ship class extends JPanel
- so I can use setEnabled, setToolTipText, etc...
- also I can call this.getX(),this.getY()
- and I can add a Mouse/Action/Key event directly to the
component

ok, here is the question...

My board is drawn using drawRect and such...
what would be a good way to tell if a square on my board
contains a ship object?

should I grab the Point when clicked, and then check that point by
saying:



thanks

Justin
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> should I grab the Point when clicked, and then check that point by
saying:

I'd say it would be the other way around
instead of ship.contains(), it would be board.contains(ship)

try this, click at several places in the panel, then click the ship

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: board not Drawing...