Detect a Click on an image

Is there any way to detect when a user clicks on a certain image in an applet. If I have image1 and image2 and the user clicks on image1 can I trap that event somehow?

I am creating an image using getImage and then
displaying it in the paint method.I'll assume that you are painting the image inside some subclass of java.awt.Component, instead of a paint methos declared somewhere else.
You should add a MouseListener to your class. This MouseListener needs to know the location and size of the image. I'll assume you already have methods in your Component to get the location of the image [upper-left corner, as a java.awt.Point object, relative to the Component] and the size of the image [as a java.awt.Dimension object]
During Component initalization, or possibly the image initialization add the following code:
myComponent.addMouseListener(new MouseAdapater() { public void mouseClicked(MouseEvent me) {if (me.getSource() == myComponent && (new Rectangle(getImageLocation(), getImageSize()) ).contains(me.getPoint()) ) { /* Do the stuff you need to do on the click*/ } });Of course, it probably should be better formatted and you may want to add additional constraints to performing the action like SwingUtilities.isLeftMouseButton(me) and/or me.getClickCount() == 1.
Since this MouseListener is an anonymous inner class, you'll need to make any variables it needs access to final or create accessor methods for them.
You could also implement the MouseListener as a named inner class. Then it would have access to all (non-private?) variables, not just those that are final.

Similar Messages

  • Clicking Sound When Images Load

    Greetings,
    I am getting a faint clicking noise whenever images load onto the screen - such as on the internet, or when an application opens. Also, I get the sound when I scroll on a web page with my external mouse. Any ideas? Many thanks!

    Albert:
    • Are you able to detect the location of the clicking sound? That is, does is come out of the speakers, or from somewhere else on the computer, like under the keyboard etc.?
    • Do you have the original HDD in the computer? While booted from the computer go to Apple Menu > About this Mac > More Info > Hardware > ATA. On the right pane at the top you will see ATA device tree. The first ATA Bus entry is your internal HDD. Select it, then go to the second section and doubleclick on the ID, copy and paste is in your response.
    The sounds you describe are most commonly associated with the internal HDD and we need to eliminate that as the cause. If it seems to be coming from the speakers, turn the sound off, and see if it makes a difference.
    Good luck.
    cornelius

  • My cursor will not move on my MacBook Air. I've forced a shutdown, but it still won't move, and now I can't move the cursor to click my user image to log in. What should I do?

    My cursor will not move on my MacBook Air. I've forced a shutdown, but it still won't move, and now I can't move the cursor to click my user image to log in. What should I do?

    Trackpad does not work properly

  • Tried to reinstall iPhoto library from external hard drive, it shows that the photos and events are there but there are no thumbnails and if you click on an image or video nothing comes up.

    My hard drive crashed recently and we took it to apple to get repaired. The apple employees said that they would have to replace the hard drive but they didn't have the equipment to get the data off my hard drive. So I took it to a computer store who had the right equipment after a month and a half of waiting they finally got all the data off my hard drive and put it on an external hard drive (Seagate Expansion Portable Drive). I then took it back to apple who replaced the hard drive. Now I'm in the process of reinstalling everything. I have never done a Time Machine back up or backed my laptop up to . Which I now will do very often once I've reinstalled everything. I have reinstalled all of my desktop images and folders as well as my iTunes library with no issues. However when i went to reinstall my iPhoto library it came up blank. I then Rebuilt the library several times and this was the result.
    It shows that the photos and events are there but there are no thumbnails and if you click on an image or video nothing comes up.
    Please help i have three years worth of images from holidays on here and would be devastated if i lost them.

    iPhoto cannot find the thumbnails or the original pictures.
    Go to your iPhoto Library in the Pictures Folder.
    Right-click on it and from the resulting menu, choose 'Show Package Contents'.
    This will bring you inside the iPhoto Library package. There you should see a Folder called Masters. Within that, there should be folder containing your actual photos.
    Are they there?

  • Activating hyperlink on click of a image

    Hi,
    I want to connect a hyperlink with an image in MSA 5.0. So when I click on the image (which is a custom resourse), it should activate the hyperlink so that I can navigate to another tileset. I also want an example to do this. Can anyone help me in doing this?
    Thanks,
    Neha

    Hi,
    I am not sure whether the MSA event handling is supporting image controls.
    So I would suggest first to implement an (empty) event handler for this control, check in debug mode whether this event is called at all.
    If yes then the code should be quite similar as it is done 10000 times in MSA where another component is called. E.g. check the code for the onclicked event for control BP in activity tile actdeta2.
    It is always the same logic: Define and create a business query and hand over the result being a business collection to the hyperlink source which needs to be fired manually.
    Regards,
    Wolfhard

  • I upgraded to Maverick O/S and I can no longer right click on iPhoto images to find my photo files.  My photo files are not where they were before upgrade.

    I upgraded to Maverick O/S and I can no longer right click on iPhoto images to find my photo files.  My photo files are not where they were before upgrade.

    Have you checked the sorting settings to make sure they are as you expect?
    OT

  • How to disable save as option in forefox when we right click on the image?

    Hi Folks,
    Can somebody help to disable save as option when i right click on the image which is showing in the browser.

    Hi,
    '''sorry,it is impossible by code'''
    you can use addons.
    or
    you can disable while developing webpage using:
    <script language="javascript">
    document.onmousedown=disableclick;
    status="Right Click Disabled";
    Function disableclick(event)
    if(event.button==2)
    alert(status);
    return false;
    </script>
    Regards
    '''Deepak Krishnan'''

  • When I click on an image (photo) to view a gallery, when the gallery pops up all the frames are blank.

    Clicking on an image in Firefox takes me to a page with text but no other images. The image appears on the main page, such as an image in facebook that takes you to a photo gallery, but when clicked on, the pop-up has text and, it seems, a frame for an image, but no image. This happens all over the web, not just facebook.

    Any possibility this is a side effect of Bluhell Firewall? Those gallery overlays might look like advertising.
    To determine whether one of your extensions is involved, you could test some of the same pages in Firefox's Safe Mode. That's a standard diagnostic tool to deactivate extensions and some advanced features of Firefox. More info: [[Troubleshoot Firefox issues using Safe Mode]].
    You can restart Firefox in Safe Mode using
    Help > Restart with Add-ons Disabled ''(Flash and other plugins still run)''
    In the dialog, click "Start in Safe Mode" (''not'' Reset)
    Any difference?

  • Click on an Image to see the .flv in popup.

    Hi,
    I have done 90% of this project. All I want now is to swap
    image with .flv. In the project I have 9 pictures. When I click on
    either of them, the big picture opens in the pop up window and
    closes up when I click on it.
    What I want it to click on an image to open up the
    crosponding .flv rather then big image. Here is my code. Please
    help out.
    Thanks
    main.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical"
    verticalAlign="middle"
    backgroundColor="white">
    <mx:Style>
    global {
    modal-transparency: 0.9;
    modal-transparency-color: white;
    modal-transparency-blur: 9;
    </mx:Style>
    <mx:Script>
    <![CDATA[
    import mx.effects.Resize;
    import mx.events.ResizeEvent;
    import mx.events.ListEvent;
    import mx.controls.Image;
    import mx.events.ItemClickEvent;
    import mx.managers.PopUpManager;
    private var img:Image;
    private function tileList_itemClick(evt:ListEvent):void {
    img = new Image();
    // img.width = 300;
    // img.height = 300;
    img.maintainAspectRatio = true;
    img.addEventListener(Event.COMPLETE, image_complete);
    img.addEventListener(ResizeEvent.RESIZE, image_resize);
    img.addEventListener(MouseEvent.CLICK, image_click);
    img.source = evt.itemRenderer.data.@fullImage;
    img.setStyle("addedEffect", image_addedEffect);
    img.setStyle("removedEffect", image_removedEffect);
    PopUpManager.addPopUp(img, this, true);
    private function image_click(evt:MouseEvent):void {
    PopUpManager.removePopUp(evt.currentTarget as Image);
    private function image_resize(evt:ResizeEvent):void {
    PopUpManager.centerPopUp(evt.currentTarget as Image);
    private function image_complete(evt:Event):void {
    PopUpManager.centerPopUp(evt.currentTarget as Image);
    ]]>
    </mx:Script>
    <mx:WipeDown id="image_addedEffect" startDelay="100"
    />
    <mx:Parallel id="image_removedEffect">
    <mx:Zoom />
    <mx:Fade />
    </mx:Parallel>
    <mx:XML id="xml" source="gallery.xml" />
    <mx:XMLListCollection id="xmlListColl"
    source="{xml.image}" />
    <mx:TileList id="tileList"
    dataProvider="{xmlListColl}"
    itemRenderer="CustomItemRenderer"
    columnCount="4"
    columnWidth="125"
    rowCount="2"
    rowHeight="100"
    themeColor="haloSilver"
    verticalScrollPolicy="on"
    itemClick="tileList_itemClick(event);" />
    </mx:Application>
    CustomItemRendere.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="
    http://www.adobe.com/2006/mxml"
    horizontalAlign="center"
    verticalAlign="middle">
    <mx:Image source="{data.@thumbnailImage}" />
    <mx:Label text="{data.@title}" />
    </mx:VBox>
    gallery.xml
    <?xml version="1.0" encoding="utf-8"?>
    <gallery>
    <image title="Flex"
    thumbnailImage="assets/fx_appicon-tn.gif"
    fullImage="assets/fx_appicon.jpg" />
    <image title="Flash"
    thumbnailImage="assets/fl_appicon-tn.gif"
    fullImage="assets/fl_appicon.jpg" />
    <image title="Illustrator"
    thumbnailImage="assets/ai_appicon-tn.gif"
    fullImage="assets/ai_appicon.jpg" />
    <image title="Dreamweaver"
    thumbnailImage="assets/dw_appicon-tn.gif"
    fullImage="assets/dw_appicon.jpg" />
    <image title="ColdFusion"
    thumbnailImage="assets/cf_appicon-tn.gif"
    fullImage="assets/cf_appicon.jpg" />
    <image title="Flash Player"
    thumbnailImage="assets/fl_player_appicon-tn.gif"
    fullImage="assets/fl_player_appicon.jpg" />
    <image title="Fireworks"
    thumbnailImage="assets/fw_appicon-tn.gif"
    fullImage="assets/fw_appicon.jpg" />
    <image title="Lightroom"
    thumbnailImage="assets/lr_appicon-tn.gif"
    fullImage="assets/lr_appicon.jpg" />
    <image title="Photoshop"
    thumbnailImage="assets/ps_appicon-tn.gif"
    fullImage="assets/ps_appicon.jpg" />
    </gallery>

    You just set the image's visible property = false and make
    sure you have a VideoDisplay underneath the image.

  • Every time I right click on an image and select Download image Firefox crashes . I have reinstalled; uninstalled and deleted folders and then reinstalled; added

    Every time I right click on an image and select Download image Firefox crashes . I have reinstalled; uninstalled and deleted folders and then reinstalled; added no plugins; checked I can DL the same images in IE-works good.I use Win7 pro and it works in other profiles in Windows 7. I created a new profile in Windows and that worked for about 2 months and now that has gone the same way as my admin profile has done. I deleted the sqlite download file-still same prob..Please help. I use Firefox 13.0.1

    That sounds very frustrating.
    By the way, does it say "Download image" or "Save Image As"? Just checking whether you have an add-on downloader in the mix that might be relevant. If you do have an add-on, try using the built-in command.
    Do you also crash if you save from here:
    right-click page > View Page Info > Media tab > (select image) > Save As
    I assume you have seen this article and tried these things: [[What to do if you can't download or save files]].
    Have you tried the new Reset feature in Firefox 13? This duplicates certain key data from your active settings folder into a new one, bypassing some add-ons and custom settings. Your plugins will still be active, but could be disabled manually if you like.
    More information in this article: [[Reset Firefox – easily fix most problems]].
    If the new settings folder has the same problem, you can switch back if you like using Firefox's Profile Manager.
    Does it make any difference?

  • Why am I not able to export NEF files to Photoshop from Lightroom to edit. This is new. When I right click on an image, the export to PS option is not selectable.

    Why am I not able to export NEF files to Photoshop from Lightroom to edit. This is new. When I right click on an image, the export to PS option is not selectable. I've never had this happen before. I haven't used it for a few weeks, so maybe there's an update (Mac or otherwise) that's screwing things up? HELP!

    I have an Edit In - Photoshop option, but not an Export - Photoshop option.
    Obviously to have right-click Edit In to work, the photo you're right-clicking on needs to be selected.  I assume this is not the problem, and that the photo is selected.
    Mavericks 10.9.3 has a problem where the Users folder is hidden, and you need to update iTunes to fix it, but it's been a few weeks since this happened so hopefully you're up-to-date and the Users folder isn't hidden anymore.
    If you can't get things to work, I'd uninstall LR and uninstall Photoshop, then install Photoshop, and update it, then install LR and update it, as a way to get any wayward security or other OS-level things reset.

  • I installed Mavericks yesterday and have now got problems with QuarkXpress 9. Every time I click on an image and try to move it the application crashes. Anyone had similar problems or got any suggestions?

    I installed Mavericks yesterday and have now got problems with QuarkXpress 9. Every time I click on an image and try to move it the application crashes. Anyone had similar problems or got any suggestions?

    Hi Guys
    Updated my 2 imacs to Maverick yesterday. Schoolboy error on my part not checking if there were problems with any programmes before I did.
    Quark is now a nightmare with no short term answer on the way. As a Quark user for over 20 years this is just another reason to hold your hands up and say OK Indesign you win I will have to learn how to use you and Quark will be a distant memory.
    I am told there will probably be no solution to getting quak 9 running on Maverick and that you will need to update to 10 in about 2-3 weeks to get back to normal. Having spent a few bob on 2 versions of 9.5 only in Feb this year i didn't really want to upgrade yet.
    So its cough up to carry on using Quark or learn Indesign.
    I have lost faith in Quark as they are quick to send me e-mails asking me to upgrade to this and that version, why didn't they send one out saying do not upgrade to Maverick. Perhaps they know there loyal follwing will uograde to 10 and will generate a nice little bonus before Xmas.
    Lots to do today and will now take 10 times longer to do it. Is this 2013 or 1974!!!!!
    If anyone hears of a solution please post ASAP

  • Ps cs6 on mac. since installing yosemite, when working on an image if i want to change tool, via shortcut of wacom pen click, i now have to click on the image title bar, how can i fix this please?

    ps cs6 on mac. since installing yosemite, when working on an image if i want to change tool, via shortcut or wacom pen click, i now have to click on the image title bar, how can i fix this ?

    @Naiks, having suffered through unsuccessful synching attempts for Calendar and Contacts myself, l would suggest you try the following:
    UNINSTALL iCloud control panel from your PC. Seems silly, but do it.
    Go into Outlook, and look at the very top menu. Click FILE, then ACCOUNT SETTINGS, then click the popup box.
    You will see a list of all your email accounts. Make sure that ONE of them has a checkmark against it. If not, select the account your want as your default, and click "set as default.
    Exit out of Outlook and reboot your machine.
    Now reinstall iCloud, check CALENDAR and CONTACTS, and do as instructed when prompted.
    Reboot for good luck and now launch OUTLOOK. All that remains is to locate your iCloud Contacts and Calendar files, and make them your default.
    IMPORTANT: Don't panic if you can't find your contacts -- they're there. Click CONTACTS and you'll see you have several available contact files. Locate the one label "iCloud" in grey type. Right-click on it, select PROPERTIES, then click the Outlook Address Book tab. Check the box that says something like "Make this my default Outlook Address Book." Keep clicking "apply" and "okay" until you've exited out of the dialog box maze.
    You may have to do something similar with your Calendar files. I dd not, but if you need to, do it.
    Everything should now sync pretty seamlessly.
    I didn't have the exact same problem as you, but my dilemma was close enough. Good luck!
    Arthur P. Johnson

  • How do i create a gallery page that you can click on an image, expand it and move left or right to see more images?

    How do i create a gallery page that you can click on an image, expand it and move left or right to see more images?

    You may use slideshow widgets to achieve this. For more details : Adobe Muse Help | Working with Slideshow widgets

  • Tile list - clicking on the images to change get different movies to play

    I am buiding an application where I just got the tile list working with images loaded in.  My question is there a way to click on the images that are loaded in to get them to do things, such as change a video, in my video player?
    Thanks!

    Using the 'adjust date and time' setting is the best way to syncronise the photos from all your cameras. However as you say this merely puts them all in the correct order chronologically.
    If there are photos that you feel would be best somewhere else in an album other than in date order, it may depend on how many as to which is the best option for you. If it's only a few you may wish to adjust the date/time on these few manually so they fit in with the rest where you want them.
    If you have a lot of photos you want in a different order to the order by date, or you really don't care about what date/time is used and just want them in the order you want them in, then 'batch change' is the best option.
    From the view menu, select 'sort photos - manually', drag the photos around until they are in the order you want, select all of them. Now select the batch change option and choose 'Date' from the 'set' options, type in a date and time for the first photo, it can be anything but it's probably a good idea to choose something close to the original date, then check the box 'Add'. You can keep the value set at 1 minute or enter any value you want, it may be more realistic to divide the length of your holiday by the number of photos you have to calculate a value, but it really isn't necessary. Clicking OK will adjust all the dates without affecting the title or description and the photos will now show on the Apple TV in that order.
    Just to be sure iTunes is updated, you may want to go to the advanced menu/choose photos to share in iTunes and deselect the album, apply, reselect the album and apply again.

Maybe you are looking for

  • Can you tell if it is a display problem or logic board problem

    I have a 17 inch aluminum mac book pro. I bought it from a reseller on ebay in February. Recently I have been having some display issues. It has taken it longer and longer for screen to come back on from sleeping and the other day it did not come bac

  • Toshiba 46xv640UZ 46" - DVR causes TV HDMI to go to static

    I have a 46xv640uz 46" connected to a Cox Communications DVR using HDMI. Whenever i switch to "On Demand" or switch from a DVR recording to regular cable there is a "pause" of 2-3 seconds.  During this timeframe the TV switches to "static".  Just li

  • How To create a WebDAV repository...

    Is there any documentation available for creating a WebDAV repository and making it available for TREX to index and search. I tried to follow the help doc in creating such a repository but the WebDAV rep. I created does not show up in the KM reposito

  • Edge Animate doesn't respond to trigger, auto-plays to the end while previewing in the browser.

    I've this strange problem with EA. I was working on a project which was doing pretty well. You may see it over here. This afternoon I wanted to make some progress, opened the file, clicked preview in browser. What I saw was the auto-play of animation

  • RotoScoping help

    Hello again. I was up most of the night tryign to understand this. I have a clip of a guy walkign over a sand dune here, http://s111.photobucket.com/albums/n159/larswik/?action=view&current=sn51_forgro und.jpg In the background I have dark mountians