Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Class call and invoke

Posted on 2011-03-01
5
Medium Priority
?
278 Views
Last Modified: 2012-05-11
I need to use for the same class two different communication ways:
1. I need to call it from toggle button
Abc abc = new Abc();
abc.method1();
2. At the same time this class Abc created
private static Abc abc = new Abc();
public static Abc getInstance() {
return instance;
}
I have to use 1 way in jToggleButton to change boolean value , I try to do it with invoking instance, but it doesn't work.
Please advice.
0
Comment
Question by:gbcbr
  • 2
  • 2
5 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 35008145
If it has public constructor why would you use second way? If it does not have public constructor you cannot use it in the first way.
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 400 total points
ID: 35008159
you need to invoke the getInstance method in all the place instead of new ABC()!
0
 

Author Comment

by:gbcbr
ID: 35008638
>> If it has public constructor why would you use second way?
Please explain.
I use second way because this class DecisionCenter has to collect few boolean values from different classes and if all this values lay down into my puzzle correct it will allow deal.
0
 
LVL 47

Accepted Solution

by:
for_yan earned 1600 total points
ID: 35008915
If you collect boolean or double values in DC why this has anything to do with the way you access your ABC class ? Please, explain it to yourself and to me in plain words.

As you can see in this discussion there are very few classes which have both public constructore and getInstance mechanism. Why do you want to be so special?  Do like everyone else - either  - or. It is always easier to be like the majority
http://www.velocityreviews.com/forums/t140755-constructor-or-getinstance-method.html
0
 

Author Closing Comment

by:gbcbr
ID: 35009046
Thank you for very good link to discussion
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question