How to refer to an object from within a handler

So I have a mouse listener that is attached to multiple objects as so:
  for (int i = 0; i < Grids.size(); i++) {
Grids.get(i).addMouseListener(new GameMouseListener());
}Now the problem I have is I need to know which of the Objects activated the handler
obviously this wont work since the var "i" is not defined inside the class and was only used in the previous for loop.
how to I know using the Handler Which Specific Object has been clicked on.
public class GameMouseListener implements MouseListener {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (Grid.get(i).isSelected()) {
                Grid.get(i).unselected();
            } else {
                Grid.get(i).selected();
        @Override
        public void mousePressed(MouseEvent e) {
        @Override
        public void mouseReleased(MouseEvent e) {
        @Override
        public void mouseEntered(MouseEvent e) {
        @Override
        public void mouseExited(MouseEvent e) {
        }

user10689232 wrote:
So I have a mouse listener that is attached to multiple objects as so:No, you have grids.size() amount of listeners, each listening to one object. Just pass the i along to the listener:
new GameMouseListener(i); // and create that constructor

Similar Messages

  • How to refer to enclosing instance from within the member class?

    Hi
    How to refer to the enclosing instance from within the member class?
    I have the following code :
    import java.awt.*;
    import java.awt.event.*;
    public class MyDialog extends Dialog
         public MyDialog(Frame fr,boolean modal)
              super(fr,modal);
              addWindowListener(new MyWindowAdapter());
         public void paint(Graphics g)
              g.drawString("Modal Dialogs are sometimes needed...",10,10);
         class MyWindowAdapter extends WindowAdapter
              public void windowClosing(WindowEvent evt)
                   //MyDialog.close(); // is this right?
    In the above code, how can I call the "close()" method of the "Dialog" class (which is the enclosing class) from the inner class?
    Thanks in advance.
    Senthil.

    Hi Senthil,
    You can directly call the outer class method. Otherwise use the following way MyDialog.this.close(); (But there is no close() method in Dialog!!)
    If this is not you expected, give me more details about problem.
    (Siva E.)

  • How to refer to JNDI PROVIDER_URL from within Tomcat Web app

    Can anyone provide a clear description on how to refer to a "Provider_URL" relative to the web application root for which a Java Class resides within? My issue is as follows. I've looked through the JNDI tutorial and the Tomcat JNDI How-To's and I'm still unable to find a solution.
    I'll elaborate:
    I have a "PROVIDER_URL" class variable defined as:
    private String PROVIDER_URL = "file:/C:/development/MyProject/MyWebApplication/WEB-INF/properties";I initialize my JNDI context within the class:
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    properties.setProperty(Context.PROVIDER_URL, PROVIDER_URL);
    context = new InitialContext(properties);
    cpds = (ConnectionPoolDataSource) context.lookup(baseName);
    ...The above example works fine. My question is given my web app's directory, how do I refer to "MyWebApplication/WEB-INF/properties" in a relative manner so that if I move my web application to a different server, the directory path does not affect my deployment and I dont have to hardcode the current path? Does this need to occur in the "server.xml" file? Can you provide a URL to an example?
    Your suggestions are appreciated...thanks.

    try to give
    http://localhost:8080
    or the app server based port address.

  • How to transport an LSMW object from dev to Quality and to Production?

    hi All,
             Could any one please specify how to transport the lSMW object from developmen to Quality and finally to Production?
    Thanks in Advance.
    Regards.
    Abhilash.

    Hi,
    The "cleaner" way is using normal transport procedure via "Extras->Generate Change Request".
    This will transport the entire project though, not possible to transport a single object this way.
    step by step
    1. Run Tcode LSMW in source system.
    2. in the menu bar choose Extras-->Export. Now give the filename and save in your desktop.
    3. Now login to destination system. again execute LSMW.
    4. Now goto Extras-->Import.Give your file which was downloaded earlier.
    5. Now tool bar click on import with diffrent name option and give your new project and subprojectname.
    6. Now execute all steps.
    Also refer the below link
    http://help.sap.com/saphelp_crm50/helpdata/en/da/a22506a3291b418b759524b278dcde/content.htm
    Please reward points if it helps
    Thanks
    Vikranth

  • How can you move the objects from one server to another?

    how can you move the objects from one server to another?

    Hi,
    Collecting objects for Transporting
    1. rsa1->transport connection
    2. left panel choose 'object type', middle panel choose 'infocube' and 'select objects'
    3. then choose your infocube and 'transfer'
    4. will go to right panel, choose collection mode 'manual' and grouping only 'necessary objects'
    5. after objects collection finished, create request
    6. If they are $TMP, then change the package.
    7. When you click the Save on the change package, it will prompt for transport. Here you can provide an existing open transport request number, or if you like here itself you can create a new one.
    8. You can check the request in SE09 to confirm.
    Releasing Transport Request  
    Lets say you are transporting from BWD to BWQ
    Step 1: In BWD go to TCode SE10
    Step 2: Find the request and release it (Truck Icon or option can be found by right click on request #)
    Note: First release the child request and then the parent request
    Steps below are to import transport (generally done by basis )
    Step 1: In BWQ go to Tcode STMS
    Step 2: Click on Import queue button
    Step 3: Double Click on the line which says BWQ (or the system into which transport has to be imported)
    Step 4: Click on refresh button
    Step 5: High light the trasnport request and import it (using the truck icon)
    Transport
    http://help.sap.com/saphelp_nw2004s/helpdata/en/b5/1d733b73a8f706e10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/0b/5ee7377a98c17fe10000009b38f842/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/media/uuid/224381ad-0701-0010-dcb5-d74236082bff
    Hope this helps.
    thanks,
    JituK

  • How do I move an object from one photo to another and then change the scene, i.e.  winter to sum?

    How do I move an object from one photo to another and then change the scene, i.e.  winter to summer?

    OK.
    Open the picture with the new scene. This will be your canvas.
    Open the picture with object A, select it with one of the selection tools, go to Edit>copy
    Go back to the new scene/canvas, Go to Edit>paste
    Repeat for object B
    Use the move tool to position A & B, each on its own layer. Use the corner handles of the bounding box to resize, if necessary
    You should have 3 layers: Background layer, and the 2 layers with A & B
    Note: It's best if the resolution of the 3 picture files is the same value.

  • How to call a COM object from an Oracle Form?

    Hi All,
    Pls advice. How to call a COM object from an Oracle Form?
    Thanks.

    try asking the "Form" forum

  • How do I create an object from a filename?

    I'm traversing directories and storing a list of files in a File array. Then I traverse the array looking at the extension of the file. If it is .java then I would like to instantiate it as a class so that I may pass the new object to another function which will examine its methods. I've tried Class.forName(file.getCanonicalPath()) and it throws a ClassNotFound exception. How can I create an object from a valid filename, please?

    Rick_Avlonitis wrote:
    If it is .java then I would like to </snip>.java files contain source code, they can't be "instantiated". Class.forName() takes a classname as parameter, i.e. "mypackage.MyClass". A class name is not a file name, and it doesn't have an extension. As stated in the other reply, you'll need to have the class on your class path.

  • How to pass arraylist of object from action class to jsp and display in jsp

    I need to do the following using struts
    I have input jsp, action class and action form associated to that. In the action class I will generate the sql based on the input from jsp page/action form, create a result set. The result set is stored as java objects in a ArrayList object.
    Now I need to pass the arraylist object to another jsp to display. Can I put the ArrayList object in the request object and pass to the success page defined for the action? If this approach is not apprpriate, please let me know correct approach.
    if this method is okay, how can I access the objects from arraylist in jsp and display their property in jsp. This java object is a java bean ( getter and setter methods on it).
    ( need jsp code)
    Can I do like this:
    <% ArrayList objList = (ArrayList)request.getattribute("lookupdata"): %> in jsp
    (***I have done request.setattribute("lookupdata", arraylistobj); in action class. ***)
    Assuming the java object has two properties, can I do the following
    <% for (iint i=0. i<objList.size;I++){ %>
    <td> what should i do here to get the first property of the object </td>
    <td> what should i do here to get the first property of the object </td>
    <% }
    %>
    if this approach is not proper, how can I pass the list of objects and parse in jsp?
    I am not sure what will be the name of the object. I can find out how many are there but i am not sure I can find out the name
    thanks a lot

    Double post:
    http://forum.java.sun.com/thread.jspa?threadID=5233144&tstart=0

  • How can I access applet paramters from within javafx?

    I have a simple javafx applet from the clock tutorial, but I would like to initialise this from parameters that are specified in the <APPLET> tag, for exaple <param name="timeZone" value="America/Los_Angeles">My question is how do I access this parameter from within javafx?
    Thanks,
    Phil

    I'm looking for the same answer, if anybody knows ... ;)

  • Accessing java objects from within javascript

    Hello,
    Anyone with an idea of a useful toolkit for accessing java objects from within javascript will be much appreciated.
    Thanks in advance,
    Antana.

    What do you mean by accessing Java objects? Do you mean interacting with an applet via JavaScript? Something else?

  • How do I remove an object from the foreground of a photo eg a fence?

    How do I remove an object from the foreground of a photo eg a fence?

    What version of Photoshop?
    If CC then try here
    Learn Photoshop CC | Adobe TV

  • How do you remove an object from a picture.  Newbie to program CS6

    how do you remove an object from a picture.  Newbie to program CS6

    Well, generally you can use the clone-stamp tool for one, shortcut is S. It basically allows you to take data from any part of the image and copy that over. What I do is draw on a new layer above the one to modify- make sure you select Sample:"This layer and below" in the top toolbar when doing so. Other ways include blending something on top of the object too, using different blending modes. Painting over it works too at times (rarely). It'd be easier if we knew a specific case though...

  • How to refer to other objects?

    Greetings,
    I'm not sure how objects should refer to other objects.
    Example:
    Class Automobile needs to refer to objects from other classes, namely to tires, color, motor and company.
    So, the way I would do this in C++ or VB is to store all tire, color, motor and company objects into arrays and then store Integer ids in class automobile refering to the index. Like
    tiresId
    colorId
    motorId
    companyId
    So if I would like to know the name of the company of this automobile, I would have to do the following:
    company(automobile.getCompanyId).name
    I'm not sure however if this is the right OOP-Way of doing it. Should I rather put object references into class automobile instead so that I would only have to
    automobile.getCompany ?
    The problem I have with this solution is that I have to read and store the automobile data into files and while it's pretty easy to store an integer-id I'm not sure on how to store object references. They are a little "obscure" to me on this point.
    Thanks in advance for any advice.

    if you just want to save the type of company, color and so on for every automobile, i think integer ID is a good way,
    similar to the existing Color-class with constants:
    Color.BLACK, Color.RED, ..
    the way with references would also work, then all referenced objects will be saved too,

  • How to refer the BPM objects in Project to Project.

    Hi,
    I have created some BPM obejects in Project A, i want to use the same Obejct in Project B.
    How to refer the Objects across the Project.
    Could pls some one help me on this.
    Regards,
    Anandh P

    Here are a couple ways to share BPM Objects across projects.
    You can right mouse click a BPM Object in a project and then export it. This will create a zip file that can then be imported into a Module in another project.
    There is a new feature in 10g that allows you to create a dependency between projects. If you define one project to be dependent on another then it can use the BPM Objects found in the other one. To do this, right mouse click the project's name in the Project Navigator tab -> Project Preferences -> Dependency -> select the project you want to be dependent on from the dropdown. This is based on the project's currently visible in the Workspace directory (the directory you are prompted for when Studio first starts up).
    Dan

Maybe you are looking for

  • Assistance with Printing to Zebra QL220 using the LabVIEW report VI

    I currently am trying to use the LabVIEW report VI to output a formatted set of strings to the above mentioned printer. The UMPC hardware that runs the developed application is bare bones XP box and doesn't' have MS office installed I use the LV new

  • Music in slideshow starts at the beginning with last 10 photos.

    I recently created a slideshow with iphoto and exported it to iDVD to burn using 5 songs that were faded in and out using Garageband. Even though i set the images to 3 seconds of viewing and to fit all images to the music, the last 10 images the musi

  • Multiple Electronic Signatures

    I have just upgraded from Adobe 9 Professional to Adobe 11 Professional.  Although I have saved several signature appearances, I am unable to chose which one to insert when signing documents.  Is there a way to do this without having to "change" or "

  • How do I create this rollover effect?

    http://www.gunnar.ca/layout.htm I am attempting to design a site. I have the idea for the layout and have created it using tables at the address above. I realize I should be using css to create the layout instead of tables. First of all - is this lay

  • Branching OO Design Question

    I have this ADT; call it Foo. It has a basic set of functionality; call that functionality X. It also has some satellite functionality; call that functionality Y and Z. Putting X, Y, and Z into one class Foo isn't really option, as it would result in