?
Solved

java application which will respond to clicks on the image

Posted on 2006-04-15
11
Medium Priority
?
247 Views
Last Modified: 2010-03-31
i want to create a java application which will respond to clicks on the image.i want to know any tutorial or help i can get to get started with it.
0
Comment
Question by:zolf
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16459733
Put the image in a JLabel and add a MouseListener to the label
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16459736
label = new JLabel(new ImageIcon("x.jpg"));
label.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent e) {
            // Respond
      }
});
0
 
LVL 92

Expert Comment

by:objects
ID: 16459762
yuou could use a JButton with an ActionListener.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:zolf
ID: 16459774

      thanks for your replies.let me explain in more details.for example i get
      an image of a stero system and if i clcik on the play button it should play
      ,if i click on the stop button it should stop playing....so on.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16459789
You need to add buttons maybe over the image? If so, implement your own JPanel and override the paintComponent method to display the image
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 220 total points
ID: 16459791
If you mean respond to events on the image of buttons, you need to calculate the coordinates and respond if the mouse iw within them
0
 
LVL 2

Accepted Solution

by:
amol_chaudhari earned 280 total points
ID: 16462810
hi zolf,
        there are two cases
1. if u have seperate images of play and stop buttons then u can display that images on the seperate panel or label or button and add actionListener to them.....
using mouse adapter u can catch the click event and then for each seperate compenent u can write seperate code.....

2. if all the buttons are on single image then u must keep track of XY boundaries of that buttons.. display image on panel or label add actionLIstener then using mouse adapter u can catch the mouse click event, in that routine get the xy cordinate of the mouse on image as
 event.getX();
 event.getY();

compare it with the boundaries of the button and take action accordingly....

for more help on mouse handling see.....
http://java.sun.com/docs/books/tutorial/uiswing/events/mousemotionlistener.html
0
 

Author Comment

by:zolf
ID: 16466940


shivspk those sites do not open which you mentioned.do they open for you???
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16488815
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question