J
jamestechinfo
I've tried to develop several JFrame programs in the past and it
always drives me crazy because I can't figure out how to set Classes
I've developed, which aren't Components, but are critical to storing
information necessary for the program to operate, so that they can be
seen by components inside the frame. I'm not very knowledgable about
the structure and coding of Swing/AWT programs, but I understand the
princepals of passing data between methods and classes, and it is very
frustrating to me that I cannot find an easy way (or even a working
way at this point) to reference the info with my program the way I
need to.
To illustrate my question with a real example, I'm trying to write a
program which allows employees at my job to easily receive products
from deliveries by scanning the barcode on the product or putting in
the supplier code on the invoice.
The program needs to be able to extract product info from the database
(to match the scanned barcode and to give the receiver visual
verification that the info in the system is correct), and it needs to
be able to match the product with the vendor, and thus the vendor
codes, which go with the invoice.
I've connected my first draft/test program to the database using a
class I call dbInfo. This class stores the connection information
specific to our database, and also acts as a container/manager for
other classes which populate arraylists such as VendorList, BrandList,
and lists for any other info which is tied to a primary key in the
database and might change during the use of the program (this way in
the info in the form can be refreshed by simply using one dbInfo
method).
My dbInfo class populates all its info into the appropriate lists
correctly. I cannot, however, get my components to see this info.
For example, I have a VendorBox, which is a JComboBox that selects the
vendor for the invoice.
My original vendorBox grabbed its vendor information directly from the
database by storing its own JDBC info and generating the SQL statement
itself. This worked fine, but is not very modular, I had to add code
to every other component that dealt with this info which would to
reference the specific VendorBox on that JFrame form. If I could get
the components to see the dbInfo for the form, I could just store the
reference to VendorBox as dbInfo.invoiceVendor and any other component
could have easy access to it by simply knowing where dbInfo was.
Long explanations can be hard to read, so here's a basic diagram
------------------------------
JFrame
|
}Components
| }VendorBox ( a ComboBox which selects the
| vendor to receive from )
|
}dbInfo (not a component)
}VendorList
------------------------------
My Question: How to I get VendorBox to see VendorList (or dbInfo for
that matter)?
------------------------------
*Note: I'm using Netbeans 5.5, which doesn't allow me to edit the
component initialisation proccess inline. I think I might be able to
do this using the properties window, but I haven't had any luck
getting this to work*
What I've tried:
Just putting it in based on its name and location:
1) A direct reference - using a setdbInfo() method, which sets the
dbInfo equal to JFrameName.dbInfoVariableName. Netbeans gives me a
variable (or symbol or something of the like) not found.
2) The Netbeans property window - because I have setdbInfo() and
getdbInfo() fields in my VendorBox class, Netbeans shows dbInfo in the
property window. Trying to edit this property gives me a form which
among other things says 'form connection mode' and has options like
'from property' and 'from method'. None of the options have any
options to select within them, which I think is because i need to do
something to set up the form connections, but I'm not sure and my own
personal searches have not presented me with useful information.
At this point I thought I'd try to make a finddbInfo class, which
would just find the dbInfo class by crawling its way out
3) Introspection - When I read the description of this I sighed
relief, I thought it would show me the class that my VendorBox was
inside, but as far as I can tell it only shows you the class
inheritance information. I tried all the getxxx() commands netbeans
offered for code completion, but all I got back was info from the
classes my vendorBox was built on or null.
4) VendorBox.getParent() - combined with introspection, I used this to
progress a Class from displaying info about my vendorBox to info about
its containing panels, when I progressed to the outmost panel,
however, instead of getting the JFrame info on the next entry, I got
null.
At this point I cried, cut myself, and poured the rest of my drink out
for my dead homies.
Please help me, I enjoy using Java because I can work with it quickly,
but I feel like screaming sometimes because I can't pass a simple
piece of info to a component. I've learned so much more than I needed
to and wasted so much valuable time trying to do this and I know in my
heart that there is an easy answer that will make me feel
simultaneously stupid and relieved. I need that feeling like you
wouldn't believe, and I'm sure there our other amateur programers out
there who could benefit greatly by understanding why my methods don't
work.
On that note, if you could even explain why solutions like 1) or 4)
don't work, I think a lot of people could benefit from that info.
always drives me crazy because I can't figure out how to set Classes
I've developed, which aren't Components, but are critical to storing
information necessary for the program to operate, so that they can be
seen by components inside the frame. I'm not very knowledgable about
the structure and coding of Swing/AWT programs, but I understand the
princepals of passing data between methods and classes, and it is very
frustrating to me that I cannot find an easy way (or even a working
way at this point) to reference the info with my program the way I
need to.
To illustrate my question with a real example, I'm trying to write a
program which allows employees at my job to easily receive products
from deliveries by scanning the barcode on the product or putting in
the supplier code on the invoice.
The program needs to be able to extract product info from the database
(to match the scanned barcode and to give the receiver visual
verification that the info in the system is correct), and it needs to
be able to match the product with the vendor, and thus the vendor
codes, which go with the invoice.
I've connected my first draft/test program to the database using a
class I call dbInfo. This class stores the connection information
specific to our database, and also acts as a container/manager for
other classes which populate arraylists such as VendorList, BrandList,
and lists for any other info which is tied to a primary key in the
database and might change during the use of the program (this way in
the info in the form can be refreshed by simply using one dbInfo
method).
My dbInfo class populates all its info into the appropriate lists
correctly. I cannot, however, get my components to see this info.
For example, I have a VendorBox, which is a JComboBox that selects the
vendor for the invoice.
My original vendorBox grabbed its vendor information directly from the
database by storing its own JDBC info and generating the SQL statement
itself. This worked fine, but is not very modular, I had to add code
to every other component that dealt with this info which would to
reference the specific VendorBox on that JFrame form. If I could get
the components to see the dbInfo for the form, I could just store the
reference to VendorBox as dbInfo.invoiceVendor and any other component
could have easy access to it by simply knowing where dbInfo was.
Long explanations can be hard to read, so here's a basic diagram
------------------------------
JFrame
|
}Components
| }VendorBox ( a ComboBox which selects the
| vendor to receive from )
|
}dbInfo (not a component)
}VendorList
------------------------------
My Question: How to I get VendorBox to see VendorList (or dbInfo for
that matter)?
------------------------------
*Note: I'm using Netbeans 5.5, which doesn't allow me to edit the
component initialisation proccess inline. I think I might be able to
do this using the properties window, but I haven't had any luck
getting this to work*
What I've tried:
Just putting it in based on its name and location:
1) A direct reference - using a setdbInfo() method, which sets the
dbInfo equal to JFrameName.dbInfoVariableName. Netbeans gives me a
variable (or symbol or something of the like) not found.
2) The Netbeans property window - because I have setdbInfo() and
getdbInfo() fields in my VendorBox class, Netbeans shows dbInfo in the
property window. Trying to edit this property gives me a form which
among other things says 'form connection mode' and has options like
'from property' and 'from method'. None of the options have any
options to select within them, which I think is because i need to do
something to set up the form connections, but I'm not sure and my own
personal searches have not presented me with useful information.
At this point I thought I'd try to make a finddbInfo class, which
would just find the dbInfo class by crawling its way out
3) Introspection - When I read the description of this I sighed
relief, I thought it would show me the class that my VendorBox was
inside, but as far as I can tell it only shows you the class
inheritance information. I tried all the getxxx() commands netbeans
offered for code completion, but all I got back was info from the
classes my vendorBox was built on or null.
4) VendorBox.getParent() - combined with introspection, I used this to
progress a Class from displaying info about my vendorBox to info about
its containing panels, when I progressed to the outmost panel,
however, instead of getting the JFrame info on the next entry, I got
null.
At this point I cried, cut myself, and poured the rest of my drink out
for my dead homies.
Please help me, I enjoy using Java because I can work with it quickly,
but I feel like screaming sometimes because I can't pass a simple
piece of info to a component. I've learned so much more than I needed
to and wasted so much valuable time trying to do this and I know in my
heart that there is an easy answer that will make me feel
simultaneously stupid and relieved. I need that feeling like you
wouldn't believe, and I'm sure there our other amateur programers out
there who could benefit greatly by understanding why my methods don't
work.
On that note, if you could even explain why solutions like 1) or 4)
don't work, I think a lot of people could benefit from that info.