File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom JComponent
 
Similar Threads
TriState CheckBox
GUI
Help 3
: A gray color box appeare d when loading an image on JPanel
how to paint some shape over another JComponent