Solved

Class call and invoke

Posted on 2011-03-01
5
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

624 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