• Post Reply Bookmark Topic Watch Topic
  • New Topic

good way to do action

 
mark smith
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i begin in swing and i would like to do a simple drawing program for my little kid.



that work fine...

now i would like to be able to use a toolbar to draw a shape... when we click on a button...



if i want that work, i will need to a jpanel in the constructor of this objet
i don't know if it's a really good design choice...

maybe my design choice is bad...

any suggestion?

thanks
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is usually the point where you start using (non-static, perhaps anonymous) inner classes. These get an automatic reference to the instance of the outer class which you can use as you please.

This does of course mean that you shouldn't put all your code in the main method. That certainly is bad design in Java.
 
mark smith
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so the only choice is to put innerclass...

if i create a class for the toolbar... and the toolbar call my action...
i will need to pass the jpanel to the toolbar... and the toolbar pass it to my action...
very so so ...

on the web... habitually, i see people create some innerclass...

are there better way to correct that?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!