Board index » jbuilder » Static objects in Frame Designer problem

Static objects in Frame Designer problem


2005-08-14 04:21:23 AM
jbuilder22
Hi, is there anyway to remove designer massages when You have static objects
in Frame class.
I always get...for example:
"Failed to create live visual subcomponent jdbStatusLabel1 as static
JdbStatusLabel jdbStatusLabel1 = new JdbStatusLabel();. Creating using
default constructor com.borland.dbswing.JdbStatusLabel
Failed to create live visual subcomponent jButton3 as static JButton
jButton3 = new JButton();. Creating using default constructor
javax.swing.JButton
Failed to create live visual subcomponent UkalkulacijatJDBT as static
JdbTable UkalkulacijatJDBT = new JdbTable();. Creating using default
constructor com.borland.dbswing.JdbTable"
I also sometimes get:
"class java.lang.NoSuchFieldError jButton3
Unable to design Frame1.java. Make sure that the file is in the current
project, does not contain any syntax errors, and that all resources are
compiled."
Applications compiles and works perfectly normal, but designer is becoming
annoying with thoose messages everytime I go to UI designer.
And also, I need those object static because I use methods on them from
another class where are DataSets(DataModule)....or there is another way...
 
 

Re:Static objects in Frame Designer problem

XXXX@XXXXX.COM wrote:
Quote
Well you sound like you know what you are saying, but I don't want to do
that in the way you explained it, since I am almost finished with work,
and I don't have time to check
what you advised me to look at, and also my app. isn't that big, maybe
7000 lines alltogether,14 classes so it's not hard to read it.I finally
got rid of "class java.lang.NoSuchFieldError jButton3"
error, and I can live with designer messages....But, let's forget
jdbstatuslabel, I can throw that out it's really not that imoprtant.

Chock it up to a new future paradigm shift then :)
Think of a normalized database for a moment. Would you create a Databas with
one table holding everything? Or would you create Tables that HAVE
relationships with other tables?
In other words:
Table: Customers
-->Contains Customer Info (Name, Address, etc.)
-->Contais Shipping Info (ShipAdd, City, State,etc)
-->Contains Orders (Date Time, Quantity, Item, Cost, Price,Sale
Price, etc)
You would not create a customer table with all of these duplicate entries
(although I have seen some come close, unfortunately).
No a good table structure would be:
-->Customer (IDCustomer, Name, TypeBusiness, etc)
-->Orders (IDOrder, IDCustomer, Qnt, Item, Price, etc)
-->Addresses( IDAdd, IDCustomer, Address, City, State, Type,etc)
What you are doing is GROUPING dependent information on keys (primary,
foreign). You should use a similar approach when doing OOP programming.
Customer Class
Order Class
Address Class.
But how do you hold dependency information in a static context? If I create
a customer, Order, and Address class, I want to maintain some type of state
between a Customer Class created, Order Class, and Address class, so that
if one changes, all do.
There are several ways to accomplish this (some better than others), but for
demo purposes only, think of a primary key/foreign key relationship.
For instance, you could define a HashMap that contains a key to an ArrayList
of Objects (Customer,Address,Order), the key being IDCustomer's value.
ArrayList array= new ArrayList();
array.add(customer);
array.add(addresses);
array.add(orders);
HashMap currentOrder new HashMap();
currentOrder.put(IDCustomer,array);
That way a relationship would exists between an order and all dependent
classes.
Of course another way it to create a linking class
public class ValidOrders(idCustomer,customerClass,addressClass,
orderClass){
this.setIDCustomer(idCustomer);
this.setCustomer(customerClass);
this.setAddressClass(addressClass);
.... etc
//then
public ValidOrders getValidOrders(){
return validOrders;
}
Another way is to have one static method in each class that returns an
instance of itself:
public static CustomerClass getCustomerClass(){
return customerClass();
}
This way you have instances of the invoked objects/classes, plus all
attributes/methods in the class, without having to make each one static
(like you did).
Another way is to use an ActionClass that fires an event when one class
class needs data from another or at a needed time within the event. See Sun
Site for examples.
Quote
I also have static Jbuttons and Jdbtables, because ,for example, when
Master DataSet is navigated, and if Detailed DataSet is empty I want to
disable my "refresh" button.
ActionClass would work here.
Quote
Another example, I have column change listener
on dataset and when user enters value selection
jumps from first to let's say fifth column, I have working code for both
cases but how can I access thoose objects from another class.
See above examples, like in the HashMap or ActionClass examples.
Basically what you have done is kind of like the one table example. All data
is live in one application instance. If you ever need to mod this app, it
is going to get messy, not to mention, you are really eating up memory and
resources by keeping objects alive when they do not need to be.
NOTE: I am not proposing any of the examples above is the way you should
implement your application design. I am only using them as a reference to
think about other ideas. That is why Paul F. advised that you look at
design patterns. Sun has a good tutorial about this on their site.
Basically, you should not use static attributes, only methods. And these
should be kept to a minimum, unless you want your app to eat resources like
candy. Yes, statics are necessary for certain types of patterns and to
return instances of Object invocations, but it is overly redundant to make
each attribute or each method static, not to mention a waste of resources.
Download a Java profiler and see what I mean.
Good luck.
 

Re:Static objects in Frame Designer problem

XXXX@XXXXX.COM wrote:
Quote
Hi, is there anyway to remove designer massages when You have static objects
in Frame class.
I always get...for example:

"Failed to create live visual subcomponent jdbStatusLabel1 as static
JdbStatusLabel jdbStatusLabel1 = new JdbStatusLabel();. Creating using
default constructor com.borland.dbswing.JdbStatusLabel
Failed to create live visual subcomponent jButton3 as static JButton
jButton3 = new JButton();. Creating using default constructor
javax.swing.JButton
Failed to create live visual subcomponent UkalkulacijatJDBT as static
JdbTable UkalkulacijatJDBT = new JdbTable();. Creating using default
constructor com.borland.dbswing.JdbTable"

I also sometimes get:
"class java.lang.NoSuchFieldError jButton3
Unable to design Frame1.java. Make sure that the file is in the current
project, does not contain any syntax errors, and that all resources are
compiled."

Applications compiles and works perfectly normal, but designer is becoming
annoying with thoose messages everytime I go to UI designer.

And also, I need those object static because I use methods on them from
another class where are DataSets(DataModule)....or there is another way...
There is no valid reason to use static fields for those
widgets. The data layer should know absolutely nothing
about the view layer, so having a design where your data access
class which manages the datasets directly invoke methods
on the the status label in the UI class goes against that
design practice. This leads to very messy code which is
too tightly coupled.
If an event occurs in the data access layer which needs
to be reflected in the UI layer, you communicate between
the layers via registering with the data access layer
to receive status notifications/events. For that, you
should design an event/listener interface, and then
implement that interface in both the frame in question,
and in the data access class.
(A design pattern book may help you out with this kind
of problem.)
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

{smallsort}

Re:Static objects in Frame Designer problem

Well you sound like you know what you are saying, but I don't want to do
that in the way you explained it, since I am almost finished with work, and
I don't have time to check
what you advised me to look at, and also my app. isn't that big, maybe 7000
lines alltogether,14 classes so it's not hard to read it.I finally got rid
of "class java.lang.NoSuchFieldError jButton3"
error, and I can live with designer messages....But, let's forget
jdbstatuslabel, I can throw that out it's really not that imoprtant.
I also have static Jbuttons and Jdbtables, because ,for example, when
Master DataSet is navigated, and if Detailed DataSet is empty I want to
disable my "refresh" button.Another example, I have column change listener
on dataset and when user enters value selection
jumps from first to let's say fifth column, I have working code for both
cases but how can I access thoose objects from another class. I tried using
instance of Frame and get method from Frame class, but it makes, ofcourse,
new frame in class, and anyway this doesn't work. So how can I, and can I
make reference to object in Frame class without getting new frame in that
class.In normal cases instance and get method from instance class works
normal, but here no.Can anyone help me with this,...thnx for answering me
Paul....bye..
"Paul Furbacher [TeamB]" < XXXX@XXXXX.COM >je napisao u poruci interesnoj
grupi:43001515$ XXXX@XXXXX.COM ...
Quote
XXXX@XXXXX.COM wrote:
>Hi, is there anyway to remove designer massages when You have static
>objects in Frame class.
>I always get...for example:
>
>"Failed to create live visual subcomponent jdbStatusLabel1 as static
>JdbStatusLabel jdbStatusLabel1 = new JdbStatusLabel();. Creating using
>default constructor com.borland.dbswing.JdbStatusLabel
>Failed to create live visual subcomponent jButton3 as static JButton
>jButton3 = new JButton();. Creating using default constructor
>javax.swing.JButton
>Failed to create live visual subcomponent UkalkulacijatJDBT as static
>JdbTable UkalkulacijatJDBT = new JdbTable();. Creating using default
>constructor com.borland.dbswing.JdbTable"
>
>I also sometimes get:
>"class java.lang.NoSuchFieldError jButton3
>Unable to design Frame1.java. Make sure that the file is in the current
>project, does not contain any syntax errors, and that all resources are
>compiled."
>
>Applications compiles and works perfectly normal, but designer is
>becoming annoying with thoose messages everytime I go to UI designer.
>
>And also, I need those object static because I use methods on them from
>another class where are DataSets(DataModule)....or there is another
>way...

There is no valid reason to use static fields for those
widgets. The data layer should know absolutely nothing
about the view layer, so having a design where your data access
class which manages the datasets directly invoke methods
on the the status label in the UI class goes against that
design practice. This leads to very messy code which is
too tightly coupled.

If an event occurs in the data access layer which needs
to be reflected in the UI layer, you communicate between
the layers via registering with the data access layer
to receive status notifications/events. For that, you
should design an event/listener interface, and then
implement that interface in both the frame in question,
and in the data access class.

(A design pattern book may help you out with this kind
of problem.)

--


Paul Furbacher (TeamB)

Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Static objects in Frame Designer problem

XXXX@XXXXX.COM wrote:
Quote
Well you sound like you know what you are saying, but I don't want to do
that in the way you explained it, since I am almost finished with work, and
I don't have time to check
what you advised me to look at, and also my app. isn't that big, maybe 7000
lines alltogether,14 classes so it's not hard to read it.I finally got rid
of "class java.lang.NoSuchFieldError jButton3"
error, and I can live with designer messages....But, let's forget
jdbstatuslabel, I can throw that out it's really not that imoprtant.
Well, my gut feeling is that you can to where you
want to go faster if you take advantage of the
listener/event pattern. Much of what you
need, if not all of it, is probably available
right now. All you have to do is make the
components which are firing events know that
your frame wants to be a listener.
Quote
I also have static Jbuttons and Jdbtables, because ,for example, when
Master DataSet is navigated, and if Detailed DataSet is empty I want to
disable my "refresh" button.Another example, I have column change listener
on dataset and when user enters value selection
jumps from first to let's say fifth column, I have working code for both
cases but how can I access thoose objects from another class. I tried using
instance of Frame and get method from Frame class, but it makes, ofcourse,
new frame in class, and anyway this doesn't work. So how can I, and can I
make reference to object in Frame class without getting new frame in that
class.In normal cases instance and get method from instance class works
normal, but here no.
I'll assume that you have what is the equivalent of DataModule
as in the samples/dbSwing/MultiLingual example -- that is, a
class which acts as a data access layer controller.
In that class, provide a getter for the dataset in question.
In the frame class which uses the data module/controller,
invoke
DataSet ds = datamodule.getMyDataset();
ds.addXXXListener(this);
where "this" is the frame in question.
Either this frame will implement the listener interface
in question, or a nested class will do so. Let's say
we are interested in being an EditListener to the dataset.
We'd write either
public class MyFrame
extends JFrame
implements com.borland.dx.dataset.EditListener
...
Or, we'd create a nested class of MyFrame which extends
the EditAdapter (much cleaner).
public class MyFrame extends JFrame {
public class MyEditAdapter extends EditAdapter {
// override the method you are interested in
// handling events for such as
public void inserted(...) ...{ ... }
}
...
}
In your instance, your frame or a nested class can
probably listen for navigation events in order to refresh
that button. You can listen for other events to provide
status info, and so on. I think you are mostly all the
way there, you just have to provide the API in your
data module/controller which allows your frame to get
access to the right components in order to register
event handlers.
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Static objects in Frame Designer problem

Hi, thanx for answering me, and for Jprofiler.Well, I think I left
impression that everything in my project is static,which is really not the
case. Just
some Jdbtables, for reasons that I mentioned in previos post.I tried
Jprofiler and at her best my app. spends about 25 to 30 mb of memory. I
limited number of rows to dataset, and used paramterized queries to keep
datasets small.And my classes are structured through querries on tables,
like Merchandize name Class, Employee class, New merchandize price
calculation Class( the same way database is structured),etc.,the same way
you suggested I should do,and when i need something from Datasets i use
instance of class where they are, and getter method from that class.
I am not without questions in this post too:), so about... "Another way is
to have one static method in each class that returns an instance of
itself"..I use that and in frame for example when attaching it to data aware
components I see Instance of class and method(like myDM1.getquerydataset1).
So my question is, some DataSets are used in more than one class, so when i
have let's say 4 classes that use instance. and get method that returns the
same DataSet, do I have 4 same DataSet objects or just one that is shared
with those four classes.
And I will probably close some DataSets by myself when Jdbtable looses
focus, and since probably someone will read this...can someone tell me do I
need to have Jdatastore server and licence for datastore, or it's free to
use it as permament storage instead of memorystore.Thank you very much once
again...bye...
Quote
Chock it up to a new future paradigm shift then :)

Think of a normalized database for a moment. Would you create a Databas
with
one table holding everything? Or would you create Tables that HAVE
relationships with other tables?

In other words:
Table: Customers
-->Contains Customer Info (Name, Address, etc.)
-->Contais Shipping Info (ShipAdd, City, State,etc)
-->Contains Orders (Date Time, Quantity, Item, Cost, Price,Sale
Price, etc)

You would not create a customer table with all of these duplicate entries
(although I have seen some come close, unfortunately).

No a good table structure would be:
-->Customer (IDCustomer, Name, TypeBusiness, etc)
-->Orders (IDOrder, IDCustomer, Qnt, Item, Price, etc)
-->Addresses( IDAdd, IDCustomer, Address, City, State, Type,etc)


What you are doing is GROUPING dependent information on keys (primary,
foreign). You should use a similar approach when doing OOP programming.

Customer Class
Order Class
Address Class.

But how do you hold dependency information in a static context? If I
create
a customer, Order, and Address class, I want to maintain some type of
state
between a Customer Class created, Order Class, and Address class, so that
if one changes, all do.

There are several ways to accomplish this (some better than others), but
for
demo purposes only, think of a primary key/foreign key relationship.

For instance, you could define a HashMap that contains a key to an
ArrayList
of Objects (Customer,Address,Order), the key being IDCustomer's value.
ArrayList array= new ArrayList();
array.add(customer);
array.add(addresses);
array.add(orders);
HashMap currentOrder new HashMap();
currentOrder.put(IDCustomer,array);

That way a relationship would exists between an order and all dependent
classes.

Of course another way it to create a linking class

public class ValidOrders(idCustomer,customerClass,addressClass,
orderClass){
this.setIDCustomer(idCustomer);
this.setCustomer(customerClass);
this.setAddressClass(addressClass);

.... etc
//then
public ValidOrders getValidOrders(){
return validOrders;
}

Another way is to have one static method in each class that returns an
instance of itself:

public static CustomerClass getCustomerClass(){
return customerClass();
}

This way you have instances of the invoked objects/classes, plus all
attributes/methods in the class, without having to make each one static
(like you did).


Another way is to use an ActionClass that fires an event when one class
class needs data from another or at a needed time within the event. See
Sun
Site for examples.



>I also have static Jbuttons and Jdbtables, because ,for example, when
>Master DataSet is navigated, and if Detailed DataSet is empty I want to
>disable my "refresh" button.

ActionClass would work here.

>Another example, I have column change listener
>on dataset and when user enters value selection
>jumps from first to let's say fifth column, I have working code for both
>cases but how can I access thoose objects from another class.

See above examples, like in the HashMap or ActionClass examples.

Basically what you have done is kind of like the one table example. All
data
is live in one application instance. If you ever need to mod this app, it
is going to get messy, not to mention, you are really eating up memory and
resources by keeping objects alive when they do not need to be.

NOTE: I am not proposing any of the examples above is the way you should
implement your application design. I am only using them as a reference to
think about other ideas. That is why Paul F. advised that you look at
design patterns. Sun has a good tutorial about this on their site.

Basically, you should not use static attributes, only methods. And these
should be kept to a minimum, unless you want your app to eat resources
like
candy. Yes, statics are necessary for certain types of patterns and to
return instances of Object invocations, but it is overly redundant to make
each attribute or each method static, not to mention a waste of resources.
Download a Java profiler and see what I mean.


Good luck.

 

Re:Static objects in Frame Designer problem

OK, this doesn't look hard, I'll try that tomorrow, I have almost the same
code, but in wrong place( in wrong class).That nested class seems much
better solution,I think I got it now....well to you it may seemed very easy
but for me with 4 months of database and java experience...hmmm....:)....Ok
thanx again for your patience...bye..
"Paul Furbacher [TeamB]" < XXXX@XXXXX.COM >je napisao u poruci interesnoj
grupi:4300c7d5$ XXXX@XXXXX.COM ...
Quote
XXXX@XXXXX.COM wrote:
>Well you sound like you know what you are saying, but I don't want to do
>that in the way you explained it, since I am almost finished with work,
>and I don't have time to check
>what you advised me to look at, and also my app. isn't that big, maybe
>7000 lines alltogether,14 classes so it's not hard to read it.I finally
>got rid of "class java.lang.NoSuchFieldError jButton3"
>error, and I can live with designer messages....But, let's forget
>jdbstatuslabel, I can throw that out it's really not that imoprtant.

Well, my gut feeling is that you can to where you
want to go faster if you take advantage of the
listener/event pattern. Much of what you
need, if not all of it, is probably available
right now. All you have to do is make the
components which are firing events know that
your frame wants to be a listener.

>I also have static Jbuttons and Jdbtables, because ,for example, when
>Master DataSet is navigated, and if Detailed DataSet is empty I want to
>disable my "refresh" button.Another example, I have column change
>listener on dataset and when user enters value selection
>jumps from first to let's say fifth column, I have working code for both
>cases but how can I access thoose objects from another class. I tried
>using instance of Frame and get method from Frame class, but it makes,
>ofcourse, new frame in class, and anyway this doesn't work. So how can I,
>and can I make reference to object in Frame class without getting new
>frame in that class.In normal cases instance and get method from instance
>class works normal, but here no.


I'll assume that you have what is the equivalent of DataModule
as in the samples/dbSwing/MultiLingual example -- that is, a
class which acts as a data access layer controller.

In that class, provide a getter for the dataset in question.

In the frame class which uses the data module/controller,
invoke

DataSet ds = datamodule.getMyDataset();
ds.addXXXListener(this);

where "this" is the frame in question.
Either this frame will implement the listener interface
in question, or a nested class will do so. Let's say
we are interested in being an EditListener to the dataset.
We'd write either

public class MyFrame
extends JFrame
implements com.borland.dx.dataset.EditListener
...

Or, we'd create a nested class of MyFrame which extends
the EditAdapter (much cleaner).

public class MyFrame extends JFrame {

public class MyEditAdapter extends EditAdapter {
// override the method you are interested in
// handling events for such as
public void inserted(...) ...{ ... }
}
...
}


In your instance, your frame or a nested class can
probably listen for navigation events in order to refresh
that button. You can listen for other events to provide
status info, and so on. I think you are mostly all the
way there, you just have to provide the API in your
data module/controller which allows your frame to get
access to the right components in order to register
event handlers.


--


Paul Furbacher (TeamB)

Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Static objects in Frame Designer problem

XXXX@XXXXX.COM wrote:
Quote
OK, this doesn't look hard, I'll try that tomorrow, I have almost the same
code, but in wrong place( in wrong class).That nested class seems much
better solution,I think I got it now....well to you it may seemed very easy
but for me with 4 months of database and java experience...
Well, I'd say you are doing quite well: as you said, you have most
of the code, it just needs to be put in the right place.
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Static objects in Frame Designer problem

Well nested classes did it , I officially declare that all static object are
now non-static. Now we are getting somewhere, thanx to everyone who
helped...it also helped about other things..it made me rethink, and think
better now in other situations(primary and foregn key example, I was doing
that all the time but didin't think like that), ....
Now if I could just force that pickList from stop throwing
nullPointException when I have Croatian, or any other Central European
locale defined on source DataSet it would be great...there is a way around
the problem(new identical DataSet which doesn't have locale defined, closed
when it isn't needed), but I would like to have only one...so anyone knows
something about this....is it a Bug of some kind....I am using Jbuilder 2005
foundation update 4...bye...
"Paul Furbacher [TeamB]" < XXXX@XXXXX.COM >je napisao u poruci interesnoj
grupi:43014f96$ XXXX@XXXXX.COM ...
Quote
XXXX@XXXXX.COM wrote:

>OK, this doesn't look hard, I'll try that tomorrow, I have almost the
>same code, but in wrong place( in wrong class).That nested class seems
>much better solution,I think I got it now....well to you it may seemed
>very easy but for me with 4 months of database and java experience...

Well, I'd say you are doing quite well: as you said, you have most
of the code, it just needs to be put in the right place.


--


Paul Furbacher (TeamB)

Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
 

Re:Static objects in Frame Designer problem

XXXX@XXXXX.COM wrote:
Quote
Now if I could just force that pickList from stop throwing
nullPointException when I have Croatian, or any other Central European
locale defined on source DataSet it would be great...there is a way around
the problem(new identical DataSet which doesn't have locale defined, closed
when it isn't needed), but I would like to have only one...so anyone knows
something about this....is it a Bug of some kind....I am using Jbuilder 2005
foundation update 4...
Look to see if you have the source for dbswing in the
"src" directory of your Foundation installation. (I know
that Developer and Enterprise offer it, but don't know
whether it's available with Foundation.) If it's there,
unarchive it to a fresh "src" directory under you Java projects
directory, such as
d:/JavaProjects/dbswing/src
Then use the New Project From Source wizard, identifying
the above src dir. Create a JAR archive using the archive
wizard. Build the project with all the debugging options
on (this is the default for new projects unless you have
changed it). Finally, create a JBuilder library definition,
e.g., named "dbSwing-debug", and use that in your project.
That may help you debug the cause of the NPE, and perhaps
you can then modify the dbSwing code to eliminate it. If
you do find the cause (and possibly a solution), write up
a bug report at Quality Central, and post back here with
your findings.
--
Paul Furbacher (TeamB)
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.