Check if there is an instance from specific class

suppose i have i class with name FrmColor
and i want to write a program that show this Frame by clicking on a button like this
import FrmColor;
import java.awt.Button;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Frame;
public class Test extends Frame
     private Button b;
     public static void main(String args[])
          new Test();
     public Test()
          super("Test");
          b = new Button("Show Color");
          b.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent evt){
                    b_aciotnPerformed(evt);
     private void b_actionPerformed(ActionEvent evt)
          if there is an instance of FrmColor then
               bring FrmColor to Front
          else
               create an instance from this class
pleaze Help Me.

hi,
what you want is a static int variable called count which is incremented everytime the constructor is called:
public static int count = 0;In the constructor, have:
count++;and a static method to return this variable:
public static int getCount() {
    return count;
}You can then get this count:
FrmColor.getCount();This would be implemented in your code as follows:
private void b_actionPerformed(ActionEvent evt)
if(FrmColor.getCount() != 0)
    bring FrmColor to Front
else
    create an instance from this class

Similar Messages

  • Indexing instances of specific class inside MovieClip authored with Flash Pro

    Hi there.
    I'm writing a class that extends MovieClip and that is linked to the MovieClip Object authored via Flash Pro during development (Father object).
    The hierarchy of this MovieClip Object is hidden from me - everything I know is that it may contain instances of other Class that was authored during development and extends MovieClip in the same manner (Son objects).
    I have no information regarding names or hierarchical positions of these Son objects inside Father object.
    Now the question is: how to get them listed?
    So approach I've taken was to implement current events:
    public class Son extends MovieClip
         public static const INITIALIZED : String = "son_initialized";
         public function Son ()
              this.dispatchEvent (new Event (INITIALIZED));
    public class Father extends MovieClip
         public var son : Vector<Son>;
         public function Father ()
              son = new Vector<Son> ();
              this.addEventListener (Son.INITIALIZED, this.onSonInitialized);
         public function onSonInitialized (event : Event)
              this.son.push (event.target);
    Well, this code compiles with no errors whatsoever, but it turns out that onSonInitialized gets never called. I assume that's because children constructors are called ahead of their parent one.
    Is there any way to get them listed?
    Thanks in advance.

    kglad,
    I'm trying to get an array of references to Son objects (Son extends MovieClip), randomly located deep inside display list hierarchy of Father object (extends MovieClip too).
    The Father movieclip is authorized in Flash Professional and is a black box for me - I can only manipulate Father.as and Son.as.
    Since I can't know exactly their pathes and names (i.e. father.child1.child5OfChild1.son32 for example), I decided to make them self-aware, dispatching event during construction time, messaging everybody that this instance of Son exists:
    public function Son ()
         this.dispatchEvent (new Event (INITIALIZED));
    And then I attached a listener inside Father's constructor:
    public function Father ()
         this.addEventListener (Son.INITIALIZED, this.onSonInitialized);
    The idea was that this event listener should have been catching all the Sons, located inside Father. But it doesn't work that way - Father's constructor seems to be called after all constructors of its children, so this event listener catches nothing.
    I've worked this around by straightforward display list traversing - it works, but doesn't look so elegant. May be there is still a way to make it work through events?

  • Help! How to convert an instance from java.lang.Object to a particula class

    * How to convert an instance from java.lang.Object class to a particular class
    witch is known only at the running time?
    Roster EJB component is make up of RosterHome, Roster and RosterBean.
    RosterHome is the home interface of Roster EJB.
    Roster is the remote interface of Roster EJB.
    RosterBean is the implement of Roster EJB.
    The following code segment is to invoke Roster EJB component.
    String jndiName="roster.RosterHome";
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    RosterHome home =
    (RosterHome)javax.rmi.PortableRemoteObject.narrow(objref,
    RosterHome.class);
    Roster myRoster = home.create();
    String team="T1"
    String player="Tom"
    myRoster.addPlayer(player,team);
    But, now, all the home interface, the remote interface and the JNDI Name of
    Roster EJB component are not been known at the compiling time. However They are
    known at the running time, throught reading from the XML config file.
    Questions:
    1,How to write code for this case ? or
    2,How to convert an instance from Object class to a particular class witch is known
    only at the running time?
    String jndiName="roster.RosterHome";// in fact, reads from XML file.
    String homeClassName="roster.RosterHome";// in fact, reads from XML file.
    String remoteClassName="roster.Roster";// in fact, reads from XML file.
    javax.naming.Context initial = getInitialContext();//getInitialContext() returns a instance of Context.
    Object objref = initial.lookup(jndiName);
    Object objHome= javax.rmi.PortableRemoteObject.narrow(objref,
    Class.forName(homeClassName));
    /* how to do next?
    }

    I am not sure what you are trying to do. But at some point you should know which methods to call on the remote interfaces. Maybe the method names are stored in the XML file as well or you have a set of standard method names (also consider parameters).
    However, this can be solved by reflection. Look at the java.lang.reflect package, especially java.lang.reflect.Method, and also at java.lang.Class.
    If you are doing this on the app server:
    I've seen posts where people say that reflection is not permitted in EJB, but I don't think so. Check the EJB spec.
    If you are doing this in an application: reflection is always permitted. Probably also in applets and JSP.

  • How to call a method from a class without creating an instance fromthisclas

    I want to create a class with methods but I want to call methods from this class without creating an instance from this class. Is this possible?
    Is there in Java something like class methods and object methods????

    keyword 'static' my friend.
    public class foo {
    public static void bar {
    System.out.println ("hello");
    foo.bar()

  • Create an instance of a class from class name

    Hi,
    I have the class name as a String variable. I need to create an instance from this class. How to do it in Java?
       Thanks and regards, Marina

    Hello
    see
    [http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String)]
    and
    [http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#newInstance()]
    for Classes with paramterless constructor
    or
    [http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Constructor.html#newInstance(java.lang.Object[])]
    for Constructor with parameters
    regards franz

  • Passing instance parametres through classes

    I'd want to know if this way of programming is good
    I have a class called Application which many classes should have access to. So what I do is to pass the instance of the class through the constructors of the classes that needs the Application class and all works fine.
    Don't know if this is a good programming manneer.
    Thanks!

    Is there just one instance of the class? If so, google for "singleton pattern" and use that. It will do just what you want, will be recognized by other programmers, and is simpler.

  • I was trying to log in using my credit card, and was unable to. However when I checked my checking account i seen there was 4 charges from itunes. But, i was never able to sign in. I would appreciate a PERSON contact me to explain why this happened.

    Hello,
         Last night my daughter was trying to log in to take care or some apps she has. While she was doing so, she got a message that said credit card was declined. Three time that popped up on her. then I tired with my credit card, and the same thing happened. So I left it and tired calling. But do you think there could be a person to talk with **** NO. Now I am stuck doing this. So anyway's sorry to rant, I Checked my checking account today and found there were a charge from itunes of $1.38 on it. I then looked at my daughter account and found 3 charges of the same amount. Mine ended up getting a overdraft fee of $35.00.
         My question is. What are you going to do about this? If I am unable to log in how can I get charged? does not make a hole lot of scene to me.How about you?

    We are fellow users here on these user-to-user forums, you're not talking to iTunes Support nor Apple.
    Is the credit card registered to exactly the same name and address (including format and spacing etc) that you have on your iTunes account, it was issued by a bank in your country and you are currently in that country ? If it is then you could check with the card issuer to see if it's them that are declining it, and if not then try contacting iTunes support and see if they know why it's being declined : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Account Management
    Each time that you add or change your card details then a temporary store holding charge may be applied to check that the card details are correct and valid (though that is usually $1 or the approximate local equivalent) : http://support.apple.com/kb/HT3702
    Did your daughter owe any amounts to iTunes ? Does anything show on your purchase history : http://support.apple.com/kb/HT2727 ? If they are proper charges which you don't think that you should have then you can contact iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Since i got the new Iphone 4s it constantly drops calls. Apple have replaced the phone with another new iphone 4s but i am still having the same problem. I have checked with vodapohe that there is no issue from there end, given a new sim, still drops out

    Since i got the new Iphone 4s it constantly drops calls. Apple have replaced the phone with another new iphone 4s but i am still having the same problem. I have checked with vodapohe that there is no issue from there end, given a new sim, still drops out

    Have a look at this it might help
    http://support.apple.com/kb/TS4148

  • What can be wrong with my iPhone 4?  There is no sound from incoming calls, SMS and even when I play music.  I already checked that it's not muted, volume is high and not set to "vibrate mode."

    What can be wrong with my iPhone 4s.  There is no sound from incoming calls and SMS even when I try to play music.
    I already checked that it is not muted, volume is high and not in " vibrate mode."

    What can be wrong with my iPhone 4s.  There is no sound from incoming calls and SMS even when I try to play music.
    I already checked that it is not muted, volume is high and not in " vibrate mode."

  • How to check if there is specific text in a word document ?

    Hello everyone ,
    I have a form include text box1  , I need to check a word document if  there is specific text inside it , if it’s true the textbox1.text = 1 , if it’s false the textbox1.text = 0 , and so on .
    to be clear I’m trying to check a lot of things not just specific text also ( font size , font color , font type , photo , table …………etc ) .
    I read a lot of threads about Office Automation , all about how to create a new documents and insert text tables photos….. etc, but what I need just to check if it existing or not
    Any idea , books, threads ,examples ….
    Thanks in advance.
    Visual Studio 2013
    office 2007

    "1- what if i need to check that word in the beginning of the second paragraph in that document or at the end of the third paragraph "
    to find a word in a paragraph, use the range keyword as in
    Dim rng As word.Range = objDoc.Paragraphs(1).Range
    rng.Find.Execute(FindText:="yourtext")
    " can you give me any website or books , to learn how to check  ( font size , font color , font type , photo , table
    …………etc ) and return with (1,0) or (true ,flase)."
    You can use the range object here aswell
    If rng.Font.Size = 7 Then TextBox1.Text = 1
    Look at this link for a multiple of examples about word automation
    https://msdn.microsoft.com/en-us/library/78whx7s6(v=vs.80).aspx

  • Is there a way to access ABAP OO instances from a batch job report

    Hello,
    I am looking for a way to access ABAP OO instances from a batch job report. My circumstances are the following:
    I have got some ABAP OO coding that identifies other objects (class instances) that have to be processed (they have a DoIt method that does some calculation). As this processing is time consuming and performace relevant I have to parallelize this in batch jobs. This batch jobs however can only be "simple" ABAP reports according to SM36. The problem is now that I dont really know how to tell the batch job report what objects to process. Somehow I have to access theses instances from  that batch job report.
    Does anybody have an idea?
    Greetings
    Matthias

    Hi David,
    thanks a lot for your help. After a lot of searching on the net this seems to be the only way to cope with it. However I am not sure about the locking mechanisms and if its suitable for mass data processing. In the help page you suggested the following is stated which I do not fully understand::
    "The current lock logic does not enable you to set specific locks for the following requirements:
    ·        Many parallel read and write accesses
    ·        Frequent write accesses
    ·        Division into changeable and non-changeable areas
    Although the lock logic makes the first two points technically possible, they are not practical because most accesses would be rejected."
    Does this mean
    a) if I dont want to set "specific locks" for frequent write accessess I am fine
    or
    b) I am discouraged from use shared memory technics for frequent write accessess?
    In the latter case I will have a problem...
    What do you think?
    Greets
    Matthias

  • Having issues with contacts... groups specifically... when I add contacts to a group and check back there are fewer in group than when i started.. they disappear??

    having issues with contacts... groups specifically... when I add contacts to a group and check back there are fewer in group than when i started.. they disappear??

    Hi
    in this scenarion control is not going inside the condition
    if (vo.getRowCount() == 0) and therefore VO is not getting initialized
    why u are counting the row of VO to initialize the VO ,if possible pls remove this condition check ,problem will be solved .pls let me know in case of any issues.
    thanx
    Pratap

  • I am in the process of doing a Proof Of Concept / Evaluating products that can help us build a Java Application to Convert a PDF document to a Searchable PDF.   I wanted to check is there any simple JAVA API from Adobe to achive this ? Any direction in th

    I am in the process of doing a Proof Of Concept / Evaluating products that can help us build a Java Application to Convert a PDF document to a Searchable PDF. 
    I wanted to check is there any simple JAVA API from Adobe to achive this ? Any direction in this regard is greatly appreciated.@

    You can achieve this using LiveCycle PDF Generator JAVA API. You can find required code here:
    Adobe LiveCycle * Quick Start (SOAP mode): Converting a Microsoft Word document to a PDF document using the Java API
    In parameters:
    //Set createPDF2 parameter values
    String adobePDFSettings = "Standard";
    String securitySettings = "No Security";
    String fileTypeSettings = "Standard OCR";
    "Standard OCR" file type setting will run OCR on input pdf. In the code, instead of doc file provide a pdf file. Resultant pdf will be searchable PDF i.e OCRed PDF.
    Feel feel to ask any further questions.

  • TS2755 is there a way to block texts from specific numbers to imessage with out turning imessage off?

    is there any way to block text from specific numbers to imessage without turning imessage off?

    Go to Settings > Messages > Send & Receive > You can be reached by iMessage at:
    Select the right facing arrow in a blue circle next to the email address this girl is sending iMessage to and select Remove This Email.
    If she has your cell phone number, she can switch to sending iMessage to that and there will be nothing you can do, but removing the email address will prevent you from receiving an iMessage addressed to that email address.

  • Is there any way to get specific app data from iCloud so that when you redoes load an app, you can restore its data?

    Is there any way to get specific app data from iCloud so that when you redoes load an app, you can restore its data?

    no.
    the backup is only for the purpose if you need to wipe the device.

Maybe you are looking for

  • How to find out the cost of SAP user for a particular user id

    Dear All, I got one issue like how to find out the cost of SAP user, i mean for a particular user id. Could you please advice me regarding this. Raghu

  • Having trouble using a vector from another class

    have a vector in an addresbook class but when I try to acess the vector to write its object to a file from a write class, it doesn't resolve the symbol for the variable. How to I use the same same vector across different classes. thanks

  • Clearing the eprint queue after error

    We sent two print jobs to eprint and got an email error message that the printer was not connected. We discovered the IP address was missing and traced that to the cable being disconnected accidentally. That is all cleared now and in the process of t

  • Bluetooth **bleep**

    Newly updated to 10.4.1.B.0.109.  Not rooted.  Even ran a repair with a full reset after the update.  I'm having a **bleep** of a time using bluetooth and wifi at the same time.  Anyone else experiencing issues?  All I'm trying to do is use a BT keyb

  • Java/lang/reflect/InvocationHandler starting server

    I'm having some issues gettin the node manager up and running. We're just transitioning to running clusters and I need to get the Node manager going for this and other reasons. I'm running 6.1 sp2. My Node Manager starts correctly, but when I attempt