Reputation: 341
I have successfully created a Java class that provides database connectivity and returns a connection object. I need to use this connection object to
Unfortunately, I am using NetBeans and some auto generated code to build the GUI, and my question is simple:
When you create a class, you need to instantiate it and then call the method. Where do I instantiate this class in my form? Do I do it in the main, since it is the entry point of all programs, or do I do it behind the code for the button. I am a novice so please understand.
When I created the project, I created a main class too, and then I added a form to it. I then created a different project which is a class lib and added that to my project. How do I link the two together?
Upvotes: 2
Views: 262
Reputation: 205875
It sounds like the NetBeans GUI editor is clouding the picture. You can tame it by limiting it's use to a single panel, as shown in this example. The default layout of JFrame
is BorderLayout
, so f.add(new NewJPanel())
has the effect of adding a panel to the CENTER
. You can add other panels, perhaps ones having different layouts, to other areas.
Addendum: Note also that the generated ActionListener
typically calls a method having a signature such as this, where xxx
is the name of the generated control:
private void xxxActionPerformed(java.awt.event.ActionEvent evt) {}
These methods are inside the class but outside the generated code fold, so they may be edited as required.
Upvotes: 1