Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to mix Netbeans with manually generated code  RSS feed

 
Ranch Hand
Posts: 132
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello what i want to know is how i can use manully generated code e.g.


if i was writing this by hand i would simply use something along the lines of jPanel1.add(B1);
to put the button on the panel

but how do i do this in netbeans which i am using to do lots of the design layout managers etc


 
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to stop you doing that Peter - have you tried it?
 
Bartender
Posts: 19976
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why my signature has been "An IDE is no substitute for an Intelligent Developer.".

When IDE "wizards" generate code, the developer often never properly learns what the code is for and cannot extend or maintain it.

You apparently do know what the code is for, but are - rightfully - concerned about what happens when you go in and manually muck with code that an automaton has developed.

This is often a problem, since then the wizard and the developer get into a fight, and in worst cases, the wizard may actually damage or remove manually-maintained code.

It has been a long time since I used NetBeans, but I think that they were one of the IDEs whose wizards placed comments into their generated code that tell you where it's safe to put your own stuff and where it isn't.

The other option is to simply stomp on the code and treat it all as your own. Which is generally OK as long as you never plan to go back and maintain anything using the wizards and their dialogs.

Finally, in some cases, the wizard generates an entire module and you're expected to keep hands off it, but the module is designed to interact with modules that you wrote so that both worlds can be safely preserved.

As I said, I haven't worked with NetBeans in quite a while, so which, if any, of the above approaches will help I cannot tell.
 
peter m hayward
Ranch Hand
Posts: 132
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having read time comments i think its about time to stop using the ide and code it like i did a uni
 
John Matthews
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using NetBeans at the moment, and will continue to use it because it's brilliant as a Java code editor - it makes life so much easier.

But while I'm still learning the Java ropes, it also saves a lot of time when designing the form/component layout. In terms of auto-generated code, you can see an example in my post here, 4th one down. NetBean's main contribution is the initComponents() method, whose content is hidden by default in the NetBeans editor. It also generates the main() method, and all the variables at the bottom corresponding to the components I added to the form using the NetBeans form designer.

The generated code is read-only - you can't edit it (using the NetBeans editor). But it's not 'magic' - I personally don't understand all of the layout stuff (yet), but I get the gist of what it's doing and can see that it corresponds to how I designed the form. And you can post it to a forum such as this as an SSCCE - the generated code is just 'ordinary' Java which can be used by other people who don't have NetBeans.

And for a simple project whose code is all in one file, it's fairly easy to convert the code into something you *can* edit. Just start a new Project / Java / Java application, add a new empty file with the same name as the one in the existing project, and copy/paste the existing file's code into it. It will still run within NetBeans, but NetBeans doesn't 'know' about its components - if you want to move a button a bit to the right, you're got to change your handwritten code instead of moving the button in the form designer (which would have changed the generated code).

I'm a fan, in case you hadn't guessed
 
John Matthews
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wrote:The generated code is read-only


Mostly true, but that try/catch in main() which (as you might be able to spot from the code) handles look-and-feel, is optional - you can delete it.
 
peter m hayward
Ranch Hand
Posts: 132
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem with netbeans occasionally  it creates errors i have had situation where removing a component  in design view leaves bits of code or adding a component puts i in the middle of a block of code then all hell breaks loose as you have red marks everywhere I have taken the time and trouble to let them know with example but as yet i have heard nothing!


maybe a better place to start would be BlueJ or greenfoot, as these are very easy to use  there is also eclipse which is another editor similar to netbeans




 
John Matthews
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right - yes, generated code which you can't edit that doesn't compile isn't ideal

I've used Eclipse for C/C++ on previous (work) projects and to be honest I found it a bit overwhelming. Once it was set up, mainly by copying someone else's config file, it was fine. But I would have had a lot of trouble setting it up on my own, and whenever I've tried to use it for personal stuff, I've given up and used something else.

Haven't tried the other 2. But perhaps if your NetBeans problems are caused by the form designer, perhaps you could do something along the lines of my previous post and convert the auto-generated code into something you can edit yourself? Just use the form designer to get you started.
 
John Matthews
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick Google suggests IntelliJ might also be worth a look (another one I haven't tried).
 
peter m hayward
Ranch Hand
Posts: 132
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used blueJ at uni and i learned the basics, netbeans does a lot for you  i agree but at what cost each component has lots of un-necessary code take a jtextfield as an example you may only be using it to display some result or other and yet it has mouse listeners etc



 
Tim Holloway
Bartender
Posts: 19976
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IntelliJ added a desktop GUI designer (for Swing) a number of years ago that I really liked. I write very few desktop GUI apps these days, but it was nice to see it - before that, you had to go all the way back to Borland's Visual Café at the Turn of the Millenium to find a good GUI designer for Java. And hardly anyone remembers Visual Café anymore.

One really great thing about IntelliJ GUI design was that the code it generated was self-sufficient. Visual Café generated code that was highly dependent on proprietary helper classes, and as an author of open-source software that was not tolerable. In fact, I wrote a Perl script that took the Café-generated code and removed the proprietary stuff.
 
peter m hayward
Ranch Hand
Posts: 132
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will look up IntelliJ
tomorrow

thanks for your input
 
John Matthews
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:One really great thing about IntelliJ GUI design was that the code it generated was self-sufficient.


Like NetBeans in that respect.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!