A question about Netbeans GUI

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about Netbeans GUI

boz_boz
I'm still fairly new to Netbeans (and Java in general), so this may be a silly question, but...

I'm working on a project to write a Java application with GUI which can read/write data to a SQL database. I've written the methods to run the SQL queries from Netbeans, so that's fine. I'm having a problem with the GUI part - my understanding is that I should be able to setup the GUI class to "extend" to the other class (BookQueries , which contains all the SQL queries already). And once that's done, I can just apply each of the methods in the BookQueries class to the JButtonActionPerformed methods in the GUI.

Problem is, when I build a GUI in Netbeans, it already has an "extends" built in, so I can't add my own one:

public class MyGUI extends javax.swing.JFrame

This seems to be a preset extend for Netbeans, and if I try to remove it, it causes an error. Is there any way to build the GUI in Netbeans without this extends already built-in?  Or am I just misunderstanding this?




Reply | Threaded
Open this post in threaded view
|

Re: A question about Netbeans GUI

Thomas Wolf-7
You need to go to the Oracle web site and find a tutorial on Java “Swing” GUI.  Your question really has nothing to do with Netbeans.  Netbeans just generates some source code for you that you’re expected to add/modify using your Swing.

The method actionPerformed() is a method of an ActionListener interface you define in a class that you then pass to a JButton through its addActionListener() method so that when the button is clicked, your actionPerformed() method is called.  None of this will make any sense to you until you’ve gone through a tutorial and possess some basic knowledge.

Best of luck,
Tom

> On Nov 20, 2017, at 4:30 PM, boz_boz <[hidden email]> wrote:
>
> I'm still fairly new to Netbeans (and Java in general), so this may be a silly question, but...
>
> I'm working on a project to write a Java application with GUI which can read/write data to a SQL database. I've written the methods to run the SQL queries from Netbeans, so that's fine. I'm having a problem with the GUI part - my understanding is that I should be able to setup the GUI class to "extend" to the other class (BookQueries , which contains all the SQL queries already). And once that's done, I can just apply each of the methods in the BookQueries class to the JButtonActionPerformed methods in the GUI.
>
> Problem is, when I build a GUI in Netbeans, it already has an "extends" built in, so I can't add my own one:
>
> public class MyGUI extends javax.swing.JFrame
>
> This seems to be a preset extend for Netbeans, and if I try to remove it, it causes an error. Is there any way to build the GUI in Netbeans without this extends already built-in?  Or am I just misunderstanding this?
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: A question about Netbeans GUI

markwade
In reply to this post by boz_boz
You can kind of do what you want, sort of.  You can add your own
components to the palette or just drag them to the GUI form, a bit
easier. Probably easiest to create a new JPanel Form with the wizard and
name it BookQueries.  You can then drag that class to a JFrame form.

In other words, use the wizard to generate a JPanel form to create
BookQueries rather than create it as a plain Java class. Since you have
the work done already just copy and paste the methods from your existing
BookQueries to the new one and remove the existing.

You can't just extend javax.swing.JPanel because you need the form
generated by NetBeans to be able to work with it in the GUI designer.

You don't need to do it that way though. You can just instantiate an
instance of your existing implementation of BookQueries and call its
appropriate method when a particular button is clicked, although I kind
of like the idea of creating it as a GUI component and using it that way.


On 11/20/2017 04:30 PM, boz_boz wrote:

> I'm still fairly new to Netbeans (and Java in general), so this may be a silly question, but...
>
> I'm working on a project to write a Java application with GUI which can read/write data to a SQL database. I've written the methods to run the SQL queries from Netbeans, so that's fine. I'm having a problem with the GUI part - my understanding is that I should be able to setup the GUI class to "extend" to the other class (BookQueries , which contains all the SQL queries already). And once that's done, I can just apply each of the methods in the BookQueries class to the JButtonActionPerformed methods in the GUI.
>
> Problem is, when I build a GUI in Netbeans, it already has an "extends" built in, so I can't add my own one:
>
> public class MyGUI extends javax.swing.JFrame
>
> This seems to be a preset extend for Netbeans, and if I try to remove it, it causes an error. Is there any way to build the GUI in Netbeans without this extends already built-in?  Or am I just misunderstanding this?
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: A question about Netbeans GUI

markwade
I was thinking about this and it seems to me to be much easier than I
thought.  It seems you can do just what you described. You've created a
BookQueries class, have it extend javax.swing.JFrame, then create a
JFrame form with the wizard and design the GUI, then just change the
extends from javax.swing.JFrame to BookQueries.  As long as the methods
are public, or protected if they're in the same package, you'll be able
to call them from  JButtonActionPerformed events.

Works here.


On 11/27/2017 12:21 PM, Mark Wade wrote:

> You can kind of do what you want, sort of.  You can add your own
> components to the palette or just drag them to the GUI form, a bit
> easier. Probably easiest to create a new JPanel Form with the wizard
> and name it BookQueries.  You can then drag that class to a JFrame form.
>
> In other words, use the wizard to generate a JPanel form to create
> BookQueries rather than create it as a plain Java class. Since you
> have the work done already just copy and paste the methods from your
> existing BookQueries to the new one and remove the existing.
>
> You can't just extend javax.swing.JPanel because you need the form
> generated by NetBeans to be able to work with it in the GUI designer.
>
> You don't need to do it that way though. You can just instantiate an
> instance of your existing implementation of BookQueries and call its
> appropriate method when a particular button is clicked, although I
> kind of like the idea of creating it as a GUI component and using it
> that way.
>
>
> On 11/20/2017 04:30 PM, boz_boz wrote:
>> I'm still fairly new to Netbeans (and Java in general), so this may
>> be a silly question, but...
>>
>> I'm working on a project to write a Java application with GUI which
>> can read/write data to a SQL database. I've written the methods to
>> run the SQL queries from Netbeans, so that's fine. I'm having a
>> problem with the GUI part - my understanding is that I should be able
>> to setup the GUI class to "extend" to the other class (BookQueries ,
>> which contains all the SQL queries already). And once that's done, I
>> can just apply each of the methods in the BookQueries class to the
>> JButtonActionPerformed methods in the GUI.
>>
>> Problem is, when I build a GUI in Netbeans, it already has an
>> "extends" built in, so I can't add my own one:
>>
>> public class MyGUI extends javax.swing.JFrame
>>
>> This seems to be a preset extend for Netbeans, and if I try to remove
>> it, it causes an error. Is there any way to build the GUI in Netbeans
>> without this extends already built-in?  Or am I just misunderstanding
>> this?
>>
>>
>>
>>
>>
>