wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Custom JComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom JComponent" Watch "Custom JComponent" New topic
Author

Custom JComponent

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
ok i have a Battle ship game im doing,

and i want each ship be a separate Component...

so i can add mouse listeners to them

ive extended JComponent and Component...

and when i do

ship BS = new Ship() // ship extends Component..

this should create an instance of ship with Component attributes right??

please help, what when i do the following:

if(e.getSource == BS)
{
// do something
}


nothing happens..

Justin


my code...




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

Joined: Jun 09, 2003
Posts: 4632
here's a starter, needs a bit more work to get the coords correct.
(have something else to do at present)

Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
sweet man, i knew i was on the right track..

just about 3/4 of a mile off : )

thanks,

Justin
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
some changes to get the coords right

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Custom JComponent
 
Similar Threads
TriState CheckBox
Help 3
: A gray color box appeare d when loading an image on JPanel
GUI
how to paint some shape over another JComponent