11 Replies Latest reply on Nov 18, 2010 2:02 PM by darrylburke

    JPanel Listener doesn't work in a JFrame...

      Hi, all:

      Sorry for my silly question. Not quite familiar with Java GUI.

      My code looks like:
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      public class JPanelInJFrame  extends JFrame {
           JPanel panel;
             public JPanelInJFrame() {
                     panel = null;
             public void start() {
                  panel = new JPanel();
                  panel.addMouseListener(new MouseAdapter() {
                          public void mousePressed(MouseEvent e) {
           public static void main(String[] args) {
                JPanelInJFrame frame = new JPanelInJFrame();
                frame.setSize(200, 200);
      I guess there must be a very silly fault in my implementation, but where is it? Why the JPanel's listener doesn't work for JPanel itself? How to revise it?

      Thank you so much in advance.

      Best Regards

      Edited by: jiapei100 on Nov 18, 2010 12:49 AM