Creating Objects with String name

How can i create an object, but just having the name as String?
Like, instead of creating like JInternalFrame obj = new MyInternalFrame(), do it like JInternalFrame obj = createObject("MyInternalFrame") ( i just gave createObject as example, ignore it)...
Does anyone knows how to do it? Because i have several windows, and by clicking, i dont want to be with a lot of if clauses checking each one to se wich one is the ritgh class to call...
Tks,
Bruno

You need the Class class in package java.lang, specifically class (static) method forName() and instance method newInstance():
JInternalFrame obj =
    (JInternalFrame) Class.forName("MyInternalFrame").newInstance();

Similar Messages

  • Is it posible to create objects with different names dinamically?

    Hi,
    I'm creating an app that manages different wireless nodes in a network and I was thinking that I could create a class called Node which would have a constructor that every time I created an object Node, I would pass the address and some other data about the Node and the constructor will save all that data and also create a unique ID for every Node object.
    Now the problem is that I need to be able to discover all the nodes in my network every time the user clicks a Ping button. So every time the users clicks Ping I need to do a ping and create as many Node objects as nodes I have in my network. The thing is I don't know how to make it create the node objects with different names so after I've created all the nodes objects I can refer to one of them.
    Something like this.
    int Id=0;
    id++;
    Node node+Id = new Node();
    I think its not possible to do something like that. If it isn't how can I do to refer to one of the objects I've created?
    Thanks.

    Twistx77 wrote:
    Thanks to both of you. I'll check out the Link and if I can't find the solution there I'll make the array , I don't know how I didn't think about doing that. There are two collections you should study specifically:
    First you have the ArrayList which in essense is a growable array. This means you don't have to decide in advance how big it can be.
    Second there's the HashMap. It's sometimes called an associate array. Such an array doesn't have fixed position indexes like an ordinary array. Instead each index (called key) is associated with a value but the keys don't have any particular order. Still, given a certain key, finding the corresponding value in a HashMap is almost as fast as an array access.

  • Create an object with the name passed in as a string argument to a method

    Hi,
    I am sorry if it's too trivial for this forum , but I am stuck with the following requirements.
    I have a method
    void abc(String object_name, String key, String value)
    method abc should first check if there exists in memory a hashmap object with the name passed in as argument object_name.
    If yes ..just put the key and value there.
    if not , then create the hashmap object called <object_name> and insert the key/value there.
    Can anybody help me in the first step i.e, how to check if an object exists with the name passed in and if not then create it.
    Will getInstance method be of any help?
    Thanks in advance for your response.
    -Sub-java

    Dear Cotton.m,
    Thanks for your suggesstion. I will remember that.
    But somehow I have a strong belief that you still need to consult dictionary for exact meaning of the words like "upset" , "frustration" etc. Not knowing something in a language , that too as a beginner, does not yield frustration, but increases curiosity. And people like petes1234 are there to diminish that appetite.
    To clarify above, let me compare jverd's reply to my doubt with petes1234's.
    jverd said it cannot be done and suggested a work around (It was perfect and worked for me) While petes1234 , having no work in hand probably, started analysis of newbies mistakes.
    jverd solved my problem by saying that it cannot be done. petes1234 acted as a worthless critic in my opinion and now joined cotton.m.
    Finally, this is a java forum and I do not want to discuss human characteristics here for sure.
    My apologies if I had a wrong concept or if I chose a wrong forum to ask, where people like petes1234 or Cotton.m show their geekdom by pointing out "shortfalls" rather than clearing that by perfect examples and words.
    Again take it easy and Cotton.m , please do not use this forum to figure out others' frustration but be a little more focussed on solving others "Java related" problems :)
    -Sub-java

  • How to create directories with same name in different schemas

    I have two schemas on the same database.
    I am trying to create directories with same name, but different paths in both the schemas.
    When i created the directories in second schema, the directory paths of the first schema are automatically changed to the second path.
    Is there any solution to create directories with same name, but different path in two different schemas on the same database.
    Thanks,
    Sridhar.

    Hi,
    >>When i created the directories in second schema, the directory paths of the first schema are automatically changed to the second path.
    If you have removed the REPLACE clause of your create statement, then you would see that is not possible.
    SYSTEM> connect scott/tiger
    Connected.
    SCOTT> create directory mydir as '/tmp';
    Directory created.
    SCOTT> connect legatti/pwd
    Connected.
    LEGATTI> create directory mydir as '/tmp';
    create directory mydir as '/tmp'
    ERROR at line 1:
    ORA-00955: name is already used by an existing object
    LEGATTI> select owner,object_name,object_type,created
      2  from dba_objects where object_name='MYDIR';
    OWNER     OBJECT_NAME    OBJECT_TYPE         CREATED
    SYS       MYDIR          DIRECTORY           19/12/2007Cheers
    Legatti

  • Create Folder with the name of expense report number in SHAREPOINT ?

    Hi All,
    iExpence - In expense report confirmation page. There is custom link.
    Requirement
    When user click on link, system should create folder with the name of expense report number in SHAREPOINT and copy copies of expense receipts in the created folder in SHAREPOINT.
    Please suggest.
    Thanks,

    OAF no api as such for this kind of customization. Rather try developing some web service or something similar which can be invoked from the custom link to do the job.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                   

  • BI Platform: Parameter object with the name "URL_PARAM"... does not exist

    Hi,
    I'm facing this issue with only one dashboard in BI4 Platform. When trying to view it through the BI Launch Pad, I get the following error:
    "Parameter object with the name "URL_PARAM" and the index "0" still does not exist in the parameter 1[...]".
    I've seen this thread where a similar thing was reported with NetWeaver platform.
    My client as well as server versions are Release 1.4 SP0 Patch2 (14.0.5).
    Also, although some of the pictures referenced in the dashboard are not in the Public Folders on BI4. Could it be that it's not able to reference the images and hence not be displaying the whole dashboard?
    Please let me know if anyone has a solution to this.
    Thanks!
    - Sakshi Dhakad

    Hi,
    So here are the versions we currently have:
    SAP BO Design Studio (64 bit) - 14.1.0
    SAP BO Design Studio 1.4 for BI Platform - 14.1.0.349
    And on checking on Central Management Console, I get this:
    SAP BO BI Platform 4.1 Support Pack 5 Patch 2
    Version: 14.1.5.1568
    Also, I'm not sure if I installed an add-on or the patch. Based on these versions, could you tell me how to fix the issue ?
    Thanks!

  • Error creating Objects with Reflection

    This is the code:
    try{
         System.out.println("Restart - test 1 - sub == " + sub);
         c = Class.forName(sub);
         con = c.getDeclaredConstructor();
    catch(NoSuchMethodException e){
         System.out.println("Unknown event type\t" + e);
    }Output:
    Restart - test 1 - sub == Mouse
    Unknown event type     java.lang.NoSuchMethodException: Mouse.<init>()I have a Mouse class with a declared Constructor. Why can't it find the Constructor?

    SquareBox wrote:
    almightywiz wrote:
    Your code is trying to find the default constructor for your Mouse class. If you don't have a default constructor specified, it will throw the exception you encountered. What does your constructor signature look like?
    public Mouse(int weight){
         this.weight = weight;
    }How do I get the Constructor if it contains parameters?This is answered in your other thread: Creating objects with relfections And you even marked it correct!
    Please don't post the same question multiple times. It leads to people wasting their time duplicating each others' answers, and makes for a fractured discussion.
    Edited by: jverd on Apr 26, 2011 3:59 PM

  • Can we create objects with interface

    can we create objects with interface,if yes then where we implement the
    methods,can we type cast any object with inerface kind of object,if yes what kind
    of objects we can type cast

    can we create objects with interface,if yes then where we implement the
    methods
    Objects are created with classes, not interfaces, which are abstract.
    can we type cast any object with inerface kind of object,if yes what kind
    of objects we can type cast
    Objects may be cast to interfaces, but only if an object's class or one of its superclasses actually implements the interface.

  • Planning 9.3 Duplicate member error: An object with the name 0000 already e

    Hi All
    I have 5 dimensions in my Planning applications namesly, Company, State, Product, Entity and Account
    Company hase members called 0000(default) and 1000, 1001 etc
    I also want add my Entity default member as 0000, but when I tried to add the memeber in my entity dimension I'm getting the Error : An object with the name 0000 already exists: Please help me to fix this
    Thanks in Advance

    U won`t be able to add the duplicate item name to planning application untill it would be the 9.5 version.
    By the way, NotPlanning App`s nothing like as scanty - they has already an option "Allow duplicate item names" in 9.3 version..

  • Create Annotations with 'author' name tool property

    Philip Cord has kindly sent me this code that allows to create annotations with the "Author" tool property (older versions than CS3 couldn't get this on script listener - only on the CS3 script listener).
    Hope it helps anyone like me that can't have access anymore to CS3
    var colour = new SolidColor();
    colour.rgb.hexValue = 'ff00ff';
    selectNote(0);
    colourNote(colour);
    addAuthorToNote("Author Name");
    function colourNote(colour) {
    var Saturation = colour.hsb.saturation;
    var Brightness = colour.hsb.brightness;
    var Hue =colour.hsb.hue;
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( stringIDToTypeID('annotation'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble( charIDToTypeID('H   '), charIDToTypeID('#Ang'), Hue );
    desc3.putDouble( charIDToTypeID('Strt'), Saturation );
    desc3.putDouble( charIDToTypeID('Brgh'), Brightness);
    desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('HSBC'), desc3 );
    desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    function selectNote(number) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putIndex( stringIDToTypeID('annotation'), number );
    desc.putReference( charIDToTypeID('null'), ref );
    try{
    executeAction( charIDToTypeID('Shw '), desc, DialogModes.NO );
    }catch(e){}
    function addAuthorToNote(Author) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( stringIDToTypeID('annotation'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    desc2.putString( charIDToTypeID('Athr'),  Author);
    desc.putObject( charIDToTypeID('T   '), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
    function makeAnnotation(X,Y,Width,Height) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putClass( stringIDToTypeID('annotation') );
    desc.putReference( charIDToTypeID('null'), ref );
    var desc2 = new ActionDescriptor();
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), X );
    desc3.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), Y );
    desc2.putObject( charIDToTypeID('Lctn'), charIDToTypeID('Pnt '), desc3 );
    var desc4 = new ActionDescriptor();
    desc4.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), Width );
    desc4.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), Height );
    desc2.putObject( charIDToTypeID('Sz  '), charIDToTypeID('Ofst'), desc4 );
    desc2.putEnumerated( stringIDToTypeID('annotType'), stringIDToTypeID('annotType'), stringIDToTypeID('annotText') );
    desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('annotation'), desc2 );
    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );

    This is a bit more robust (it won't fall over if you have no images open or can't find the corresponding image) I've made it so if you have the thumbnail image open it will find the mannequin image and visa versa. Save the script to your PS scripts directory. In photoshop record an action that uses the script. Stop recording! Then you can run the script as an action.
    app.preferences.rulerUnits = Units.PIXELS;
    if (documents.length == 0)
        alert ("No documents open, dude!")
    else
        var dir1 = "Mannequin";
        var dir2 = "Thumbnails";
        // call the current document
        var tempDoc = app.activeDocument;
        // get the info out of the source doc
        var fileName = tempDoc.name;
        var filePath = tempDoc.path.toString();
        var fileNameAndPath = filePath + '/' + fileName;
        var tempDir = filePath.substring(filePath.lastIndexOf("/") +1, filePath.length);
        var goCode = false;
        var docName = fileName.substring(0,fileName.length -4);
        if (tempDir == dir1)
            var otherImagePath = filePath.substring(0, filePath.lastIndexOf(dir1));
            var tempFile  = decodeURI(otherImagePath + "/" + dir2 + "/" + fileName);
            goCode = true;
        if (tempDir == dir2)
            var otherImagePath = filePath.substring(0, filePath.lastIndexOf(dir2));
            var tempFile  = decodeURI(otherImagePath + "/" + dir1 + "/" + fileName);
            goCode = true;
        if (tempDir != dir1 && tempDir != dir2)
            alert("Cannot find matching image.")
            goCode = false;
        if (goCode)
            //open the other image
            var fileRef = new File(tempFile)
            if (fileRef.exists)
                app.open(fileRef);
            else
                alert("Matching file does not exist.")
    }// end doc check
    Hope this helps.

  • Creating objects with proper stereotypes

    Hi,
    I'm just trying to create Architecture Areas and Business Functions using VB. This all works as expected, besides of one small but important exception:
    I want to create Architecture Areas and Business Functions of a given type (Stereotype).
    When I create the Architecture Area or Business Function, assign the code and name, and then set the Stereotype, everything looks OK. The Stereotype is appearing on the symbol etc., but ... the graphical symbol differs from what we have configured for this element.
    In the script I'm doing it this way:
    L2Process = EamL2.ArchitectureAreas.CreateNew(PdEam.cls_ArchitectureArea)
    L2Process.SetNameAndCode Trim(L3SubSubFolder.Name), Trim(L3SubSubFolder.Code)
    L2Process.Stereotype = "Process"
    The Architecture Area is created, the Stereotype is assigned:
    But the graphical symbol is not the expected one, it"s rather the "default" one ...
    What I have configured is:
    Is there a way to create Architecture areas and Business Functions, so that the configured Custom Symbols are used? MAybe a parameter for CreateNew like in the CreateModel function, where we can set the Diagram Type?
    CreateModel(PdEAM.cls_Model, EvaluateNamedPath("%_MODELS%") + L3SubSubFolder.Name + ".eam" + "|" + "Diagram=CityPlanningDiagram", omf_DontOpenView)
    I can't find anything in the documentation in regards to this issue...
    Thanks,
    Rafal

    Hi Rafal,
    Could you try creating object directly in the collection using the GetCollectionBySteretype("Process") on model ?
    Something like:
    Dim processes
    Set processes = EamL2.GetCollectionByStereotype("Process")
    Set L2Process = processes.CreateNew()
    L2Process.SetNameAndCode Trim(L3SubSubFolder.Name), Trim(L3SubSubFolder.Code)
    This should assign stereotype at initialization and may be fix your issue...
    Marc
    PS. I did not check code, take care of potential typo.

  • Create Object with "Photoshop.Application"

    Cannot create an object reference to Photoshop CC using Excel 2011 and vba, is there missing files with the standard installation?

    Hi;
    I have been writing VBA code for many years and have always used Windows up till now, I am attempting to do things on a MAC I can easily do in Windows. I have for years used macros written by myself referencing Adobe Photoshop and also Microsoft Access from within Excel. I have used what is termed 'Late binding" to create objects for the above applications. I understand Access is not useable on the MAC but I believe I should be able to use the macros I have written with slight modifications for file locations. Typically nearly the first executable statement in these macros are as follows
    Dim appRef as Object
    set appRef = CreateObject("Photoshop.Application")
    the second statement when executed allows me the opportunity to use Photoshop (Versions 7 -> CS5 have been successful) to reference all the procedures and functions that would appear on the desktop when using Photoshop.
    According the scripting PDF manual for CS6 they use the same syntax for the VBScript examples. I believe this should work with Photoshop CC. I think when I installed the cloud version I opted for "Typical" installation" instead of maybe selecting "Custom Installation". How do I achieve the use of the above technique? As stated earlier I have used this since Photoshop 7. Any help would be greatly appreciated.
    Thank you,
    Robert Firman

  • Create object reference by name

    I wish to disable and enable a bunch of controls on the front panel. Instead of creating hard-wired property nodes, I wish to cycle through an array of string names of controls and set the corresponding control's property. Is it possible to create a reference on the fly based on a string? The reference will then be fed to a Property node. Or is there an alternative way for my problem?

    See the image below for a better example.
    This one provides a list of all the controls on the front panel.  See the names of the labels appears in the ArrayofCtrls.
    RayR
    You can create a subvi of this. Replace ThisVI by a control.  You then wire This VI from the calling VI.  Or, you can get fancy and wire a pathname to the appropriate function which replaces ThisVI in the above example.  You can then obtain front panel listings for other VI's.  The possibilities are alomost endless  
    Message Edited by JoeLabView on 01-08-2008 08:11 AM
    Attachments:
    _example.PNG ‏33 KB

  • Type cast with string name

    I have a hashtable full of Objects. I also have there type represented by a String. How can I typecast these Objects back to there type. i.e.
    String str = "helpme";
    str = (Object)str;
    String type = "String";
    can I use the var type to cast str back to a String;

    I've never used reflection before so my answer maybe way off from what you're looking for.... but to solve your problem on casting an Object to a type specified by a String variable you could use a case or if statement if you know what types are available ahead of time and call the appropriate methods to return your Object type.
    For example... You could create a method for each type you expect to return.
    public String getStringValue( Object obj ) {
         return (String)obj;
    public Integer getIntegerValue( Object obj ) {
         return (Integer)obj;
    public Byte getByteValue( Object obj ) {
         return (Byte)obj;
    }Then... depending on what the value of your String type variable is you can call the appropriate method that will return the Object type you're wanting.
    String type = "String";
    if( type.equals("String") )
         String yourStr = getStringValue(yourObject);
    else if( type.equals("Integer") )
         Integer yourInt = getIntegerValue(yourObject);
    else if( type.equals("Byte") )
         Byte yourByte = getByteValue(yourObject);This maybe not be the most efficient way especially since there can be potential errors but it can work assuming the String type is really representing the type of Object yourObject is.
    I don't know.. just a possible solution that popped in my head.
    .kim

  • How to reference objects with same name?

    Probably another easy one, but again, couldn't find the answer in old discussions...
    I have some objects with the same name on my form. Designer has made them unique by making an array out of them...object[0], object[1], object[2] etc. How can I reference the individual objects in javascript?  I tried the obvious by referencing them as an array, but to no avail.  I suppose it'd be just as easy, if not better, to just have unique names, but in this case, the objects are related and having them in an array would be handy.

    You can try like below.
         var oObject = xfa.resolveNode("Object[1]");
         xfa.host.messageBox("" + oObject.rawValue);
    Thanks
    Srini

Maybe you are looking for