?
Solved

Problem whith Canvas and mouse events

Posted on 2003-03-13
6
Medium Priority
?
252 Views
Last Modified: 2011-04-14
When i add this Canvas to a JFrame it will not fire the mouse events...
Any sugestions?

public class Area  extends Canvas implements MouseListener
{  
   
  /**Constructor
   */
  public Area()
  {
    super();    
    this.setBackground( new Color(128, 255,0, 0));
    this.repaint();  
    addMouseListener(this);
  }
 //-------------------Event handlers--------
  public void mouseClicked(MouseEvent e)
  {
    System.out.println("test");
  }  
  public void mouseEntered(MouseEvent e){}
  public void mouseExited(MouseEvent e){}
  public void mousePressed(MouseEvent e)
  {
    System.out.println("test2");
  }
  public void mouseReleased(MouseEvent e){}
}
0
Comment
Question by:flalar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 300 total points
ID: 8127012
I'd subclass JPanel, override the paintComponent() method and add that (instead of using canvas) :-)

ALSO!  Make sure you are adding it to the frame's contentPane

DONT DO:

  frame.add( myComponent ) ;

DO DO:

  frame.getContentPane().add( myComponent ) ;

---------

Hee hee...I said do-do >_<
0
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 8127031
Can u show the code that adds the "Area" canvas?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8127220
Have you sized Area?
0
 

Expert Comment

by:CleanupPing
ID: 9058716
flalar:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9762629
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to TimYates

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 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