Swing Mouse Event Propagation

Hello,
I'm developing my first Swing application.
One of the components is a thumbnail image panel (ext. JPanel) containing several other components (mostly ext. JLabel). I have the image panel receiving mouse events so as to allow the user to see when the image panel is 'in focus' (rollover effect basically) and to allow the image panel to be selected by clicking.
I added a tooltip to one of the contained labels, and it now 'consumes' my mouse enter/exit event so that now it is as if the label is not part of it's container. This is not what I want.
Is there not some simple way to allow mouse events to be listened for by a child component but yet to 'fall through' to a listener in the parent component?
Any insight into this little problem would be most appreciated.
Thanks.

You can listen to all MouseEvents generated:
Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()
     public void eventDispatched(AWTEvent e)
          System.out.println(e);
}, AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);You would then need to determine if the source component is a descendent of your main panel.

Similar Messages

  • Multiple JPanels on top of each all receiving mouse events

    I have multiple JPanels that are painted on top of each other. Each one has mouse listeners that listen for mouse enters, exits, etc. However, it appears that Swing is only propagating the mouse events for the most visible panel (the one that is on top of all of the others). Is there a way to configure Swing in such a way that all JPanels on the screen will get the mouse events, even if they aren't entirely visible on the screen?
    Thanks,
    -- Ryan

    Hi,
    You can implement mouse listener for panel and you can identify buttons in the panel with the mouse event of panel using MouseEvent.getComponentAt(MouseEvent.getPoint()) instanceof JButton or not.
    I hope this will help,
    Kishore.

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • Mobile IconItemRenderer - prevent event propagation

    Hello,
    I don't want anything to happen when an element is clicked or touched in a mobile itemRenderer extending IconItemRenderer.
    Isteand of overriding the drawBackground method and not listening for the change event, is there anyway of doing this faster, like preventing the event from propagating?
    Thank you.

    1. commitProperties seems fine
    2. I assume it would be faster since you avoid unnecessary drawBackground calls.  You might want to test to make sure.
    3. Correct, if you can't click on something it won't be able to fire a mouseDown event
    4. The mouseDown listener is added to the renderer in List.dataGroup_rendererAddHandler.  You could tweak it there, but that would require a subclass of List.  I typically find it easier to do from within the renderer via one of the two approaches I mentioned above especially when that changes based on the data in the renderer.
    5. The Flex SDK currently deals exclusively with mouse events.  See the "Mouse vs. Touch Events" section of this spec for more information: http://opensource.adobe.com/wiki/display/flexsdk/Mobile+List%2C+Scroller+and+Touch

  • Event propagation in mediumweight components

    Hi,
    There's an article "Mixing heavy and light components":
    http://java.sun.com/products/jfc/tsc/articles/mixing/
    It explains mouse event handling:
    "Mouse events on a lightweight component fall through to its parent; mouse events on a heavyweight component do not fall through to its parent. "
    What about mediumweight components? Are mediumweight components receiving mouse events like lightweight or like heavyweight components?
    Is it possible to infer how the mouse events are propagated just by using JComponent.isLightweightComponent()?
    Kari

    What do you mean by sub-app .  Are you using modules ?  For regular situations you can set "bubbles" to true on the event.

  • Need More Mouse Events

    [http://forums.sun.com/thread.jspa?messageID=10811388|http://forums.sun.com/thread.jspa?messageID=10811388]
    During search over net I found the above thread and it seems to be describing the same problem which I am also facing. For my application also I need to capture all the mouse events while dragging. I tried the soluiotn mentioned at this thread to solve this problem by overrinding the below method in several ways:
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,AWTEvent newEvent);
    Even after several attempts, I could not succeed. Can you please suggest how to do that. I was not able to reply to above thread so creating this new thread.
    Thanks

    I wanted to see if a timer based approach does indeed produce a smoother curve than just simply listening for mouse drag events. What I came up with below was the resulting test code. Lo and behold, using a timer does indeed produce a smoother curve. But it wasn't because it was capturing more mouse positions, it was because it was capturing less. Ain't that a kicker? Another interesting thing is that according to the source code, coalesceEvents is a no-op. The documentation, however, would have you believe that it coalesces mouse events as I thought it did.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.GeneralPath;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.BorderFactory;
    public class Test {
        private static class TimerBasedPanel extends JPanel implements MouseListener {
            private GeneralPath line;
            private Timer mousePosQuerier;
            private Component mouseEvtSource;
            private int pointCount;
            public TimerBasedPanel(Component mouseEventSource) {
                mousePosQuerier = new Timer(15, new ActionListener() {
                    Point lastMousePoint = new Point(-1, -1);
                    public void actionPerformed(ActionEvent e) {
                        Point p = MouseInfo.getPointerInfo().getLocation();
                        if (p.x != lastMousePoint.x || p.y != lastMousePoint.y) {
                            lastMousePoint.setLocation(p);
                            SwingUtilities.convertPointFromScreen(p, mouseEvtSource);
                            line.lineTo(p.x, p.y);
                            pointCount++;
                            repaint();
                mouseEvtSource = mouseEventSource;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
                mousePosQuerier.start();
            public void mouseReleased(MouseEvent e) {
                mousePosQuerier.stop();
                repaint();
                System.out.println("Timer Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
        private static class DragEventsPanel extends JPanel
                implements MouseListener, MouseMotionListener{
            private GeneralPath line;
            private int pointCount;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
            public void mouseDragged(MouseEvent e) {
                pointCount++;
                line.lineTo(e.getX(),e.getY());
                repaint();
            public void mouseReleased(MouseEvent e){
                System.out.println("DragEvent Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
            public void mouseMoved(MouseEvent e) {}
        public static void main(String args[]) {
            JFrame frame = new JFrame();
            JPanel drawPanel = new JPanel() {
                @Override
                protected AWTEvent coalesceEvents(AWTEvent existingEvent,
                                                  AWTEvent newEvent) {
                    if(newEvent.getID() == MouseEvent.MOUSE_DRAGGED) {
                        return null;
                    }else {
                        return super.coalesceEvents(existingEvent, newEvent);
            TimerBasedPanel timerPanel = new TimerBasedPanel(drawPanel);
            DragEventsPanel dragPanel = new DragEventsPanel();
            drawPanel.setBorder(BorderFactory.createTitledBorder("Draw here"));
            timerPanel.setBorder(BorderFactory.createTitledBorder("Uses a timer"));
            dragPanel.setBorder(BorderFactory.createTitledBorder("Listens for drag events."));
            drawPanel.addMouseListener(timerPanel);
            drawPanel.addMouseListener(dragPanel);
            drawPanel.addMouseMotionListener(dragPanel);
            frame.setLayout(new java.awt.GridLayout(0,3));
            frame.add(drawPanel);
            frame.add(timerPanel);
            frame.add(dragPanel);
            frame.setSize(600,200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: Maxideon on Sep 16, 2009 9:56 PM
    Minor error, but now fixed.

  • Mouse Events on Disabled Buttons

    Hi,
    In my application I should make a disabled button to show a tool tip when mouse is entered onto it.
    I'm using java.awt.container not Jcontainer.
    I have searched in SDN forums and after reading some of the comments what I understood is �disabled Swing button can react to Mouse events but a disabled awt button can not react to mouse events�.
    Is that true or did I not understand correctly?
    And how would I be able to implement the required functionality in my
    application?
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    public class AwtTooltip {
        private Panel getContent(Frame f) {
            Button left = new Button("left");
            left.setEnabled(false);
            Button right = new Button("right");
            Panel panel = new Panel(new GridBagLayout());
            new TipManager(panel, f);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            panel.add(left, gbc);
            panel.add(right, gbc);
            return panel;
        public static void main(String[] args) {
            AwtTooltip test = new AwtTooltip();
            Frame f = new Frame();
            f.addWindowListener(closer);
            f.add(test.getContent(f));
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        private static WindowListener closer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
    class TipManager extends MouseMotionAdapter {
        Panel component;
        Window tooltip;
        Label label;
        public TipManager(Panel panel, Frame frame) {
            component = panel;
            panel.addMouseMotionListener(this);
            initTooltip(frame);
         * Since enabled Buttons consume MouseEvents we will
         * receive events sent only from disabled Buttons.
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean hovering = false;
            Component[] c = component.getComponents();
            for(int j = 0; j < c.length; j++) {
                Rectangle r = c[j].getBounds();
                if(r.contains(p)) {
                    hovering = true;
                    if(!tooltip.isShowing())
                        showTooltip(c[j], p);
                    break;
            if(!hovering && tooltip.isShowing()) {
                tooltip.setVisible(false);
        private void showTooltip(Component c, Point p) {
            String text = ((Button)c).getLabel();
            label.setText(text);
            tooltip.pack();
            convertPointToScreen(p, component);
            tooltip.setLocation(p.x+10, p.y-15);
            tooltip.setVisible(true);
        /** Copied from SwingUtilities source code. */
        public void convertPointToScreen(Point p, Component c) {
            Rectangle b;
            int x,y;
            do {
                if(c instanceof Window) {
                    try {
                        Point pp = c.getLocationOnScreen();
                        x = pp.x;
                        y = pp.y;
                    } catch (IllegalComponentStateException icse) {
                        x = c.getX();
                        y = c.getY();
                } else {
                    x = c.getX();
                    y = c.getY();
                p.x += x;
                p.y += y;
                if(c instanceof Window)
                    break;
                c = c.getParent();
            } while(c != null);
        private void initTooltip(Frame owner) {
            label = new Label();
            label.setBackground(new Color(184,207,229));
            tooltip = new Window(owner);
            tooltip.add(label);
    }

  • Event propagation API

    Hi,
    I recently started using Flex and read through the, very extensive and well written documentation. I read about the event propagation mechanism and was rather stunned that only Objects that have a parent-child relationship take part in event propagation. At first I couldn't believe it but trying to connect to objects that were at very different parts of the display list showed, that the events really do not get delivered! Wouldn't it be better to have a more general mechanism that does not care about the wherabouts of the components? I mean, what if I want to synchronize some model objects that are not even part of the display list with some UI Element they have a relationship with? The target phase doesn't work because its not the model that throws the event (of course!). Or do I miss something here?
    I was expecting a more subject-observer like pattern,  that allows me to connect whatever I want with whatever there is left. So, how do I do that. Do I have to right my own little event dispatching library (what would not be so difficult, but I would rather use something that has already proven its liability)? Can anybody recommend me a good API for that or tell me that I am dead wrong and missing something important?
    Regards,
    Benni

    Only DisplayObjects support bubble and capture propagation.  In a tree of
    regular Objects, as long as you attach a listener to the right object, you
    will be able to get its events.
    Bubble and capture are very dangerous as they break encapsulation.  We only
    use them for situations where the target is unpredictable like in mouse and
    keyboard interaction.  I would probably not use it in a data object tree.
    Maybe if you provide a more explicit example of what you are trying to
    accomplish and what you tried, folks on the forum can help.

  • Trying to create a surface  with multiple images with mouse events

    novice programmer (for a applet program)
    hi trying to create a surface i.e jpanel, canvas, that allows multiple images to be created.
    Each object is to contain a image(icon) and a name associated with that particular image. Then each image+label has a mouse event that allows the item to be dragged around the screen.
    I have tried creating own class that contains a image and string but I having problems.
    I know i can create a labels with icons but having major problems adding mouse events to allow each newly created label object to moved by the users mouse?
    if any one has any tips of how to acheive this it would be much appreciated. Thanks in advance.
    fraser.

    This should set you on the right track:- import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        public class DragTwoSquares extends JApplet implements MouseListener, MouseMotionListener {  
           int x1, y1;   // Coords of top-left corner of the red square.
           int x2, y2;   // Coords of top-left corner of the blue square.
           /* Some variables used during dragging */
           boolean dragging;      // Set to true when a drag is in progress.
           boolean dragRedSquare; // True if red square is being dragged, false                              //    if blue square is being dragged.                            
           int offsetX, offsetY;  // Offset of mouse-click coordinates from
                                  //   top-left corner of the square that was                           //   clicked.
           JPanel drawSurface;    // This is the panel on which the actual
                                  // drawing is done.  It is used as the
                                  // content pane of the applet.  It actually                      // belongs to an anonymous class which is
                                  // defined in place in the init() method.
            public void init() {
                 // Initialize the applet by putting the squares in a
                 // starting position and creating the drawing surface
                 // and installing it as the content pane of the applet.
              x1 = 10;  // Set up initial positions of the squares.
              y1 = 10;
              x2 = 50;
              y2 = 10;
              drawSurface = new JPanel() {
                        // This anonymous inner class defines the drawing
                        // surface for the applet.
                    public void paintComponent(Graphics g) {
                           // Draw the two squares and a black frame
                           // around the panel.
                       super.paintComponent(g);  // Fill with background color.
                       g.setColor(Color.red);
                       g.fillRect(x1, y1, 30, 30);
                       g.setColor(Color.blue);
                       g.fillRect(x2, y2, 30, 30);
                       g.setColor(Color.black);
                       g.drawRect(0,0,getSize().width-1,getSize().height-1);
              drawSurface.setBackground(Color.white);
              drawSurface.addMouseListener(this);
              drawSurface.addMouseMotionListener(this);
              setContentPane(drawSurface);
           } // end init();
           public void mousePressed(MouseEvent evt) {
                  // Respond when the user presses the mouse on the panel.
                  // Check which square the user clicked, if any, and start
                  // dragging that square.
              if (dragging)  // Exit if a drag is already in progress.
                 return;           
              int x = evt.getX();  // Location where user clicked.
              int y = evt.getY();        
              if (x >= x2 && x < x2+30 && y >= y2 && y < y2+30) {
                     // It's the blue square (which should be checked first,
                     // since it's in front of the red square.)
                 dragging = true;
                 dragRedSquare = false;
                 offsetX = x - x2;  // Distance from corner of square to (x,y).
                 offsetY = y - y2;
              else if (x >= x1 && x < x1+30 && y >= y1 && y < y1+30) {
                     // It's the red square.
                 dragging = true;
                 dragRedSquare = true;
                 offsetX = x - x1;  // Distance from corner of square to (x,y).
                 offsetY = y - y1;
           public void mouseReleased(MouseEvent evt) {
                  // Dragging stops when user releases the mouse button.
               dragging = false;
           public void mouseDragged(MouseEvent evt) {
                   // Respond when the user drags the mouse.  If a square is
                   // not being dragged, then exit. Otherwise, change the position
                   // of the square that is being dragged to match the position
                   // of the mouse.  Note that the corner of the square is placed
                   // in the same position with respect to the mouse that it had
                   // when the user started dragging it.
               if (dragging == false)
                 return;
               int x = evt.getX();
               int y = evt.getY();
               if (dragRedSquare) {  // Move the red square.
                  x1 = x - offsetX;
                  y1 = y - offsetY;
               else {   // Move the blue square.
                  x2 = x - offsetX;
                  y2 = y - offsetY;
               drawSurface.repaint();
           public void mouseMoved(MouseEvent evt) { }
           public void mouseClicked(MouseEvent evt) { }
           public void mouseEntered(MouseEvent evt) { }
           public void mouseExited(MouseEvent evt) { }  
        } // end class

  • How to throw the mouse event to a upper level component?

    For example: a panel using absolute layout, and there is a label on it.
    Now when mouse clicked on the label, i do not want the label but the panel to get the mouse event , so that i can get the mouse click point's x and y in the panel.
    How to implement it?
    Thanks a looooooooooooot for ur help
    Best Regards

    try this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setSize(100,75);
        setLocation(300,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final JPanel p = new JPanel();
        JLabel lbl = new JLabel("Click Me");
        lbl.setToolTipText("OK");
        lbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        p.add(lbl);
        getContentPane().add(p);
        lbl.addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){//match method name
            p.dispatchEvent(me);}});
        p.addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){//with this method name
            System.out.println("Panel clicked");}});
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Handling mouse events anywhere

    Hi,
    We have built an application with a Swing GUI and for automation and testing we would like to record all keyboard and mouse events to be able to play them afterwards.
    The keyboard events can be recorded easily with a KeyboardFocusManager but for the mouse events I still need a solution.
    The GUI consists of a JFrame containing several JPanels. When I add a MouseListener on the JFrame, its mousePressed and mouseReleased events are not called everytime I click somewhere on the frame. For example, when I click on a button inside one of the JPanels, the mouse event methods of the frame are not executed.
    Can somebody tell me how I can easily capture all mouse events in the GUI without adding MouseListeners in every JPanel??
    Thanks in advance...

    I know how to use the Robot class, that's not really the issue.
    What we are doing actually is writing keyboard and mouse events into a file.
    Afterwards we use the Robot class to playback the events in the file. This is no problem, I just don't know how I can easily intercept ALL mouse events in the GUI without adding mouseListeners in each component in the GUI.

  • Allowing Mouse Events to "Fall Through" When Window Activated

    I'm implementing a "tool pallette" in my application (much like tools in an application like Photoshop) and I want the user to be able to immediately click on options on this pallete without having to make the window active. Since Swing doesn't have an explicit "Pallete" window that would give this to me for free, I'm assuming I need to subclass JDialog to make this happen.
    Even if window activation still must happen, it's crucial that the user only needs to click once to press the button on an inactive window.
    I know I can detect WindowEvents like WINDOW_ACTIVATED by simply adding my own window listener, but I don't know how I'd go about having mouse events "fall through" the window listeners and cause the appropriate action on the underlying component. It's almost as if I need to tell the window itself to listen for nothing.
    I thought glass planes may be the answer, but that doesn't seem to be what's preventing the intial click in an inactive window from falling through to the underlying component.
    Any thoughts, comments, or experiences regarding this are greatly appreciated!

    Such a simple solution to such a perplexing problem. You are absolutely right. It turns out I was experience a bug in my particular L&F. Trying this with the Windows L&F proves that simply changing from JWindow to a non-modal JDialog works. Now I'll have to go about getting the bug fixed in the MacOSX (Aqua) L&F so I have equivalent behavior across all our supported platforms.
    Thanks for the quick response.

  • Mouse Events "Falling Through" During Window Activation

    I'm implementing a "tool pallette" in my application (much like tools in an application like Photoshop) and I want the user to be able to immediately click on options on this pallete without having to make the window active. Since Swing doesn't have an explicit "Pallete" window that would give this to me for free, I'm assuming I need to subclass JDialog to make this happen.
    Even if window activation still must happen, it's crucial that the user only needs to click once to press the button on an inactive window.
    I know I can detect WindowEvents like WINDOW_ACTIVATED by simply adding my own window listener, but I don't know how I'd go about having mouse events "fall through" the window listeners and cause the appropriate action on the underlying component. It's almost as if I need to tell the window itself to listen for nothing.
    I thought glass planes may be the answer, but that doesn't seem to be what's preventing the intial click in an inactive window from falling through to the underlying component.
    Any thoughts, comments, or experiences regarding this are greatly appreciated!

    The solution to this problem was posted in the Swing forum. Turns out to be a simple difference of JWindow and JDialog, but a difference I wasn't seeing under all L&Fs (i.e., Windows L&F handles JDialog properly, MacOSX (Aqua) L&F seems to treat it like any other window... I've filed a bug with them).

  • How Keyboard & Mouse Events are handled in java?

    Hi
    How Keyboard & Mouse Events are handled in java?
    Kindly brief, how a key typed in the keyboard is sensed and it is entered in JTextField?
    or
    Pls. give me some links.
    Am going to send the events from external device (like keyboard) to OS and from that I need to capture that event in Java Swing?
    Pls. drop in a bit. So that it will be helpfull to me.
    Thanks in advance,
    bee

    Actualy am very much aware of using KeyListener and MouseListener. I am in need of internal details,
    how typing a key in keyboard is captured by KeyListener? How the event is passed to java swing and and it is fired to keylistener.
    Pls. help me.
    Thanks
    bee

  • JPanels are not reading Mouse Events

    I created a basic Tic Tac Toe game, with individual "TicPanel"s inside a JPanel inside a JFrame object, however, none of the mouse events are working? Is it because the JFrame is receiving and doing nothing with the MouseEvents?
        private class TicPanel extends JPanel implements MouseListener
            private int owner; //-1 = none, 0 = O, 1 = X
            private Graphics g;
            private int num;
            ActionListener listener;
             * Constructor
            public TicPanel(int num)
                this.num = num;
                g = getGraphics();
                owner = -1;
            public void setX()
                owner = 1;
                g.drawLine(0,0,getWidth(),getHeight());
            public void setO()
                owner = 0;
                g.drawOval(0,0,getWidth(),getHeight());
            public int getOwner()
                return owner;
            public void mousePressed(MouseEvent evt){}
            public void mouseReleased(MouseEvent evt){}
            public void mouseExited(MouseEvent evt){}
            public void mouseEntered(MouseEvent evt){}
            public void mouseClicked(MouseEvent evt)
                System.out.println("works");
                listener.actionPerformed(new ActionEvent(this, num, ""));
                setX();
            public void addActionListener(ActionListener listener)
                this.listener = listener;
        }   Edited by: TheWhiteLynx on Aug 10, 2009 2:16 PM

    TheWhiteLynx wrote:
    I created a basic Tic Tac Toe game, with individual "TicPanel"s inside a JPanel inside a JFrame object, however, none of the mouse events are working? Is it because the JFrame is receiving and doing nothing with the MouseEvents?I don't see anywhere that you are adding a MouseListener to anything. Usually this is done with the addMouseListener(...) method.
    Oh, and please read the Sun graphics tutorial as this is not the way to do graphics in Swing. You do not want to get the Graphics object via getGraphics method but instead do your painting in a paintComponent override method and get your Graphics object from the parameter passed to this method. The tutorials will explain all.
    Edited by: Encephalopathic on Aug 10, 2009 2:29 PM

Maybe you are looking for

  • Can I put a DVD+R/W Recording into iMovie.. then back to DVD?

    Hi all, New to Macs and must admit I'm asking this question without really trawling through the help manuals at all... but... If I make a recording to a DVD+R/W from my home DVD player, can I then import that recording to iMovie, edit it it and send

  • Problems creating basic forms in DW CS3

    Hey I'm having some real headaches here getting my form to work in DW CS3. Take a look at www.investix.co.uk/booking-form.html....as you can see I've got my form all set up with all the text fields and buttons that I need ready to go and process the

  • Getting empty namespace (xmlns="") in output of XSLT

    Hi, I am trying to copy data from an input XML to output using XSLT in ESB 10.1.3.4. But empty namespaces are getting added to some tags. Input: <Root> <Node> <Parent1> <Child1> <Child2> <Child3> </Parent1> <Parent2> <Child1> <Child2> <Child3> </Pare

  • Can we create a role similar to SAP_J2EE_ADMIN

    Hi, Our portal UME is ABAP datasource so in order to assign Super Administrator we are giving SAP_J2EE_ADMIN in the backend . Our security team has decided that instead of giving SAP_J2EE_ADMIN to users, they want to tweak this role a little bit and

  • Photoshop crashes when i access the directory pulldown...

    greetings, All my Adobe programs crash when i use my pulldown directory menu on the "open window". It also doesn't remember the last directory i was in, it takes me back to the desktop every time. i hope this makes sense... for example--i'm in photos