Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-02-2007, 06:15 AM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Question question to know the event in which image?

hi,
i have a question:ex: if i have 4 images (image1, image2, image3, image4) and i want message1 appear if i click in image1, message2 appear if i click in image2, message3 appear if i click in image3, and message4 appear if i click in image4

how can I know if the mouse event in image1 or 2 or 3 or 4 without using the position of these images in the board?

i want a method to tell me the event in which image...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-04-2007, 01:46 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Use the getSource() method.

Java Code:
  1. public void actionPerformed(ActionEvent e){
  2. if(e.getSource().equals(image1)) {
  3.     //show message 1
  4. } else if(e.getSource().equals(image2)) {
  5.     //show message 2
  6. }
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-04-2007, 05:18 PM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Default

thank you,, and i will try it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-05-2007, 08:33 AM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Unhappy

but why if i click in the image1 in this code the message didn't appear and the event didn't work??

Code:
import javax.swing.JApplet;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;



public class SS extends JApplet
{
private ImageIcon image1;

public void init(){
image1 = new ImageIcon("instruction.jpg");
}

public void paint(Graphics g){ //paint

 image1.paintIcon(this,g,0,0);

  addMouseListener(

    new MouseAdapter()
	 {//MouseAdapter

	 public void mousePressed(MouseEvent e){ //press

    if(e.getSource().equals(image1)) {  //msg

    System.out.printf("YOU CLICK IN IMAGE1");

	 JOptionPane.showMessageDialog( null, "GOOD MORNING ", 
    "HI",JOptionPane.INFORMATION_MESSAGE  );

} //msg

}//press
	 }//MouseAdapter

	 );//addMouseListener

} //paint




}//SS
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-06-2007, 05:29 AM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Default

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-06-2007, 07:52 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Not sure at the moment, but you may need to implement MouseListener
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-09-2007, 06:03 PM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Default

can you try my code please???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-10-2007, 11:29 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

You added a mouse listener to image1.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-11-2007, 04:52 AM
stack stack is offline
Learning Programmer
 
Join Date: Mar 2007
Posts: 39
Rep Power: 7
stack is on a distinguished road
Unhappy

Quote:
Originally Posted by Sidewinder View Post
You added a mouse listener to image1.
i didn't understand what did you mean??
please explain more..
why if i click in image1 in this code the message didn't appear and the event didn't work??

Last edited by stack; 09-11-2007 at 08:51 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-11-2007, 11:26 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

I meant to say - You never added a mouse listener to image1.

Simple doing a
Java Code:
  1. addMouseListener()
Adds the mouse listener to the root content panel. You have to add the mouse listener to the object you want it to listen to a la
Java Code:
  1. image1.addMouseListener()
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make image straight - Photoshop ahsan16 Photoshop Tutorials 56 07-30-2008 04:11 PM
Resize Images And Maintain Original Sharpness AfTriX Photoshop Tutorials 7 04-20-2007 10:55 AM
PHP Image NeedHelp JavaScript and CSS 1 04-20-2007 10:00 AM
Resize an Image Blaze C# Programming 3 09-22-2006 07:58 PM
Question about Form's On_Closing event hoser2001 C# Programming 3 08-22-2006 08:25 AM


All times are GMT -5. The time now is 12:11 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads