Putting an Image in my CoordinateArea

Hey,
I would like to be able to place an image within my CoordinateArea, and I also want this image to be able to respond to being clicked on when the mouse is clicked between certain co-ordinates. Here is my code so far...
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.event.MouseInputListener;
public class tourWelby extends JFrame {
JLabel label = new JLabel();
JPanel panel = new JPanel();
Point clickPoint = new Point();
Point cursorPoint = new Point();
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
          JFrame frame = new JFrame("TourWelby");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          tourWelby controller = new tourWelby();
          controller.buildUI(frame.getContentPane());
          //Create and set up the content pane.
          frame.getContentPane().setBackground(Color.BLACK);
          // Create the menu bar
          JMenuBar menu = new JMenuBar();
          menu.setBackground(Color.BLACK);
          //Build the menus.
          JMenu file = new JMenu("File");
          file.setBackground(Color.BLACK);
          file.setForeground(Color.WHITE);
          JMenu test = new JMenu("Test");
          test.setBackground(Color.BLACK);
          test.setForeground(Color.WHITE);
          // Install the menu bar in the frame
          frame.setJMenuBar(menu);
          menu.add(file);
          menu.add(test);
          //Display the window.
          frame.pack();
          frame.setVisible(true);
          frame.setResizable(false);
          frame.setSize(800,700);
     private void buildUI(Container container) {
container.setLayout(new BoxLayout(container,
BoxLayout.PAGE_AXIS));
CoordinateArea theArea = new CoordinateArea(this);
container.add(theArea);
label = new JLabel();
          label.setBackground(Color.BLACK);
          label.setForeground(Color.WHITE);
resetLabel();
container.add(label);
public void updateCursorLocation(int x, int y) {
if (x < 0 || y < 0) {
cursorPoint = null;
updateLabel();
return;
if (cursorPoint == null) {
cursorPoint = new Point();
cursorPoint.x = x;
cursorPoint.y = y;
updateLabel();
public void updateClickPoint(Point p) {
clickPoint = p;
updateLabel();
public void resetLabel() {
cursorPoint = null;
updateLabel();
protected void updateLabel() {
String text = "The cursor is at ";
               if (cursorPoint != null) {
text += "("
+ cursorPoint.x + ", " + cursorPoint.y + ") ";
label.setText(text);
     public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
public static class CoordinateArea extends JComponent implements MouseInputListener {
Point point = null;
tourWelby controller;
Dimension preferredSize = new Dimension(800,700);
public CoordinateArea(tourWelby controller) {
this.controller = controller;
               setBorder(BorderFactory.createMatteBorder(3,3,3,3, Color.RED));
addMouseListener(this);
addMouseMotionListener(this);
public Dimension getPreferredSize() {
return preferredSize;
//Methods required by the MouseInputListener interface.
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (point == null) {
point = new Point(x, y);
} else {
point.x = x;
point.y = y;
controller.updateClickPoint(point);
repaint();
public void mouseMoved(MouseEvent e) {
controller.updateCursorLocation(e.getX(), e.getY());
public void mouseExited(MouseEvent e) {
controller.resetLabel();
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseDragged(MouseEvent e) { }
How do I go about putting an image in the CoordinateArea and making it clickable? Do I need to use an ImageIcon?
Thanks in advance.

Hi again everyone. I've gone and rethought my code and started again from scratch. Here is what I have come up with..
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.*;
public class tourWelby extends JFrame  implements MouseListener {
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mousePressed(MouseEvent e) { }
public void mouseDragged(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
public static void main (String args[]) {
     new tourWelby();
     public tourWelby() {
     super("Test");
    Container content = getContentPane();
     Point clickPoint = new Point();
     Point cursorPoint = new Point();
     JLabel label = new JLabel();
     label.setText("Test");
     label.setBackground(Color.WHITE);
     label.setForeground(Color.WHITE);
     JPanel theArea = new JPanel();
     theArea.setPreferredSize(new Dimension(800, 600));
     theArea.setBackground(Color.BLACK);
     theArea.add(label);
     theArea.addMouseListener(this);
     addMouseListener(this);
     content.add(theArea);
         pack();
         setVisible(true);
     setResizable(false);
}Basiclly now, I think I need to add the mouseListener to the JPanel. However I'm not sure where I need to put the "public void updateCursorLocation" code and such that I had before (before, I used some samples of code from another program, and I wasn't entirely sure how it worked). If someone could help me (again!) with getting the MouseListener to change the label on the JPanel, to reflect where the cursor is (as in my previous code) I would again, be most appreciative. Thanks.

Similar Messages

  • I can't figure out the Keynote title option. I'm a newbie so forgive my ignorance. I want to put an image in the swing arm, but I can't figure it out.

    I even tried opening in Motion and inserting it there, but when I bring it back to fc it's not there. I also want to change the background to an image or at least solid white. When I put an image in the Dropzone it doesn't show up. Any help would be GREATLY appreciated!

    To change the title background to use a clip in the drop zone, do just as Jim said.
    Also, place the clip that want to appear in the "swing arm" right below the title in the timeline.

  • I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the Mac, they are all locked.  Help, please.  Thanks

    I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the mac, they are all locked.  Help, please!

    "I plugged the external into the Mac and moved a folder of images onto the desktop.  It looks like it went from read only to not locked.  Is this possible?"
    Yes, that's exactly what happened. If you buy another drive, you could copy from your existing drive to the new and your files will be read/write. The new drive will have to be formatted as an HFS drive (that's the Mac's format). If you need to format it, you use Disk Utility which is in the Utilities folder on your Mac. Be careful with that -- it wipes out whatever is currently on the drive. Make sure you format the right drive.
    I keep all my images on an external drive, too. In fact, I have two matching drives and sync them so I always have a backup.

  • How to put an image in a data grid in Flex Builder 2

    Hi All,
    I need to populate a data grid with some text data received
    from a web service and, in a particular column of the datagrid, I
    have to put an image depending of a specific data returned me by
    the web service.
    It seems that there is the possibility to add an image in
    data grid column with the cellRenderer properties, but this
    property is available only for ActionScript 3.
    I'm developing an application in Flex Builder 2 that run
    ActionScript 2 and cellRenderer properties is not available. Is it
    right?
    If no, I will can use this cellRenderer properties in my
    application. Please, can you show me an example?
    If yes, there is a way to insert an image in datagridcolumn
    with ActionScript 2?
    Thank you very much
    Regards

    Flex Builder 2 uses Actionscript 3.
    You will need to write a renderer for for this column.
    There are a lot of examples of datagrids with images in them.
    here is one from the livedocs
    http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=cellrenderer_072_28.html

  • How to put an image in the popup help of a page item?

    I am using APEX 2.2. I want to put an image in the help text of a page input item.
    This is the help text:
    Some help text....
    <p><img src="&APP_IMAGES.auto_lov.jpg" /></p>This is rendered as:
    <p><img src="wwv_flow_file_mgr.get_file?p_security_group_id=0&p_flow_id=103&p_fname=auto_lov.jpg" /></p>As you can see, the application id is not returned.
    If I put exactly the same text in a html region, the image is correctly displayed:
    <p><img src="wwv_flow_file_mgr.get_file?p_security_group_id=844129086577364&p_flow_id=103&p_fname=auto_lov.jpg" />So, is it possible at all to put in image in the popup help text of a page item?

    I solved it by putting the jpg file in an images directory on the web server instead of in the database. Not really what I want, but it works.
    <p><img src="&IMAGE_PREFIX./apps/auto_lov.jpg" /></p>

  • How do I put an image in the background of a JDesktop?

    I have made a program that has a JDesktop. Just need to know the coding to put an image in the background of the JDesktop. Any suggestion?

    Add a JLabel that holds a picture to it. Make sure it's in the back layer.

  • How do I put an image in a spry tabbed panels tab

    Hello All,
    I am currently working on a site with Spry Tabbed Panels.
    One thing I'm not sure how to do is to put an image in each of the selecting tabs. I've done it before and I've forgot. I also have a site with an example of what I would like to do.
    http://emilymagnuson.com
    The tabs on this site were created with images inside of them. And I would like to know how to do it. I would like to make it work so the image changes when you click, hover, and deselect.
    Thank you.

    To put an image in the foreground, add it to your HTML code:
    <li class="TabbedPanelsTab" tabindex="0">
    <div style="margin-top:9px;"><img src="your_image_here.jpg">Contact</div>
    </li>
    Nancy O.

  • I don't know how to put an image instead of colours for background

    I am usin awt and I want to put an image from my HD as background instead typical colours. How can I do this?

    Ah. This one is mine. You can try making a Frame anonymus class and overriding paint(). Do you know how to get your picture?
    {=^)                                                                                                                                                                                                                                                                           

  • How can I put an image in the page header so that it will be repeated on every page?

    Hi to everyone!
    I want to create a Pages template with the logo of our company in the page header.
    I'd like to put that image (logo) in the page header so that it will be repeated on every page but it will not modify the content of the page.
    Anyone know how to achive this, or something similar without have to copy-paste that image every time we add a page to the document?
    Thanks in advance

    Takashi,
    Turn off the Page Headers (not absolutely necessary, but since you don't need it, why not)
    Put your Graphic on the page and make the following settings:
    Then Insert > Text Box and make the same settings as for the graphic.
    Place your "Header text" in the text box and arrange the box and graphic as you want them. Move both to Section Master using the Arrange menu.
    Jerry

  • Can't put photos/images in email (new email) in Mail

    Okay, this is weird. I can no longer drop a .jpg image (or any other) into a new email message. (This is with my prefs set to compose in Rich Text Format, yes. And this is 10.5.2.)
    If I try to drag it from the Photo Browser into a message, sometimes it appears as if it's going into the email message, but it does not appear in the body area. Sometimes it bounces back to the Photo Browser, as if the email message is an object that cannot receive a dropped image file. And if I try to drag an image file from Finder into the body of the message, I can get either behavior again.
    Either way, I can't put an image/photo/graphic file into an email message.
    Has anyone else seen this behavior and figured out a fix for it?

    An addendum...
    Just to make it really weird, I can drag image files from the Photo Browser to the Mail icon in the Dock and make a new email, and then I can see the image in the mail message. And once I have that e-mail message created by dragging an image the Dock icon, I can drag other images/files from the Photo Browser into the same new message and see them.

  • How to put an image in Webdynpro

    HI,
    I want to piut a logo in Webdynpro view.I have put the image(logo) in proper place.But I am not able to fetch the data from that folder in to my WD view.
    pLease suggest
    Regards
    -Sandip

    Hi Sandip,
    You want to embed a TextView UI element and an Image UI element in a Group UI element, kindly have a look :-
    http://help.sap.com/saphelp_nw70/helpdata/EN/5d/1d353ed106ec2ce10000000a114084/frameset.htm
    URL Generation Service :-
    http://help.sap.com/saphelp_nw70/helpdata/EN/9e/a073001903c9419592b14c2aa63669/frameset.htm
    Hope this is useful.
    Regards,
    Anagha

  • Putting gif images on my site

    I have a few questions about putting gif images on my site.
    How can I easily create a gif image from my favourite photos and put them on my site by using iWeb ?
    Can I do it by using Preview or QT Pro ?
    Thanks

    Flash is great as long as your audience is able to view flash animation on their systems. I've had trouble with PC users having Flash 7 viewer installed and not being able to view newer Flash 8 material. In a corporate environment, upgrading to each successive update is like pulling teeth.
    Having said that, I don't think animated GIFs are too hard to work with. There is a limitation with color depth and I think various programs produce gifs of varying quality. But everything I've seen have been more than acceptable for web viewing.
    I have a few examples on my website below. Check out the entries for "Goodbye Daisy," "Sporting My New Duds," and "An Important Message." I used Adobe ImageReady.
    ==> www.DirtDoog.com <==</a>    
    Place A Virtual Pin On Putt-Putt's GuestMap!

  • Best practice to put overlay images on video?

    Hello community!
    I would like to know what's the best way to put overlay images on videos, like ads ( actually ads )
    I'd like to animate them and all that stuff, the thing is I believe I know how to do it, but I'm not sure.
    On the one side I image that i should create a plugin to manage them, and a MediaElement to put them inside.
    Supposably this mediaElement ( Ads ) should run in Parallel with the video.
    I'm still investigating on that but I would appreciate any help!
    Thanks!

    Yes, you're on the right track.  See this sample app for some additional guidance:
    http://opensource.adobe.com/svn/opensource/osmf/trunk/apps/samples/framework/LayoutSample/
    The sample demonstrates the layout of an overlay bug by placing a VideoElement and ImageElement in a ParallelElement.  To map this to the ad use case, you might have the ImageElement encapsulated within a plugin.

  • How can I put another image without its associated sound on an audio (without its image) ?

    IMovie 11 : how can I put one image without its associated sound on an audio (without its image) ? thanks

    Hi
    As iMovie doesn't orient after Time - but only after Video/Photo clips is this not so easy to do.
    I use black photos as Dummy clips - and put them into a new project first
    then I add the Music I want
    Then I drop the Video-clip (that I realy want) ontop of the black dummy photo - Where it's supposed to be - THEN IF advanced tools are selected (in iMovie preferences) there will be a Drop-Down menu and here I can select to do a Cutaway - and select not to add the audio from it (or in wave-form just silence it out)
    Yours Bengt W

  • Indesign master page putting the images on the master in teh middle of some of my pages but not all

    indesign master page putting the images on the master in teh middle of some of my pages but not all =[

    We'll need some more information, and probably a few screen shots, like the master page and one of your pages where the image is not showing.

Maybe you are looking for

  • Upgraded to Snow Leopard and now iPhoto 11 crashes.

    iPhoto worked fine until I upgraded my iMac to Snow Leopard (10.6.8) and installed iLife '11. Now when I put the SD card from my Panasonic Lumix DMC-FH20 into the reader, iPhoto (9.1.5) immediately gives me the spinning beach ball until I Force Quit.

  • How to create a write operation in file adapter dynamically in to a folder.

    Hi all i want to explain my scenario... i am giving input to file adpter which is having read operation,and i am giving that input to an human work flow.i had two operations reject and resubmit in my task flow...i am editing the task with some change

  • Caps Lock

    I have a mid 2009 15in Mackbook Pro and before I had an issue with Safe boot I noticed everything wrote was in caps without me selecting the caps lock button.

  • Joining to domain on same computer account name

    Hi,  I have a critical server. I need to reinstall it with clean installation an same name. I don't have permissions to delete computer account from AD, but I have permissions to add to domain. If I remove server from domain reinstall it and will joi

  • How to change the primary node for a resource group. Solaris cluster. 3.2

    I have searched for hours to try to find this answer. I want to change the primary node of a resource group. example. log-rg runs on node1.this.com it will list node1.this.com first when you do clrg status. But we run it on node2.this.com A reboot wi