MouseEvents

Hi, I�m new to using event handling and need some help. I�ve created JTabbedPane and added some panes to it. I need to use a MouseEvent (presumably mouseClicked) to acknowledge when I�ve clicked on a certain tab. How do I get the source component that has been clicked on? I tried getSource but that doesn�t work.

It doesn't work because it's not a part of the
MouseListener class. I get an error stating thatit
is unrecognized. I was just hoping that sincethere
was a getSource command with ActionEvents thatthere
would be one for MouseEvents. As I said I�m new to
this stuff.I think you're supposed to call addChangeListener, to
notify a listener of the event, not deal directly
with the lower-level mouse events yourself.You're not really helping here...there might be a very good reason to listen to the mouse events rather than use the ChangeListener. Maybe he wants to be notified on a double-click, for instance.
Either way, his question indicates that something else is happening because there IS a getSource() method for MouseEvents. MouseEvent is a relative of AWTEvent, which defines the getSource() method, so it must be available.
getSource() should be available from MouseEvent, however, it will not return the selected component, it will probably return the JTabbedPane. As DrClap said, ChangeListener can notify you when a selection changes. If you absolutely have to use MouseListener though, you can just call "myTabPane.getSelectedComponent()" when you receive the MouseEvent.

Similar Messages

  • MouseEvents and KeyEvents in the same form is not working

    Hello!
    I'm newbee in java althought i've bee programing for a long time in other languages, C, C++ wich i'm proud of.
    Now i land on java and there are a lot of cuestions (nothing that cant be solved by trying and reading).
    But today i hitted my head against all posible solutions and nothing (but bad mood) came out.
    The code with trouble is this...
    public class NewJFrame extends javax.swing.JFrame
        public NewJFrame()
            initComponents();
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            jButton1.setText("jButton1");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            pack();
        private void formKeyTyped(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void formKeyPressed(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void formKeyReleased(java.awt.event.KeyEvent evt) {
            Integer i = evt.getKeyCode();
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
            Integer i = evt.getButton();
        private javax.swing.JButton jButton1;
    }In debug mode i cant listen to mouse events and key events in the same form. Is that normal ?
    In case this is normal, how can i surround this "problem" and make it work.
    Thanks a lot in ahead.

    Thanks for trying to understand whats going on ...
    There is my SSCCE
    * NewJFrame.java
    * Created on 2 de mayo de 2008, 20:32
    * @author  edu
    public class NewJFrame extends javax.swing.JFrame
        public NewJFrame()
            initComponents();
            setFocusable(true);
            requestFocus();
        private void initComponents() {
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    formKeyPressed(evt);
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    formKeyReleased(evt);
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    formKeyTyped(evt);
            jButton1.setText("jButton1");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE)))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addGap(0, 0, Short.MAX_VALUE)))
            pack();
        private void formKeyTyped(java.awt.event.KeyEvent evt) {                             
            setTitle(String.valueOf(evt.getKeyCode()));
        private void formKeyPressed(java.awt.event.KeyEvent evt) {                               
            setTitle(String.valueOf(evt.getKeyCode()));
        private void formKeyReleased(java.awt.event.KeyEvent evt) {                                
            setTitle(String.valueOf(evt.getKeyCode()));
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
            setTitle(String.valueOf(evt.getButton()));
        private javax.swing.JButton jButton1;
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
    }It's quite simple, its suposed to show on the windows title the KeyCode (if there is any) or the MouseButton when pressed.
    The problem is: it doesnt work... (if i comment out the jButton1 related code, that means that i dont listen to MouseEvents & dont add the MouseAdapter as MouseListner to the form, the KeyEvents are raised and i can listen to them - but there are no MouseEvents - if i run the SSCCE like above i can listen to the MouseEvents, but cant listen to the KeyEvents. Can you tell me why?
    Just before posting i realized it was a focus issue ! The button got the focus and got all the events redirected towards him ! I solved it with the code
            jButton1.setFocusable(false);and it finally worked !
    Thanks!

  • JFrame not responding to the MouseEvents

    hi,
    In my application Jframe which has a menuBar,this menu consists of various radiobuttons options .Intially when a frame opens it has an same square at a specific position .when one of the options in the mebar is clicked it responds accordingly by placing this square in different position and varing the size& the % of expanding.
    The following problems i'am facing
    1.The MenuBar is visible on the Jframe ,but when we move towards the extreme left corner and click the option will be visible.i'am able to figure it out y this happening
    2.The MouseEvents are not recognised,only radio buttons named 1& 3 when selected responds to the Itemlistener whereas the others don't.
    plz let me know where am i making mistakes.Plz i have totally ran out of ideas.i'am sending the code for ur clear understanding.
    Thanks in advance
    your help would be apprecriated
    rao_lavs
    import java.applet.Applet;
    import java.awt.*; // for Graphics, Color, Image, Point, ...
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.ItemListener;
    import java.lang.Math;
    import java.util.Vector;
    import java.util.*;
    import java.lang.Thread;
    import java.lang.String;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.CheckboxGroup;
    import java.awt.Checkbox;
    import javax.swing.*;
    public class Complete1 extends JFrame implements MouseMotionListener, MouseListener,ItemListener,Runnable{
    int width, height,index,i=0,distance=0,k=0,w,h,dist1=0,flag=0,wn,ws,ww,we,hn,hs,hw,he;
    String dist = " " ;
         Hashtable optionList = new Hashtable();
         boolean suspended;
         private long Start;
    Thread myTh2 = null;
    Vector list = new Vector();
    int x1, y1,j,x,y,s,wn1,ws1,ww1,we1,hn1,hs1,hw1,he1,counter=0,count=0,xpos,ypos;
    Image backbuffer;
    Graphics backg;
    Point p2;
    int[][] anArray; // declare an array of integers
    //int[] flag1;
    public static void main (String args[])
    JFrame f= new Complete1("Example");
    f.setDefaultCloseOperation(EXIT_ON_CLOSE);
    f.pack();
    f.show();
    f.setSize(800,800);
    f.setVisible(true);
    public Complete1(String st1) {
    super(st1);
         anArray = new int[200][200];     // create an array of integers
         //flag1 = new int[40];
         optionList.put("1",new Integer(1));
         optionList.put("2",new Integer(2));
         optionList.put("3",new Integer (3));
         optionList.put("4",new Integer(2));
         optionList.put("5",new Integer (3));
         JMenuBar mb= new JMenuBar();
         JMenu menu = new JMenu("Options");
         mb.add(menu);
         ButtonGroup bg = new ButtonGroup();
         JRadioButtonMenuItem rb = null;
         pack();
    setVisible(true);
         w = getSize().width;
         h = getSize().height;
    width=w+800;
    height=h+800;
         wn = width/2;
         hn = height/2+110;
         wn1 = width/2;
         hn1 = height/2-265;
         /*ws = wn = (width/2);
         hn = (height/2-185);
         hs = (height/2+185);
         ww = (width/2-185);
         he = hw = (height/2);
         we = (width/2+185);
         ws1 = wn1 = (width/2);
         hn1 = (height/2-300);
         hs1 = (height/2+300);
         ww1 = (width/2-300);
         he1 = hw1 = (height/2);
         we1 = (width/2+300);*/
         backbuffer = createImage( width, height );
    backg = backbuffer.getGraphics();
    backg.setColor( Color.black );
    backg.fillRect( 0, 0, width, height );
    // Create list of points.
    // These points are the centres of the squares.
    list.addElement( new Point( width/2, (height/2+300) ) );
    //list.addElement( new Point( width/2, height/2 ) );
    System.out.println(width/2 + "," + (height/2+300));
    //list.addElement( new Point( width/4, height/4 ) );
    //list.addElement( new Point( 3*width/4, height/2 ) );
         addMouseMotionListener( this );
    addMouseListener(this);
    myTh2 = new Thread (this);
    myTh2.start();
    anArray[0][0] = wn1;anArray[1][0] = hn1;anArray[2][0] = wn;anArray[3][0] = hn;anArray[4][0] = wn;anArray[5][0] = hn;anArray[6][0] = wn;
    anArray[7][0] = hn;anArray[8][0] = wn;anArray[9][0] = hn;anArray[10][0] = wn1;anArray[11][0] = hn1;anArray[12][0] = wn1;anArray[13][0] = hn1;
         anArray[14][0] = wn;anArray[15][0] = hn;anArray[16][0] = wn;anArray[17][0] = hn;anArray[18][0] = wn;anArray[19][0] = hn;anArray[20][0] = wn;
    anArray[21][0] = hn;anArray[22][0] = wn1;anArray[23][0] = hn1;anArray[24][0] = wn1;anArray[25][0] = hn1;anArray[26][0] = wn1;anArray[27][0] = hn1;
    anArray[28][0] = wn;anArray[29][0] = hn;anArray[30][0] = wn1;anArray[31][0] = hn1;anArray[32][0] = wn1;anArray[33][0] = hn1;anArray[34][0] = wn;
    anArray[35][0] = hn;anArray[36][0] = wn1;anArray[37][0] = hn1;anArray[38][0] = wn1;anArray[39][0] = hn1;anArray[40][0] = wn;anArray[41][0] = hn;
    anArray[42][0] = wn1;anArray[43][0] = hn1;anArray[44][0] = wn1;anArray[45][0] = hn1;anArray[46][0] = wn;anArray[47][0] = hn;anArray[48][0] = wn;
    anArray[49][0] = hn;anArray[50][0] = wn1;anArray[51][0] = hn1;anArray[52][0] = wn1;anArray[53][0] = hn1;anArray[54][0] = wn;anArray[55][0] = hn;
    anArray[56][0] = wn1;anArray[57][0] = hn1;anArray[58][0] = wn;anArray[59][0] = hn;anArray[60][0] = wn1;anArray[61][0] = hn1;anArray[62][0] = wn;
    anArray[63][0] = hn;anArray[64][0] = wn;anArray[65][0] = hn;anArray[66][0] = wn1;anArray[67][0] = hn1;anArray[68][0] = wn;anArray[69][0] = hn;
    anArray[70][0] = wn1;anArray[71][0] = hn1;anArray[72][0] = wn1;anArray[73][0] = hn1;anArray[74][0] = wn;anArray[75][0] = hn;anArray[76][0] = wn1;
    anArray[77][0] = hn1;anArray[78][0] = wn;anArray[79][0] = hn;
         anArray[0][1]=1;anArray[1][1]=0;anArray[2][1]=0;anArray[3][1]=0;anArray[4][1]=0;anArray[5][1]=1;anArray[6][1]=1;anArray[7][1]=0;anArray[8][1]=0;anArray[9][1]=0;anArray[10][1]=0;anArray[11][1]=1;
         anArray[12][1]=1;anArray[13][1]=1;anArray[14][1]=0;anArray[15][1]=1;anArray[16][1]=1;anArray[17][1]=0;anArray[18][1]=1;anArray[19][1]=1;anArray[20][1]=0;anArray[21][1]=1;anArray[22][1]=1;anArray[23][1]=0;
         anArray[24][1]=0;anArray[25][1]=1;anArray[26][1]=1;anArray[27][1]=0;anArray[28][1]=1;anArray[29][1]=0;anArray[30][1]=1;anArray[31][1]=0;anArray[32][1]=0;anArray[33][1]=1;anArray[34][1]=0;anArray[35][1]=1;
         anArray[36][1]=1;anArray[37][1]=0;anArray[38][1]=1;anArray[39][1]=0;
    Enumeration keys = optionList.keys();
    while(keys.hasMoreElements())
    String label = (String)keys.nextElement();
    rb = new JRadioButtonMenuItem(label);
    rb.setSelected(false);
    rb.addItemListener(this);
    menu.add(rb);
    bg.add(rb);
    rb.setSelected(true);
    Container p = getContentPane();
    setJMenuBar(mb);
         public void run ()
    int l;
         try{
         try
         try
    SaveOutput.start("log.txt");
         for(l=0;l<30000000;l++)
    myTh2.sleep(10);
         System.out.println(+xpos+ "," +ypos);
    while(suspended)
    myTh2.sleep(300);
    }catch(InterruptedException e){ }
    }catch(Exception e){ e.printStackTrace();}
         }catch(NullPointerException e){}
    finally{SaveOutput.stop();}
    public void itemStateChanged ( ItemEvent theEvent )
         JRadioButtonMenuItem mi = (JRadioButtonMenuItem)theEvent.getSource();
    String dist = mi.getText();
         if((dist=="1")|| (dist=="2"))
              distance=0;
              dist1=0;
              counter=0;k=0;
         else if(dist=="3")
              distance=100;
              dist1=100;
              counter=0;k=0;
         else if(dist=="4")
              distance=2000;
              dist1=2000;
              counter=0;k=0;
         else if(dist=="5")
              distance=10000;
              dist1=10000;
              counter=0;k=0;
    public void mouseMoved( MouseEvent e ) {
         xpos = e.getX();
         ypos = e.getY();
         if(i==0)
         distance=0;
         if(i==1)
         if(dist=="3" && anArray[counter-1][1]==1)
         distance = 800;
         else if(dist=="4" && anArray[counter-1][1]==1)
         distance = 30000;
         else if(dist=="5" && anArray[counter-1][1]==1)
         distance = 80000;
         else
         distance=dist1;
         Point p = new Point( e.getX(), e.getY() );
    // Clear the back buffer.
    backg.setColor( Color.black );
    backg.fillRect( 0, 0, width, height );
    // Set the drawing colour to white.
    backg.setColor( Color.white );
              // Loop over the list of points, drawing a square for each one.
              for ( int j = 0; j < list.size(); ++j )
    p2 = (Point)list.elementAt(j);
    // compute distance squared between square's centre and mouse position
    double deltaX = p2.x - p.x;
    double deltaY = p2.y - p.y;
    double distance2 = deltaX*deltaX + deltaY*deltaY;
    // Compute the size of the square based on the distance.
    // We use a Gaussian function to make it look smooth.
    //System.out.println("distance is :" + distance);
    if(dist=="2" && i==1)
    s = (int)Math.round( 20 * (4+1*Math.exp(-distance2/distance)) );
    else
    s = (int)Math.round( 20 * (1+3*Math.exp(-distance2/distance)) );
    // draw the square into the back buffer
    backg.drawRect( (int)p2.x-s/2, (int)p2.y-s/2, s, s );
    if(counter == 40)
                   backg.drawString("CLICK AND STOP",(width/2-30),height/2);
         repaint();
    e.consume();
    public void mouseDragged( MouseEvent e ) { }
    public void update( Graphics g ) {
    g.drawImage( backbuffer, 0, 0, this );
    public void paint( Graphics g ) {
    update( g );
    public void mouseClicked( MouseEvent e ) { }
    public void mouseEntered( MouseEvent e ) { }
    public void mouseExited( MouseEvent e ) { }
    public void mouseReleased( MouseEvent e ) {
         /* if(i==0)
                   count++;
                   if(count==40)
                   count=0;
    public void mousePressed( MouseEvent e ) {
         x=e.getX();
              y=e.getY();
                   if(((x>(int)p2.x-s/2)&&(x<((int)p2.x-s/2)+s))&&(y>(int)p2.y-s/2)&&(y<((int)p2.y-s/2)+s)))
                        if(i==0)
                             list.removeElementAt(j);
              System.out.println("j is " + j);
         list.addElement( new Point( anArray[k][0],anArray[k+1][0] ) );
    System.out.println("j after add element is " + j);
    distance = dist1;
    System.out.println("anArray[" + k +"] is :" + anArray[k][0]);
    System.out.println("anArray[" + k +"+1] is :" + anArray[k+1][0]);
    k=k+2;
    i=1;
    Start = System.currentTimeMillis();
    suspended = false;     
    if(k==80)
                             System.out.println("k value is"+k);
                                  k=0;
                                  System.out.println("value of k after initiatising is"+k);
                                  System.out.println("value of k is"+k);
                                  counter++;
                                  System.out.println("counter is :" + counter);
                   else if(i==1)
                        list.removeElementAt(j);
                        System.out.println("j is " + j);
                        distance=0;
                        list.addElement( new Point( width/2, (height/2+300) ) );
                        i=0;
                        System.out.println("value of k is"+k);
                        long End = System.currentTimeMillis();
                        double seconds1 = (End-Start)/1000.0;
                        System.out.println("the time for click" +seconds1);
    suspended = true;
                   index = list.size();
                        System.out.println("list.size() is" + index);
              mouseMoved(e);
    }//end of outer if
    }//end of class

    bravesfanatic4 wrote:
    What would cause this?You've got a bug. What it is is anybody's guess.
    Your best bet here is to show us your code. We don't want to see all of it, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem, in other words, an SSCCE (Short, Self Contained, Correct (Compilable), Example). For more info on SSCCEs please look here:
    [http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html]
    Again, if the code is compilable and runnable more people will be able to help you.

  • MouseEvents are not triggered for JMenu

    I would like to listen for MouseEvents but i'm not sure if it is a bug in java or some lack of knowledge on my side concerning event handling.
    I have a simple menu with one mouse listener and seems that mouseReleased and mouseClicked events are not triggered always as i would expect.
    if i run the code that has been attached below, than i have the following strange scenarios.
    Menu0 is not opened and click on it once:
    pressed Menu0
    clicked Menu0
    There is no mouseReleased received. why?
    Menu0 is opened and click on it once again:
    pressed Menu0
    released Menu0
    clicked Menu0
    Menu0 is collapsed and i have all the events. ok
    Menu0 is opened and click on Menu1:
    pressed Menu1
    released Menu1
    Menu0 is collapsed and there is no mouseClicked event. why?
    Menu0 is opened and go over Menu2 and click on it:
    pressed Menu2
    clicked Menu2
    There is no mouseReleased event. why?
    Press the mouse over Menu2 and release it over Menu3:
    pressed Menu2
    released Menu2
    why is it 'released Menu2' and not 'released Menu3' if it is pressed and released Menu2 than where is the clicked event anyway.
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class MouseEventTest
         public static void main( String[] args )
              JFrame frame;
              JMenuBar menuBar;
              JMenu menu, subMenu;
              JMenuItem menuItem;
              MouseListener mouseListener;
              mouseListener = new MouseAdapter() {
                   public void mouseEntered( MouseEvent e )
                   public void mouseExited( MouseEvent e )
                   public void mouseClicked( MouseEvent e )
                        System.err.println( "clicked " + ((JMenuItem) e.getSource()).getText());
                   public void mousePressed( MouseEvent e )
                        System.err.println( "pressed " + ((JMenuItem) e.getSource()).getText());
                   public void mouseReleased( MouseEvent e )
                        System.err.println("released " + ((JMenuItem) e.getSource()).getText());
              menuBar = new JMenuBar();
              menu = new JMenu( "Menu0" );
              menu.addMouseListener( mouseListener );
              menuBar.add( menu );
              menuItem = new JMenuItem( "Menu1" );
              menuItem.addMouseListener( mouseListener );
              menu.add( menuItem );
              subMenu = new JMenu( "Menu2" );
              subMenu.addMouseListener( mouseListener );
              menu.add( subMenu );
              menuItem = new JMenuItem( "Menu3" );
              menuItem.addMouseListener( mouseListener );
              subMenu.add( menuItem );
              menuItem = new JMenuItem( "Menu4" );
              menuItem.addMouseListener( mouseListener );               
              subMenu.add( menuItem );
              frame = new JFrame();
              frame.setTitle( "MouseEvent test for JMenu" );
              frame.setBounds( 320, 240, 320, 240 );
              frame.setJMenuBar( menuBar );
              frame.addWindowListener( new WindowAdapter() {
                   public void windowClosing( WindowEvent e ) {
                        System.exit(0);
              frame.setVisible( true );
    }

    Well there are differences across Operating Systems. For example I'm using JDK1.4.2 on XP. When I click on Menu0 I get:
    pressed Menu0
    released Menu0
    clicked Menu0
    It is always better to use a "higher" level event when possible. In this case you should be using an ActionListener, if you want to know when a menu or menuItem is clicked. Or maybe you could use a MenuListener to know when a menu is opened and closed.

  • KeyEvents are to KeyBindings as MouseEvents are to ???

    Hey, stupid question here.
    I've recently been told (on this forum, actually) that KeyEvents are the "old" way to handle keyboard input. The new way is to use KeyBindings and map Actions to the keys you want input from. That's all fine and good, and I finally have all of my KeyEvent stuff translated to KeyBindings and Actions.
    Now, is there a similar "new" way to do mouse input? I haven't found anything on google, so I'm thinking no. Why not though? If binding keyboard input to Actions is the better way to handle keyboard input, why is the same not true for mouse input? Or is there a better way to handle mouse input than listening for MouseEvents? Also, is there a "right" or "wrong" way to mix MouseEvents with keyboard bindings?
    Thanks,
    Kevin

    camickr wrote:
    This isn't just about KeyStrokes and Actions, its about a general programming concept. The way you want to write code is to write reusable chunks of code. As mentioned above that is all an Action is, it is a reusable piece of code. The binding allows you to easily reuse this code. Maybe it's just that what I'm using the Actions for isn't a perfect example. Actions seem to be the modular way to handle the case where you want multiple actions to perform the same function. However, what if I have mostly a 1 to 1, "this key does this, this other key does this other thing" relationship? Even in the first case where Actions make more sense, I suppose I'm failing to see the difference between an Action that's mapped to several KeyBindings (or whatever you want to trigger the Action), and a function called by several keys in a KeyListener.
    Also, is there a "right" or "wrong" way to mix MouseEvents with keyboard bindings?
    I don't know if there is a right or wrong way but the key (to me) is that you want to use the Action, not the binding. So if you know that a component has a certain Action, there is no reason you can't have a MouseEvent invoke that Action. This is the way the [List Action|http://www.camick.com/java/blog.html?name=list-action] works.
    When I say mix, I mean basically using the CTRL_DOWN_MASK in a mouse click event to distinguish between a regular mouse click and a mouse click when the ctrl key is being held down. The only way I knew to do that is by using KeyEvents and MouseEvents. Now that I've switched my KeyEvents to KeyBindings mapped to Actions, the logical next step seemed to be doing the same for the MouseEvents? I don't necessarily want the mouse to trigger the same action as some key on the keyboard, I want the keyboard to change what the mouse does when it is clicked. Does that make sense?
    Anyway, I mostly understand, I'm just still at the point where I don't really see the benefit of KeyBindings and Actions over KeyEvents in my particular circumstance. I see the benefits in general. Maybe I'm just getting too old and becoming resistant to change, haha..

  • Do masks interfere with MouseEvents?

    I have a sprite, on a layer. If I set the layer above it as a
    mask, the sprite's MouseEvents aren't captured. If I remove the
    mask, they are.....
    I have never encountered this before, and in fact I have
    several other movieclips on timeline layers, that are beneath a
    mask-layer, which aren't having any MouseEvent
    problems.....aargh!

    that's not typical behavior. there must be something
    particular about your set-up that's causing that or making you
    think that's occurring.

  • MouseEvents from an OSMF Container

    I have a player that contains a MediaContainer that has been added to stage.
    I'd like to be able to listen for MouseEvents when that container is clicked on; and I'd rather not have to use a fake object, or a general listener in which I have to exclude other objects.
    I used the mediacontainer itself, and MouseEvent.CLICK doesn't seem to be fired from it, even though the notes say it should.
    I've tried using the DisplayObject trait of my media, and that doesn't fire MouseEvents.
    I then took the standard straight from the MediaContainerExample implementation:
    and added a listener for the container click event.
    And nothing happens.
    package
        import flash.display.Sprite;
        import flash.events.MouseEvent;
        import org.osmf.containers.MediaContainer;
        import org.osmf.elements.VideoElement;
        import org.osmf.media.MediaPlayer;
        import org.osmf.media.URLResource;
        public class MediaContainerExample extends Sprite
            public function MediaContainerExample()
                super();
                // Construct a video element:
                var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv");
                var video:VideoElement = new VideoElement(resource);
                // Construct a media container, and add it to the stage.
                var mediaContainer:MediaContainer = new MediaContainer();
                mediaContainer.width = 640;
                mediaContainer.height = 500;
                addChild(mediaContainer);
                // Add the video as a child of the media container:
                mediaContainer.addMediaElement(video);
                // Play back the video:
                var player:MediaPlayer = new MediaPlayer();
                player.media = video;
                mediaContainer.addEventListener(MouseEvent.CLICK, onMediaContainerClick)
             private function onMediaContainerClick(me:MouseEvent):void{
                   trace ("Clicked on the Video!!!");
    I have not found any trait that is a subclass of InteractiveObject; so pulling from traits doesn't seem to work.
    One example I found from the forums talked about the Viewable (IViewable?) trait which I don't believe is still a part of OSMF 1.0.
    Is there a new solution to this issue?
    Thanks.
    -Will

    For some reason trying that example again - it's now responding - don't know what changed between the first compile and when I tried again but oh well. Stepping back it appears that I've done something in the Flex application that's capturing the event.
    Thanks Ryan for compiling it to look into it.
    -Will

  • JTabbedPane - MouseEvents on tabs

    I'm trying to find some way to add MouseListeners to tabs on a JTabbedPane. I can easily add them, of course, to the components denoted by the tabs, but I need them listening for MouseEvents on the actual buttons that switch tabs themselves.
    So far, the only method I can think of is adding the listener to the whole JTabbedPane. If the event isn't within the currently focused component, then it must be in one of the tabs, so I compare the tooltip for that point against the tooltip of the current tab, but this won't work properly if more than one tab has the same tooltip. Anyone have any better ideas?

    And you're well advised to use only methods on TabbedPaneUI without casting it to BasicTabbedPaneUI or any other specific UI delegate since that can throw a ClassCastException when run under different core or third-party look-and-feel. By the way, those are not real buttons (unfortunately), so you'll have to add the mouse listener to the entire tabbed pane (like in the linked example).

  • Forcing JTextAreas to pass control MouseEvents to their parent JPanels

    Hello, I have a rather annoying problem...
    Alright, I have a main JPanel that is the view of a JScrollPane.
    The JPanel contains other JPanels, JLabels and JTextAreas.
    I have a MouseListener and MouseMotionListener for the JPanel.
    Both listeners allow me to move the JPanel around inside JScrollPane when I drag the mouse. (Just like Adobe Acrobat with the hand).
    The problem:
    The movement works fine when the cursor is over any components in the main JPanel, but when it is over any of the JTextAreas they get initial control of any MouseEvents. (I notice that the cursor changes from the hand-icon to the normal pointer-icon when above a JTextArea.)
    What I want to achieve:
    I want to achieve some sort of MouseEvent related invisibility with the JTextAreas, so that any MouseEvents are passed to the panel below.
    Note:
    -The JTextAreas are for displaying text only, ie they don't need to be editable, focusable, etc...
    -I have tried adding my own MouseListeners to the JTextAreas, but it doesn't achieve the desired functionality.

    I think there is a simple way of doing what you want- don't use JTextArea's!!
    You could get deeply involved in fiddling around with event listenting, overiding methods- all of which I think would be unneccesary- especially if your not using the text areas for editing text.
    My suggestion would be to create your own multi-line JLabel- or similar component (There are plenty examples on these forums and on other pages) and use that instead. This would solve the probably pretty easy I think.

  • Getting MouseEvents to pass to overlapping JPanels

    Hi,
    I've been having trouble finding a solution to MouseEvent issue.
    I'm building a grid of diamond-shaped JPanels, (kind of like SimCity, in the sense that each is a tile, if that helps in picturing it), and I can get them to respond to mouse events, specifically a mouse click, but since their bounds are rectangular, the components overlap, making the topmost component listen to the mouseEvent, but not any of the other tiles that contain the same X,Y Coord that the mouse was clicked at.
    The question is, How can I get a mouseListener to send the mouseEvent to the next highest component after my hittest finds out the point was not actually in the polygon, even though it was in the bounds?
    hopefully I've explained it well enough,
    Thanks for any help you can give.

    ZMaster wrote:
    well, I was concerned figuring out the tile the mouse was over manually would take more time/cpu power, It's not really, it's just a matter of dividing the point clicked by the size of the tiles; for square tiles anyway, diamonds would be a little more complicated.
    i.e., for square tiles, say they're 10 pixels square, and you click 36, 72. 36/10 = 3, 72/10 = 7, so tile (3, 7) was clicked. Adjust if your tiles are 0-indexed.
    The Observer Idea seems like a good way to implement a custom mouseEvent without as much of the hassle...
    still, just too soothe my curiosity, is it possible for a component to take the MouseEvent they were given by their listener, and pass it to the next component that also qualifies to get it, i.e. having a mouse click where two components overlap, and both have mouse listeners?puckstopper's idea was to have the background be the only one that recieves MouseEvents directly, and it then passes the click location information along to each panel, which does what it needs to with it. Each panel needs to know where it is on the background panel so it can figure out if the click landed on itself or not, but they probably already do if you're positioning them manually.

  • Redispatching MouseEvents Through GlassPane

    Hey all,
    I'm trying to do some drawing on a GlassPane overtop of a JFrame consisting of several Components. I followed the tutorial on GlassPanes I found [here |http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html#glasspane] to redispatch MouseEvents through the GlassPane to the proper Components underneath.
    For the most part, this works perfectly. But there are several Components for which this doesn't seem to redispatch correctly (I used a JComboBox in the SSCCE, but I'm experiencing a similar problem with JTabbedPane as well). The problem arises when a Component contains "extra parts" that overlap another Component (like when the JComboBox's list extends on top of the JPanel.. Or, I'm assuming, when a JTabbedPane's tabs do the same).
    Anyway, any insight into this would be much appreciated.
    SSCCE:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GlassPaneTest{
         JFrame frame = new JFrame("Testing GlassPane");
         public GlassPaneTest(){     
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
              frame.getContentPane().setLayout(layout);
              JPanel buttonPanel = new JPanel();
              buttonPanel.add(new JButton("button"));
              buttonPanel.add(new JComboBox(new String[]{"one", "two", "three"}));
              frame.add(buttonPanel);
              createGlassPane();
              frame.setMinimumSize(new Dimension(200,200));
              frame.setMaximumSize(new Dimension(200,200));
              frame.setPreferredSize(new Dimension(200,200));
              frame.setVisible(true);
         public void createGlassPane(){
              final Point mousePoint = new Point(0,0);
              final JPanel glassPanel = new JPanel(){
                   public void paintComponent(Graphics g){
                        super.paintComponent(g);
                        g.setColor(Color.GREEN);
                        g.fillOval((int)mousePoint.getX(), (int)mousePoint.getY(), 20, 20);
              MouseAdapter mouseAdapter = new MouseAdapter(){
                   public void mouseClicked(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mouseEntered(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mouseExited(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mousePressed(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mouseReleased(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mouseDragged(MouseEvent me){
                        redispatchMouseEvent(me);
                   public void mouseMoved(MouseEvent me){
                        mousePoint.setLocation(me.getX(), me.getY());
                        glassPanel.repaint();
                        redispatchMouseEvent(me);
                   public void mouseWheelMoved(MouseWheelEvent me){
                        redispatchMouseEvent(me);
                   public void redispatchMouseEvent(MouseEvent me){
                        Point glassPanelPoint = me.getPoint();
                        Container container = frame.getContentPane();
                        Point containerPoint = SwingUtilities.convertPoint(glassPanel,
                                                      glassPanelPoint, container);
                        if(containerPoint.getY() >= 0){
                             Component component =
                                  SwingUtilities.getDeepestComponentAt(container, (int)containerPoint.getX(), (int)containerPoint.getY());
                             if(component != null){
                                  Point componentPoint = SwingUtilities.convertPoint(glassPanel, glassPanelPoint, component);
                                  System.out.println("mouse " + component.getClass().toString());
                                  component.dispatchEvent(new MouseEvent(component,
                                            me.getID(),
                                            me.getWhen(), me.getModifiers(),
                                            (int)componentPoint.getX(),
                                            (int)componentPoint.getY(),
                                            me.getClickCount(),
                                            me.isPopupTrigger()));
                             else{
                                  System.out.println("null component");
              glassPanel.addMouseListener(mouseAdapter);
              glassPanel.addMouseMotionListener(mouseAdapter);
              glassPanel.setOpaque(false);
              frame.setGlassPane(glassPanel);
              glassPanel.setVisible(true);
         public static void main(String [] argS){
              new GlassPaneTest();
    }

    jboeing wrote:
    It appears that the Motif LnF doesn't actually contain the mouse-over highlight at all, even without a glass pane.:o right you are! I had to laugh at myself when I read this. I guess I was looking for things that went wrong since adding the GlassPane and started picking up on things that didn't actually change. Wow. Who knows how long I would have pounded away at that "problem" if you hadn't pointed that out?
    Otherwise, I did successfully get the lightweight solution to work:Thanks so much for taking the time to come up with and offer a solution. I also came across [this page|http://weblogs.java.net/blog/alexfromsun/archive/2006/09/a_wellbehaved_g.html] offering another solution (even to some problems that I didn't know about at first, interesting read).
    Following that page, I came up with this approach:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GlassPaneTest{
         JFrame frame = new JFrame("Testing GlassPane");
         JComboBox comboBox = new JComboBox(new String[]{"one", "two", "three"});
         public GlassPaneTest(){
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
              frame.getContentPane().setLayout(layout);
              JPanel buttonPanel = new JPanel();
              buttonPanel.add(new JButton("button"));
              buttonPanel.add(comboBox);
              frame.add(buttonPanel);
              createGlassPane();
              frame.setMinimumSize(new Dimension(200,200));
              frame.setMaximumSize(new Dimension(200,200));
              frame.setPreferredSize(new Dimension(200,200));
              frame.setVisible(true);
         public void createGlassPane(){
              final Point mousePoint = new Point(0,0);
              final JPanel glassPanel = new JPanel(){
                   public void paintComponent(Graphics g){
                        super.paintComponent(g);
                        g.setColor(Color.GREEN);
                        g.fillOval((int)mousePoint.getX(), (int)mousePoint.getY(), 20, 20);
                   public boolean contains(int x, int y){
                        return false;
              AWTEventListener awtListener = new AWTEventListener(){
                   public void eventDispatched(AWTEvent e){
                        if(e instanceof MouseEvent){
                             MouseEvent me = (MouseEvent)e;
                             MouseEvent converted = SwingUtilities.convertMouseEvent(me.getComponent(), me, glassPanel);
                             mousePoint.setLocation(converted.getX(), converted.getY());
                             glassPanel.repaint();
              Toolkit.getDefaultToolkit().addAWTEventListener(awtListener, AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
              glassPanel.setOpaque(false);
              frame.setGlassPane(glassPanel);
              glassPanel.setVisible(true);
         public static void main(String [] argS){
                        try {
                             UIManager
                             .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
                        } catch (Exception e) {
                             e.printStackTrace();
              new GlassPaneTest();
    }Does anybody see anything glaringly wrong with this? It seems to work perfectly, so I'm calling it a week :)
    Thanks again!

  • JPanel overlay which grabs all MouseEvents

    Hi all.
    I'm getting stuck with an OverlayLayout and a transparent JPanel.
    What I have is a JPanel with several components on it (Textfields, Comboboxes, ..)
    In the running application I need to be able to re-arrange the components using
    drag & drop but this feature can be disabled so the UI behaves like every other you know.
    (You can think of this as a minimalistic GUI designer).
    My approach was to place another (transparent) JPanel on top of it using OverlayLayout to
    be able to drag ghost copies of my components around with the mouse.
    This panel can be switched invisible so dragging is disabled.
    This works for components which do not react on mouse events for themselves
    (JLabels, ..) but not for textfields.
    What I would need is a transparent layer which is able to grab all MouseEvents so the
    components on the underlying panel will not receive them (textfields don't get the focus, buttons don't get clicked, ...).
    Any help really appreciated.
    Kind regards
    Carsten

    You can use a glass pane to intercept all the events. Just try to delete "Edit Me" from this text box!
    package mypackage;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GlassPanelTest extends JFrame {
        public GlassPanelTest() {
            super("Glass Panel Test");
            setBounds(10, 10, 380, 200);
            Container contentPane = getContentPane();
            contentPane.add(new JTextField("Edit Me"));
            Component glassPane = getGlassPane();
            glassPane.setVisible(true);
            glassPane.addMouseListener(new MouseAdapter() {
                public void mousePressed(MouseEvent _e) {
                    System.out.println("caught by the glass pane");
        public static void main(String[] args) {
            GlassPanelTest app = new GlassPanelTest();
            app.setVisible(true);       
    }

  • How to Give MouseEvents for JTabbedPane??

    Hi All,
    I have some 10 tabs in a single JTabbedPane,So if i want to enlight the tab like when i just take my mouse cursor onto any tab it should have some effect/color changing,it should be higlighted in a different way compared to the other tabs.How can i implement this mechanism???
    Thanks in advance.
    regards,
    Viswanadh

    UIManager.put("TabbedPane.selected", Color.YELLOW );This will, however, affect all tabbed panes in your application.

  • How can I prevent children from shrinking to infinitesimal values on MouseEvents?

    Hi.
    I have the following code:
    //http://forums.adobe.com/message/3450898#3450898
    //square_mc.y property edited by kglad AND NedMurphy both
    // but kglad introduced the yGap variable, allowing for
    // user defined space between movie clips.  This solved my
    // problem of evenly distributed spacing between movie clips
    // all of the other code I generated from either my own previous
    // files or by thinking about the solution and plugging away
    // at it.
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    var nextY:Number = 0;
    var yGap:int = 2;
    var container:MovieClip=new MovieClip();
    var containerBig:MovieClip=new MovieClip();
    containerBig.x=50;
    containerBig.y=50;
    containerBig.scaleX=1;
    containerBig.scaleY=1;
    addChild(container);
    addChild(containerBig);
    stage.addEventListener(Event.ENTER_FRAME, myFunc);
    /*var imageHolder_mc:MovieClip=new MovieClip();
    imageHolder_mc.graphics.beginFill(0x888888);
    imageHolder_mc.graphics.lineTo(300,0);
    imageHolder_mc.graphics.lineTo(300,200);
    imageHolder_mc.graphics.lineTo(0,200);
    imageHolder_mc.graphics.lineTo(0,0);
    var myFrames:Array=new Array();
    for (var i:int=0; i<12; i++){
    myFrames.push("my_"+i+"_mc");
    trace(myFrames+" myFrames");
    var square_mc:MovieClip=new MovieClip();
    square_mc.graphics.beginFill(0xFF0000);
    square_mc.graphics.lineTo(200,0);
    square_mc.graphics.lineTo(200,200);
    square_mc.graphics.lineTo(0,200);
    square_mc.graphics.lineTo(0,0);
    container.addChild(square_mc);
    square_mc.name="my_"+i+"_mc";
    trace(square_mc.name);
    square_mc.addEventListener(MouseEvent.MOUSE_OVER, myFunc2);
    square_mc.addEventListener(MouseEvent.MOUSE_OUT, myFunc3);
    //square_mc.scaleX=.25+(.13*Math.sin(i/Math.PI))*mouseY*.005;
    square_mc.scaleX=.25;
    square_mc.scaleY=square_mc.scaleX;
    square_mc.alpha=i*.1+.3;
    square_mc.y=nextY+mouseY*(-1);
    nextY+=square_mc.height+yGap;
    function myFunc(e:Event):void{
    container.y=-1*mouseY+stage.height;
    trace(container.y+" containerY");
    function myFunc2(e:MouseEvent):void{
    e.target.scaleX*=1.2;
    trace(stage.height+" stageHeight");
    e.target.addEventListener(MouseEvent.MOUSE_DOWN, myFunc4);
    e.target.mouseChildren=false;
    function myFunc3(e:MouseEvent):void{
    e.target.scaleX/=1.2;
    e.target.removeEventListener(MouseEvent.MOUSE_OVER, myFunc2);
    //add ImageHolder_mc MovieClip from Library and go to frame
    // coinciding with Array value in for loop . . .
    var imageHolder_mc:ImageHolder_mc=new ImageHolder_mc();
    function myFunc4(e:MouseEvent):void{
    containerBig.addChild(imageHolder_mc);
    for(var j:int=0; j<12; j++){
    if(e.target.name=="my_"+j+"_mc"){
    imageHolder_mc.gotoAndStop(j);
    trace(e.target.y+" e.target.y");
    you can troubleshoot the issue by adding a 12 frame MovieClip to your Library when you test this code and give it the names I referenced above in Bold.
    That is, whomever will have time to help me out.
    The problem I'm facing is not with loading the content of the Movie Clip, (though I might experience issues with that later when I try to load dynamic swfs) because as for now I just have placeholders on frames.
    What I want to know is why my red squares on the left navigation keep getting smaller as I repeat the MouseOver and MouseOut events.  It doesn't seem that these squares follow the logic of the code the way I have written it.  Some of the code was generated from a previous post with the help of contributors.
    Now I have again hit a slight snag with coding the math properly.  Initially when I tested the code it worked fine without any "shrinking" going on.  However, now with more code added the red navigation squares don't bounce back to their original states, they just keep getting smaller.
    Can anyone help me with this?
    Kindly thanking in advance,
    -markerline

    my new code:
    //http://forums.adobe.com/message/3450898#3450898
    //square_mc.y property edited by kglad AND NedMurphy both
    // but kglad introduced the yGap variable, allowing for
    // user defined space between movie clips.  This solved my
    // problem of evenly distributed spacing between movie clips
    // all of the other code I generated from either my own previous
    // files or by thinking about the solution and plugging away
    // at it.
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    //http://www.republicofcode.com/tutorials/flash/as3tweenclass/
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import fl.transitions.TweenEvent;
    var nextY:Number = 0;
    var yGap:int = 2;
    var container:MovieClip=new MovieClip();
    var containerBig:MovieClip=new MovieClip();
    containerBig.x=50;
    containerBig.y=50;
    containerBig.scaleX=1;
    containerBig.scaleY=1;
    addChild(container);
    addChild(containerBig);
    stage.addEventListener(Event.ENTER_FRAME, myFunc);
    /*var imageHolder_mc:MovieClip=new MovieClip();
    imageHolder_mc.graphics.beginFill(0x888888);
    imageHolder_mc.graphics.lineTo(300,0);
    imageHolder_mc.graphics.lineTo(300,200);
    imageHolder_mc.graphics.lineTo(0,200);
    imageHolder_mc.graphics.lineTo(0,0);
    var myFrames:Array=new Array();
    for (var i:int=0; i<12; i++){
    myFrames.push("my_"+i+"_mc");
    trace(myFrames+" myFrames");
    var square_mc:MovieClip=new MovieClip();
    square_mc.graphics.beginFill(0xFF0000);
    square_mc.graphics.lineTo(200,0);
    square_mc.graphics.lineTo(200,200);
    square_mc.graphics.lineTo(0,200);
    square_mc.graphics.lineTo(0,0);
    container.addChild(square_mc);
    square_mc.name="my_"+i+"_mc";
    trace(square_mc.name);
    var alreadyExecuted:Boolean;
    if(!alreadyExecuted){
    alreadyExecuted=true;
    square_mc.addEventListener(MouseEvent.MOUSE_OVER, myFunc2);
    square_mc.addEventListener(MouseEvent.MOUSE_OUT, myFunc3);
    //square_mc.scaleX=.25+(.13*Math.sin(i/Math.PI))*mouseY*.005;
    square_mc.scaleX=.25;
    square_mc.scaleY=square_mc.scaleX;
    square_mc.alpha=i*.1+.3;
    square_mc.y=nextY+mouseY*(-1);
    nextY+=square_mc.height+yGap;
    function myFunc(e:Event):void{
    container.y=-1*mouseY+stage.height;
    //trace(container.y+" containerY");
    function myFunc2(e:MouseEvent):void{
    //e.target.scaleX*=1.2;
    var myTween:Tween = new Tween(e.target, "scaleX", Elastic.easeIn, e.target.scaleX*1, e.target.scaleX*1.5, .1, true);
    //trace(stage.height+" stageHeight");
    e.target.addEventListener(MouseEvent.MOUSE_DOWN, myFunc4);
    trace(alreadyExecuted+" BOOLEAN");
    function myFunc3(e:MouseEvent):void{
    //e.target.scaleX/=1.2;
    var myTween:Tween = new Tween(e.target, "scaleX", Elastic.easeIn, e.target.scaleX*1, e.target.scaleX/1.5, .1, true);
    //e.target.removeEventListener(MouseEvent.MOUSE_OVER, myFunc2);
    //add ImageHolder_mc MovieClip from Library and go to frame
    // coinciding with Array value in for loop . . .
    var imageHolder_mc:ImageHolder_mc=new ImageHolder_mc();
    function myFunc4(e:MouseEvent):void{
    containerBig.addChild(imageHolder_mc);
    for(var j:int=0; j<12; j++){
      if(e.target.name=="my_"+j+"_mc"){
       imageHolder_mc.gotoAndStop(j);
    trace(e.target.y+" e.target.y");
    However, this code only ends up allowing the first thumbnail square to have the event listener.  I tried several variations of placement of the Boolean within the code but in some cases I got that nothing was functioning at all and in some cases I got that the Boolean didn't prevent the shrinking from occuring.  This code is as close as I got to calling the code to stop adding event listeners.
    I also tried:
    var alreadyExecuted+i:Boolean;
    if(!alreadyExecuted+i){
    code
    but I got an error telling me that it expects a semicolon before plus.  I guess you can't create numeric instances of  Booleans in the for loop.  The goal was to create a single boolean for each i in the loop to have a total of 12 booleans 0 through 11, one for each thumbnail so that the event listeners don't repeat as you suggested the Boolean would do.
    Still stumped.

  • MouseEvents in Flash CS4 (AS3)

    Hi everyone,
    I have some trouble with the mouse event listener. I am trying to execute code if the mouse is on a certain position in the stage, but the code should stop as soon as the mouse is pressed and then start again as soon as the mouse is released.
    Here is my code:
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePos);
    function mousePos( e:MouseEvent ):void{
         if(mouse is pressed){//This is where i need some help I don't know how to check if the mouse is DOWN.
              //do cool stuff here
         }else if(mouseX < (stage.stageWidth / 4)){
              mDs = ((mouseX - (stage.stageWidth / 4))^2)/((stage.stageWidth / 4)/20);
         }else if(mouseX > ((stage.stageWidth / 4)* 3)){
              mDs = ((mouseX - ((stage.stageWidth / 4)* 3))^2)/(((stage.stageWidth / 4))/20);
         }else{
              mDs = 0.5;
    Thank you for any help and tips!

    var isPressed:Boolean=false;
    stage.addEventListener(MouseEvent.MOUSE_DOWN,handleMouse);
    stage.addEventListener(MouseEvent.MOUSE_UP,handleMouse);
    function handleMouse(e:MouseEvent):void{
    isPressed = !isPressed
    function mousePos( e:MouseEvent ):void{
         if(isPressed){//This is where i need some help I don't know how to check if the mouse is DOWN.
              //do cool stuff here
         }else if(mouseX < (stage.stageWidth / 4)){
              mDs = ((mouseX - (stage.stageWidth / 4))^2)/((stage.stageWidth / 4)/20);
         }else if(mouseX > ((stage.stageWidth / 4)* 3)){
              mDs = ((mouseX - ((stage.stageWidth / 4)* 3))^2)/(((stage.stageWidth / 4))/20);
         }else{
              mDs = 0.5;

Maybe you are looking for

  • Charts in PowerPivot 2010

    I am uable to create charts out of Power Pivot.. It is only showing the table, but the data sheet for the charts is not available.  Do you have a solution for this problem? 

  • Moving controlfiles in Oracle DB 10.2.0.4

    Dear Expert, <br><br> Please help me, how to move controlfile from C:\oracle\CE2\origlogA\cntrl\filename.DBF to D:\oracle\CE2\origlogA\cntrl\filename.DBF.  We are using Windows Server 2003 64 bit, and Oracle 10.2.0.4. Please guide me <br><br> Regards

  • Jcombobox as cell editor behaviour !

    1. on a normal combobox, when it got focus & i pressed up/down, the display will change depending on the selected item... but it's not when it used as jtable cell editor. is it possible to change that behaviour ? i want a normal combobox behaviour ev

  • Oracle University Study Guide

    Does anybody know how to get Oracle University Study Guides ? Is it possible to buy them ? Thanks, Navid

  • Need to get a too large project onto a DVD

    I have a 9.5 GB iMovie 6 project that I need to get to a video editor, and because of the size, I cant get it on a DL DVD. Short of manually splitting it in two and burning each to a DVD, is there any other way I can get this project out? This projec