Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem whith Canvas and mouse events

Posted on 2003-03-13
6
Medium Priority
?
259 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
5 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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 Month13 days, 22 hours left to enroll

580 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