• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBeans question  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Builder tools like NetBeans , JBuilder etc generate code of the form
'Button button1 = new Button();'
when a Button object is dragged and dropped onto the Form Designer.
I have a custom Button object called 'MyButton' and another related class called 'MyField'; now i want that whenever a 'MyButton' object is dragged and dropped onto the designer - another object should be created of type 'MyField' - AND IT SHOULD BE VISIBLE IN THE CODE GENERATED.
In other words, the code should contain the following statements :

'MyButton myButton1 = new MyButton();'
'MyField myField1 = new MyField().'
Can anyone tell me how this can be done.
Thanks and Regards
Vikas
 
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking how to modify what the tool generates for code?
Or are you asking how to tweak the code after it has been generated?
Or are you asking something comepletely different?
 
Vikas Manghani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a way i want to modify what the tool generates.
When the application programmer drags and drops 'MyButton' onto a Frame(say) the tool would generate code for the component. Now i want that in addition code should also be generated for creating an instance of 'MyField'. that is the code behind in the editor should contain the following lines.
'MyButton myButton1 = new MyButton();'
'MyField myField1 = new MyField();'
This code would then be run at runtime when the Frame is instantiated. here 'myButton1' and 'myField1' are instance variables of the Frame class.
Thanks
Vikas
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to do a lot of this in a previous job. Every tool is different. We used JBuilder. Basically you want to make a new button class MyButton derived from JButton with the extra stuff you want in it. Then you make bean customizers for it, make little icon images and load it into the JBuilder toolbar. You need to follow the example in a good book like Y. Daniel Liang Rapid Java app dev using Jbuilder 3. Yeah, I know it is old but nothing has changed. The JBuilder help shows how to add the new component you make to the pallete. Good luck.
 
Vikas Manghani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could u possibly post some code of how to create another instance in the designer on the fly. or atleast guide me on wot areas of the Bean API to investigate (e.g. BeanContext, etc.)
I dont think i will have access to the book for some time atleast.
Thanks
Vikas
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!