File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing with Many static variable and method

 
Leonardo Carreira
Ranch Hand
Posts: 489
Eclipse IDE Java Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ..
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Leonardo Carreira
Ranch Hand
Posts: 489
Eclipse IDE Java Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir for your reply..

but iam still confused...
may you give me an example?..

Thanks in advance..

 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic