Passing instance to other classes

Hi,
I have the following class
public class myApp extends SingleFrameApplicationWhen I pass the instance like as given below, the instance of SingleFrameApplication is passed. How can I pass the instance of myApp along with this, so that I can access the variables of myApp class from other classes and packages.
new TreeTableView(this);Please help.
Any help in this regard will be well appreciated with points.
Warm Regards,
Rony

Hi,
i think the constructor of TreeTableView looks sth. like TreeTableView(SingleFrameApplication app), so the TreeTableView takes a SingleFrameApplication and not a myApp. you have two possibilities to access your methods and variables.
1. Extend TreeTableView with a constructor TreeTableView(myApp app)
or
2. You cast the SingleFrameApplication to a myApp everytime you have to access myApp
=>
a = ((myApp)singleFrameApplicationInstance).variable;

Similar Messages

  • 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.

  • Passing data to other classes

    I have two seperate classes in my program.
    The class with main sends an LinkedList to the other class with this statement...
    PanelB a = new PanelB();
    a.setLink(points);Then in my other class I have this code...
    public LinkedList q;Then I have a subclass with this code to accept the LinkedList...
    public void setLink(LinkedList p, Graphics g){
    q = p;At this point everything is great the data is passing along nicely.
    Until I try to send the data to another sub class in the same class...
    public void paint(Graphics g, LinkedList q) {
           int k = q.size();
           System.out.println(k);It compiles fine but the program does not print out the size of the LinkedList. It does print it out at every step though before this one. What am I missing or is there a better way of doing all of this?

    Okay I messed with the code a little bit this is what I got.
    public class shapeDraw{
    public static void main (String[] args) {
      JFrame frame = new JFrame("Shape Outline");
      JPanel panel = new PanelB();
      panel.setPreferredSize(new Dimension(500,500));
      frame.getContentPane().add(panel);
      frame.pack();
      frame.setVisible(true);
      LinkedList points = new LinkedList();
      PanelB a = new PanelB();
      a.setLink(points);
    }}I left a lot out of the code to make it easier and quicker to read. This is my next class that is called by this class.
    public class PanelB extends JPanel {
    public LinkedList q;
    public void setLink(LinkedList p){
         q = p;
    public void paint(Graphics g) {
         Graphics2D g2 = (Graphics2D)g;
         g2.setPaint(Color.red);
         Point trig = new Point(10,200), trigB = new Point (50, 300);
         double x1=trig.getX();
         double x2=trigB.getX();
         double y1=trig.getY();
         double y2=trigB.getY();
         super.paint(g);
         g2.draw(new Line2D.Double(x1, y1, x2, y2));
    }This code draws a line. I would like bring my ListLinked to this subclass because I want to use the points I have stored in it to draw a picture.

  • Passing instance of the class to C++

    Hello,
    I pass instance of an object into C++ code, and I save pointer to it inside of DLL. So can I be sure that it wont be deleted later? Caz I need to use it in C++'s thread. It should be alive during all working, and java should not move it in memory...
    What do you think?
    Thanks,
    Dymytriy

    Won't work.
    Java won't delete it but it can move it.

  • Passing variables to other classes

    Hi the problem im having is ive made 3 classes class A, A1 and A2 when i create A i also create A1 what i am wanting to do is if a condition in A1 is met it will pass a variable to A so A can delete A1 and then create A2, im having some dificulty in passing this variable back to A.
    Any help appreciated

    You mean you want to return a variable from a method in class A?
    Read:
    http://java.sun.com/docs/books/tutorial/getStarted/application/objects.html

  • 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?

  • Pass the name of a button into existing instance of a class from actionlist

    I want to pass a name of a button from actionlistener that is associated with that button into existing instance of a class. I need to do so because I have array of buttons and I have set the name of the buttons as coordinates. Is there a way to do that?

    My buttons are declared as JButton arrayOfButtons[][] = new JButton[numberOfRows][numberOfColumns];and I labeled them inside 2 for loops as:
    arrayOfButtons[row][column].setName(Integer.toString(row) + " " + Integer.toString(column));
    arrayOfButtons[row][column].setText("Some displayed text");I also added ActionListener
    arrayOfButtons[row][column].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println(((JButton)e.getSource()).getName());
    });Now when I press a button it only displays the array coordinates on a command line. I want the class instance where I declared the buttons to get notified which button was clicked.

  • Passing values and calling other classes?

    Hello all.
    I have 2 classes(separate .java files). One is a login class and the other is the actual program. Login class(eventually exe file) should open the other class and pass the login parameters if you know what I mean. Is this possible, or do the 2 classes need to be part of one file?
    Thanks alot
    Milan D

    Login class can be another class in another file
    wht u have to do is to make an instance of login class in the class u want to use that class
    like login lg = new Login();
    and call method of login class
    lg.setUser(username);
    where setUser(String user); is a method of login class
    this way u can pass the parameters to login class
    i hope this might be helpful
    regards
    Moazzam

  • How to create the instance of a class and to use this object remotely

    I have to change a standalone program to do it working on a local net.
    the program is prepared for this adjustment, because the only problem for this change came from the use of the database; and, in the application, all the accesses to the database come from only a class that supplies a connection to the database.
    In this way I think that I could have (in a local net) a "server application" that has the database embedded inside it.
    Furthermore, some client applications (running in different computers of the net) could get access to the database through the connection that comes from an instance of the class that, in the "server application", is made to provide the connection to the database.
    I think this could be a good idea...
    But I don't have practice with distributed applications and I would ask some suggestion about the way to realize my modification.
    (in particular how to get and use, in the "client applications", the instance of the class that give the connection to the database from the "server application").
    I would have some help..
    thank in advance
    regards
    tonyMrsangelo.

    tonyMrsangelo wrote:
    I have to change a standalone program to do it working on a local net.
    the program is prepared for this adjustment, because the only problem for this change came from the use of the database; and, in the application, all the accesses to the database come from only a class that supplies a connection to the database.
    In this way I think that I could have (in a local net) a "server application" that has the database embedded inside it.
    Furthermore, some client applications (running in different computers of the net) could get access to the database through the connection that comes from an instance of the class that, in the "server application", is made to provide the connection to the database.
    I think this could be a good idea... Which is why JEE and implementations of that exist.
    But I don't have practice with distributed applications and I would ask some suggestion about the way to realize my modification.
    (in particular how to get and use, in the "client applications", the instance of the class that give the connection to the database from the "server application").
    You can't pass a connection from a server to a client. Nothing will do that.
    As suggested you can create a simple RMI server/client set up. Or use a more feature rich (and much more complex) JEE container.
    RMI is simple enough for its own tutorial
    [http://java.sun.com/docs/books/tutorial/rmi/index.html]
    JEE (previously called J2EE) is much more complex and requires books. You can get a brief overlook from the following
    [http://java.sun.com/javaee/]

  • Flash Vars is not working when we accessing from other class files

    Hi all, I'm currently developing a flex application where i
    need to pass the data from the flash vars to the other class files
    instead of the main actionscript class file.
    Does any body know how i should go about doing that?? you can
    see this below code : please help me out if u know how to solve
    testnew2.as file
    package {
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew2 extends Sprite {
    public var
    xmlfile:String=String(root.loaderInfo.parameters.lists);
    public function testnew ():void{
    package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew extends testnew2 {
    public function testnew () {
    var myText:TextField = new TextField();
    // this assumes that you are going to pass in an id variable
    // on the end of the myFile.swf?id=12345 or
    // use FlashVars in the HTML parameter list for instance
    // 'FlashVars', 'id=123456', 'width', '1024',
    myText.text = new testnew2().xmlfile;
    addChild(myText);
    but if we access in same file it is working fine:
    package {
    import flash.text.TextField;
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    public dynamic class testnew extends Sprite {
    public function testnew () {
    var myText:TextField = new TextField();
    myText.text = String(root.loaderInfo.parameters.lists);
    addChild(myText);

    Pass the data into the main app, then from there either pass
    it into the sub-components or use
    Application.application.parameters, or bind to the values.
    Tracy

  • Creating an instance of a class at runtime?

    Does anyone know how to create an instance of a class at RunTime? For example, I want to load classes from a JAR file at RunTime, and then create instances of certain classes of each JAR. I ask this because I do not see how to create an instance of one of those classes the traditional way, SomeClass var = new SomeClass(). I am pretty sure that someone out there has done this and succeeded in doing it. All of the post on this stuff only talk about loading the class from a JAR file, but I have already loaded them using URLClassLoader�s findClass() method. I have also created an instance of the class that findClass() returns using newInstance(), but newInstance() returns an object of type Object. How can I convert this object to an object of type SomeClass? You cannot cast it because the compiler will complain due to the import statement issue. So if you cannot include the import statement because that classpath does not exist, then how the heck would you cast the newInstance() object into a SomeClass object?

    You can cast the returned object to the type you need...that is what I do in my applet. The trick is that you must get the instance of the applets class loader (or you get a classCastException). Pay attention to this line below - that's the real key here.
    "// Get a reference to the applets own classloader"
    protected CBaseQuestionnaireFile m_BaseObject = null;// declared up front
    m_BaseObject = loadAndRunClass("com.cpm.dataentry.questionnaire.CQuestionnaireFile");// fully qualified base object
    Here is the load and run method:
       CBaseQuestionnaireFile loadAndRunClass(String classname)
          com.cpm.common.base.CBaseQuestionnaireFile questBase = null;
          Class cClass = null;
          try
             // first we open the jar file with the classes we need
             String[] aJarList = new String[10];
             // Questionnaire format file
             File fURL1 = new File(GetMainFrame().m_strQuestionnaireFileName);
             URL url1   = new URL(fURL1.toURL(),"");
             URL urlNew = new URL("jar:" + url1.toExternalForm() + "!/" );
             // Server base class directory
             String strServerDirectory = "http://" + GetMainFrame().m_strHost + "/APPLETS/";
             File fURL2 = new File(strServerDirectory);
             URL url2 = new URL(fURL2.toURL(),"");
             URL urlNew2 = new URL("jar:" + url2.toExternalForm() + "!/" );
             // Local base class directory
             String strLocalDirectory = CSystem.GetBasePath() + "/Research/bin/";
             File fURL3 = new File(strLocalDirectory);
             URL url3 = new URL(fURL3.toURL(),"");
             URL urlNew3 = new URL("jar:" + url3.toExternalForm() + "!/" );
             File fURLBase = new File(CSystem.GetBasePath() + "/Research/bin/base.jar");
             URL urlBase = new URL(fURLBase.toURL(),"");
             URL urlNewBase = new URL("jar:" + urlBase.toExternalForm() + "!/" );
             File fURLControl = new File(CSystem.GetBasePath() + "/Research/bin/controls.jar");
             URL urlControl = new URL(fURLControl.toURL(),"");
             URL urlNewControl = new URL("jar:" + urlControl.toExternalForm() + "!/" );
             File fURLUtil = new File(CSystem.GetBasePath() + "/Research/bin/utlities.jar");
             URL urlUtil= new URL(fURLUtil.toURL(),"");
             URL urlNewUtil = new URL("jar:" + urlUtil.toExternalForm() + "!/" );
             // Determine where to look
             URL[] urlList = null;
             if(GetMainFrame().m_isStandalone == false) {
                // From a browser
                CSystem.PrintDebugMessage("Running as an applet");
                if(GetMainFrame().m_bOnLineMode == true) {
                   // On line
                   CSystem.PrintDebugMessage("*** On Line Mode ***");
                   urlList = new URL[2];
                   urlList[0] = urlNew;
                   urlList[1] = urlNew2;
                else {
                   // Off line
                   CSystem.PrintDebugMessage("*** Off Line Mode ***");
                   urlList = new URL[4];
                   urlList[0] = urlNew;
                   urlList[1] = urlNewBase;
                   urlList[2] = urlNewControl;
                   urlList[3] = urlNewUtil;
              else {
                 CSystem.PrintDebugMessage("*** Stand Alone Mode ***");
                 urlList = new URL[1];
                 urlList[0] = urlNew;
    CSystem.PrintDebugMessage("Question file/path: " + GetMainFrame().m_strQuestionnaireFileName);
            // Set the wait cursor
            GetMainFrame().SetWaitCursor();
            // Get a reference to the applets own classloader
            Class myClass = getClass();
            ClassLoader appletClassLoader = myClass.getClassLoader();
            // Call our multi-jar class loader
            JarClassLoader jarLoader = new JarClassLoader(urlList,appletClassLoader);
    CSystem.PrintDebugMessage("CPM Test - passed Jar Loader" + jarLoader.toString());
             // Load the classname from the jarfile
             try
                  cClass = jarLoader.loadClass(classname);
             catch(ClassNotFoundException cnfe)
                Object[] optionsConfirm = { "Ok" };
                JOptionPane.showOptionDialog(GetMainFrame(),"Questionnaire file is either damaged or has been tampered with.", "Questionnaire File Error",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsConfirm, optionsConfirm[0]);
                GetMainFrame().m_strQuestionnaireFileName = "";
                // Clear the wait cursor
                GetMainFrame().ClearWaitCursor();
                return null;
             Class cSuperclass = cClass.getSuperclass();
    CSystem.PrintDebugMessage("Test Superclass type is: " + cSuperclass.toString());
             Object o = cClass.newInstance();
    CSystem.PrintDebugMessage("Test plain class type is: " + o.toString());
             // Never remove this line of code
             // without it, a crafty user could use our load routine
             // to load/and run some nasty code
             // This test makes SURE that *ONLY* questionnaires get opened
             // and their methods get called
             if(o instanceof com.cpm.common.base.CBaseQuestionnaireFile)
                // Create the object
    CSystem.PrintDebugMessage("Test Is instance of CBaseQuestionnaireFile");
    CSystem.PrintDebugMessage("CPM Test - Casting to Base Class");
                questBase = (com.cpm.common.base.CBaseQuestionnaireFile)o;
    CSystem.PrintDebugMessage("CPM Test - Getting languages from questionnaire");
                GetMainFrame().GetLanguagesFromQuestionnaire(questBase);
    CSystem.PrintDebugMessage("CPM Test - Setting locale from Questionnaire selection");
                questBase.SetQuestionnaireLocale(GetMainFrame().m_locale);
    CSystem.PrintDebugMessage("CPM Test - Initializing Questionnaire");
                questBase.Initialize();
                questBase.InitializeCards();
              else
                Object[] optionsConfirm = { "Ok" };
                JOptionPane.showOptionDialog(GetMainFrame(),"Questionnaire file is either damaged or has been tampered with.", "Questionnaire File Error",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsConfirm, optionsConfirm[0]);
                GetMainFrame().m_strQuestionnaireFileName = "";
                // Clear the wait cursor
                GetMainFrame().ClearWaitCursor();
                return null;
          catch (Exception e)
              exDialog.showForThrowable(e.toString(),e);
         // Clear the wait cursor
         GetMainFrame().ClearWaitCursor();
         // Set MouseListener Pointer
    //     questBase.SetMouseListenerPointer(GetMainFrame().m_mouseListener);
         return questBase;
       }

  • Managing Multiple threads accessing  a single instance of a class

    Hi,
    i have to redesign a class, say X, in such a way that i manage multiple threads accessing a single instance of the class, we cannot create multiple instances of X. The class looks like this:
    Class X{
    boolean isACalled=false;
    boolean isInitCalled=false;
    boolean isBCalled=false;
    A(){
    isACalled=true;
    Init(){
    if(!isACalled)
    A();
    B();
    C();
    isInitCalled=true;
    B(){
    if(!isACalled)
    A();
    isBCalled=true;
    C(){
    if(!isACalled)
    A();
    if(!isBCalled)
    B();
    }//end of class
    Init is the method that would be invoked on the single instance of this class.
    Now i cannot keep the flags as instance variables coz different threads would have differrent status of these flags at the same time, hence i can make them local, but if i make them local to one method, the others won't be able to check their status, so the only solution i can think of is to place all the flags in a hashtable local to method INIT AND INITIALIZE ALL OF them to false, as init would call other methods, it would pass the hashtable reference as an additional parameter, the methods would set the flags in the hashtable and it would be reflectecd in the original hashtable, and so all the methods can have access to the hashtable of flags and can perform their respective checks and setting of flags.
    This all would be local to one thread, so there's no question of flags of one thread mixin with the flags of some other thread.
    My question is :
    Is this the best way, would this work?
    In java, everything is pass by value, but if i pass the hashtable reference, would the changes made inside the called method to the hashtable key-value would be visible in the original hashtable declared inside the calling method of which the hashtable is local variable?

    In Java object variables are passed "by copy of reference", and primitive variables "by value".
    The solution with HashMap/Hashtable you suggest is ok, but I think you should read about ThreadLocal class:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

  • How to port a Sebel BI Dashboard from one instance to other instance

    Hi,
    I am in search of find a way to port the Oracle Sebel BI Dash board from one instance to other. When we complete the Dash board in a test instance how can we port it into to production.. is there any way to port the bash board are we need to develop it again in the production.
    Thanks
    Abdul Hafeez Shaik

    Identify the "class=MyStyle" string in the MTML code, and use the Multi-File Find and Replace feature to step through each topic and change the specific instances to "class=MyOtherStyle." (I doubt that you'll want to "Replace All".)
    Sorry, there's no silver bullet!
    Good luck,
    Leon

  • How can I write an instance of a class in a static variable

    Hi !
    I have an instance of a class
    Devisen dev = new Devisen();
    In an other class I have a static method and I need there the content of some variables from dev.
    public static void abc()
    { String text=dev.textfield.getText()
    I get the errormessage, that the I cannot use the Not-static variable dev in a static variable.
    I understand that I cannot reference to the class Devisen because Devisen is not static I so I had to reference to an instance. But an instance is the same as a class with static methodes. (I think so)
    Is there a possibility, if I am in a static method, to call the content of a JTextField of an instance of a class ?
    Thank you Wolfgang

    Hallo, here is more code for my problem:
    class Login {
       Devisen dev=new Devisen();
    class Devisen {
       JTextField field2;
       if (!Check.check_field2()) return; // if value not okay than return
    class Check {
       public static void check_field2()
         HOW TO GET THE CONTENT OF field2 HERE ?
    One solution ist to give the instance to the static function, with the keyword "this"
    if (!Check.check_field2(this)) return;and get the instance
    public static void check_field2(Devisen dev)BUT is that a problem for memory to give every method an instance of the class ? I have 50 fields to control and I dont want do give every check_method an instance of Devisen, if this is a problem for performance.
    Or do I only give the place where the existing instance is.
    Hmm...?
    Thank you Wolfgang

  • How to call a instance method without creating the instance of a class

    class ...EXCH_PRD_VERT_NN_MODEL definition
    public section.
      methods CONSTRUCTOR
        importing
          value(I_ALV_RECORDS) type ..../EXCH_VBEL_TT_ALV
          value(I_HEADER) type EDIDC .
      methods QUERY
        importing
          I_IDEX type FLAG
          i_..........
        returning
          value(R_RESULTS) type .../EXCH_VBEL_TT_ALV .
    Both methods are instance methods.
    But in my program i cannot created instance of the class unless i get the results from Query.
    I proposed that Query must be static, and once we get results we can create object of the class by pasing the result table which we get from method query.
    But i must not change the method Query to a static method.
    Is there any way out other than making method Query as static ?
    Regards.

    You can't execute any instance method without creating instance of the class.
    In your scenario, if you don't want to process your method of your class, you can check the instance has been created or not.
    Like:
    IF IT_QUERY IS NOT INITIAL.
      CRATE OBJECT O_QUERY EXPORTING......
    ENDIF.
    IF O_QUERY IS NOT INITIAL.
    CALL METHOD O_QUERY->QUERY EXPORTING....
    ENDIF.
    Regards,
    Naimesh Patel

Maybe you are looking for

  • Maintenance View

    Hi experts,      How can I check if a Z table have a maintenance view and if not have one how can I transport it? Thanks for the help!

  • LDAP Autoaddressing not working in Mail

    I have LDAP directory services set-up in Mail and it works perfectly when doing look ups directly from Address Book. It was working fine from within Mail at first but I seem to run into times when the autoaddressing feature does not work in Mail at l

  • Attaching a note to a contact in address book

    I like to takes notes detailing my conversations after I speak to my clients. Is there a quick way to take notes and attach that note to a contact in my address book? Ideally it would create a date and timestamp. Thanks in advance.

  • AI Acquire Waveforms High and Low Limit

    Hey everybody, I am currently working with Labview 7.1 and a daq card. I am collecting 4 channels and using ai acquire waveforms to do this. I want to have different high and low voltage limits for each channel though. Is there a way to do this with

  • Safari has stopped allowing access to sites that require login/password?

    Why is Safari preventing me entering sites that require a "login/passowrd"? Firefox has no such problem (though it was similar for some sites until clearing the cache) No similar process for Safari...?