| Author |
Swing with Many static variable and method
|
Leonardo Carreira
Ranch Hand
Joined: Apr 07, 2009
Posts: 482
|
|
Hi Friends..
i have a question..
do i have to use many static variable or method in Swing/Swt/Awt application?..
example i have method like this instance : (which would be accessed from another JDialog)
do i have to use static variable also?..
assume that, i have 2 JDialog, which named JDialog1 and JDialog2..
JDialog2 would be opened by click a button on JDialog1..
and in JDialog2 has JTable.. when user double click row in JTable, then the values would be sent to JTextField in JDialog1..
so i provide static JTextfield..
and the code like this example :
what i have done is true or not?
Correct me if iam wrong..
Thanks in advance ..
|
Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
I definitely would not do that. Instead, make the methods regular instance methods (so non-static), and provide the second JDialog a reference to the first JDialog. You can then use this reference to call the methods.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Leonardo Carreira
Ranch Hand
Joined: Apr 07, 2009
Posts: 482
|
|
Thanks sir for your reply..
but iam still confused...
may you give me an example?..
Thanks in advance..
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
The new JDialog class gets a reference field to class JDialog1, which you set in the constructor:
Created from a JDialog1 instance:
Your code then simply calls dialog1.xxx instead of JDialog1.xxx - using the new private field instead of static calls.
|
 |
Leonardo Carreira
Ranch Hand
Joined: Apr 07, 2009
Posts: 482
|
|
Yap..
it could ran well now..
how about if there are 3 JDialogs or more..
how to share that JDialog?..
i want to use only one JDialog so i have to share JDialog2, which would be accessed in another JDialog.. (actually we could create another JDialog which has contents like JDialog2, but i wouldn't create like that, it would magnify the Jar file which would be created)
example..
i have created JDialog2 to show all of the Products data..
then, that JDialog2 would be accessed in PurchasingDialog, or TradingDialog..
i want to distinguish whether the JDialog2 called by PurchasingDialog or TradingDialog..
is it possible?
Thanks in advance sir..
|
 |
 |
|
|
subject: Swing with Many static variable and method
|
|
|