Attaching several buttons to one mouse listener

Attaching several buttons to one mouse listener
I have an application which consists of a GUI form, "EntryForm," and "DataForm," a collection of variables.
Clicking EntryForm's submit button sends the entries to DataForm.
The submit button is attached to a mouse listener "SubmitButtonHandler"
My Question: How can I attach an arbitrary number, up to five instances of EntryForm to ONE mouse listener?
I have tried this:
     final SubmitButtonHandler sbh = new SubmitButtonHandler( ...
     entryForm1 = new EntryForm();
     dataForm1 = new DataForm();
          entryForm1.submitButton.addMouseListener( sbh );
     entryForm2 = new EntryForm();
     dataForm2 = new DataForm();
          entryForm2.submitButton.addMouseListener( sbh );
     entryForm3 = new EntryForm();
     dataForm3 = new DataForm();
          entryForm3.submitButton.addMouseListener( sbh );
     entryForm4 = new EntryForm();
     dataForm4 = new DataForm();
          entryForm4.submitButton.addMouseListener( sbh );
     entryForm5 = new EntryForm();
     dataForm5 = new DataForm();
          entryForm5.submitButton.addMouseListener( sbh );
     ...In the mouse listener I have tried these approaches:
     public void mouseClicked( MouseEvent e ) {
          if ( e.getSource() == entryForm1.submitButton ) {
               System.out.println( "Clicked: entryForm1.submitButton" );
               // send the data to dataform1
          } else if( e.getSource() == entryForm2.submitButton ) {
               System.out.println( "Clicked: entryForm2.submitButton" );
               // send the data to dataform2
     public void mouseClicked( MouseEvent e ) {
          if ( e.getSource() == submitButton ) {
               if( e.getSource() == entryForm1.submitButton ) {
               // send the data to dataform1
               } else if( e.getSource() == entryForm2.submitButton ) {
               // send the data to dataform2
          } else if ( e.getSource() == anotherButton ) {
               ...In both cases, only ONE form's button registers and even that is screwy.
Can this approach be fixed so that the mous listener can discern between the various forms, or do I have to use five sets of forms and mouse listeners?
Many thanks in advance.

Hi,
Button1.addMouseListener(ourMouseListener);
Button1.setActionCommande("This is button 1");
Button2.addMouseListener(ourMouseListener);
Button2.setActionCommande("This is button 2");
In the "ourMouseListener" event method, you use this...
if((((JButton)event.getSource()).getActionCommand()).equals("This is button 1"))
Source code for Button1
if((((JButton)event.getSource()).getActionCommand()).equals("This is button 2"))
Source code for Button2
JRG

Similar Messages

  • Several buttons and one EventListener

    Hi everyone,
    I place 10 buttons on my stage, name it "b1", "b2", "b3",.. , "b10".
    All these buttons should use the same function.
    Is it possible to do it dynamically?
    var a: Array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    for (var i = 0; i < a.length; i++) {
    button = "b" + a[i];
      this[button].addEventListener(MouseEvent.CLICK, onClick_b);
      function onClick_b(pEvt: Event): void {
      my_mc.play();
    Only the button "b10" plays my function.
    Anyone an idea how to let all the other buttons play this function?
    Thank you! C.

    Thank you for your answers, this solution works, but I need an array in my project...
    Now my buttons are called "bone", "btwo", "bthree".
    var button: String;
    button = "b";
    var a: Array = ["one","two","three"];
    for (var i = 0; i < a.length; i++) {
        button = "b" + a[i];
         button.addEventListener(MouseEvent.CLICK, onClick_b);
    function onClick_b(pEvt: Event): void {
        my_mc.play();
    But it doesn't work...

  • How do I attatch several emails to one I'm sending out?

    How do I attach several email to one I'm sending out?

    Firefox doesn't do email, it's a web browser.
    If you are using Firefox to access your mail, you are using "web-mail". You need to seek support from your service provider or a forum for that service.
    If your problem is with Mozilla Thunderbird, see this forum for support.
    [http://www.mozillamessaging.com/en-US/support/] <br />
    or this one <br />
    [http://forums.mozillazine.org/viewforum.php?f=39]

  • How do you attach several jpegs in At

    I have Lion and use At & T email. I no longer can attach several jpegs at one time as an attachment in an email with Lion. I could using Snow Leopard

    You use the Mail app? Just drag all the photos you want to include into the message box.

  • How do I attach several files to an outgoing email?

    I am trying to attach several files to one outgoing email address.  I am looking for feedback on how this can be done or to be informed if it is not possible.  Thank you.

    Basically, it is not possible unless they are photos (max of 5) from with the Photo app or documents fom specific pps such as Goodreader. Otherwise, you open the app, select the document and then email.

  • Need several buttons that each target a video cue point but only one works

    I have the code that works for one button to find a cue point but how can I make this work for several buttons and their respective cue points?
      "seek-btn2" to find cue 2(named "lou2")
    import fl.video.*;
    // Video component instance name
    var flvControl:FLVPlayback = display;
    var flvSource:String = "lou.flv";
    // Set video
    flvControl.source = flvSource;
    // Add seek functionality to the button
    function seekHandler(event:MouseEvent):void
       flvControl.seekToNavCuePoint("lou1")
    //seek_btn is the button instance name
    seek_btn.addEventListener(MouseEvent.CLICK, seekHandler);
    when i repeat the last part of the code it does not work, thanks for your time....

    Thanks but where would I insert that code and what would I take out from the original code I posted?
    i tried this....
    import fl.video.*;
    // Video component instance name
    var flvControl:FLVPlayback = display;
    var flvSource:String = "lou.flv";
    // Set video
    flvControl.source = flvSource;
    seek_btn1.cuePointName = new String();
    seek_btn1.cuePointName = "lou1";
    seek_btn1.addEventListener(MouseEvent.CLICK, onButtonPress);
    seek_btn2.cuePointName = new String();
    seek_btn2.cuePointName = "lou2";
    seek_btn2.addEventListener(MouseEvent.CLICK, onButtonPress);
    // onButtonPress function
    private function onButtonPress(evt:MouseEvent):void {
         flvControl.seekToNavCuePoint(evt.target.cuePointName);

  • Is it faster to load several separate buttons, or one Nav?

    I'm working on a flash navigation for my site in development. I finished one of my buttons, I originally wanted to have each button as a separate flash object so if I wanted to change the name or what it looked like I could just swap it out rather then having to edit the .fla file. I'm using graphics I made in Photoshop for the button's bg. Also, each button has a sound on mouse-over.
    I'm planning to have five buttons in total. One button is 10KB on the compression settings that I am happy with. Would it be faster for the page loading time though if I combined all the buttons into one flash object consisting of five separate frames?
    Thanks!

    I'm not sure what you mean by independent folders.  You can always organize your Layers to have Layer folders but that is simply to organize the Layers and to collapse them to save real estate when necessary and expand them to see detail when necessary.  It won't make a difference how you structure your FLA because all of your buttons will be embedded in your Library in the single SWF at runtime.  So I guess you would still have all of the buttons externalized in the single SWF?  As opposed to embedding them in your master Site SWF?  Then you can use the load() method to load your buttons.swf file into your master.swf file .  You still might run the risk of your server not responding well to the load() method at times and failing to load your nav buttons as opposed to if you had them embedded in your master swf.  But if you have a reliable server and no bottleneck on your site then you could externalize all of your buttons.  One cool thing is to have your graphical appearance of your buttons embedded into your master.swf file and your button labels externalized into an XML file that is basically like a text HTML file that can be changed and updated using a simple text editor and you would never have to reauthor the FLA file to make changes.  You might even be able to format the font appearance but I'm not entirely sure since I'm still new to using XML to format content.  But I do know that XML can be used to change the content of the text such as what the text actually says.  You would externalize this .xml file the same way you would externalize an .AS actionscript file which would contain packages and classes as opposed to having your actionscript on Frame 1 of your FLA.

  • Why does the Back button require two mouse clicks?

    I've just upgraded to ver. 9 and now the Back button requires two mous clicks/

    I might not have used the word "Normal".  "Typical" maybe.  I suppose "Normal" is acceptable in the context of "SNAFU".
    Wait until you make an edit on one of your own posts to fix a stupid typo, then later look to find the typo back and you can no longer edit it.  And what's up with that messed-up Javascript that shows up at the top of some quoted messages?
    These forums are barely usable, but a bright spot is the color-managed photo attachment capability (i.e., you can upload an image with a non-sRGB color profile and the server will convert it).  I suppose if anything Adobe could have been expected to get that part right.
    -Noel

  • Tooltip/mouse listener question

    Hi all-
    I have a panel that contains various components that a user can move around. This is done by attaching a mouse listener and determining which component is currently being clicked/dragged.
    For a particular panel, I would like to display the x,y coordinates of a component in a tooltip, preferably while the user is moving it (which may not be possible with tool tips), but at least so that a user can see the updated coordinates after the component has been moved.
    However, when I setToolTipText for the component, it seems to override the mouse clicked events, and I can no longer even detect a click on the component.
    Is there a way that I can use tooltips and detect mouse clicks on the same component? Am I missing something simple, or do I need to find another way to do what I want to?
    Thanks
    Greg

    I searched posts last night but not today...oops.
    Found one today where a suggestion to something similar by mpmarrone was to use a Popup. It's now working, although I'm still not sure why tool tip text seems to take control of the mouse listener...

  • Problem with JPanel's mouse listener!

    I am developing a Windows Explorer-like program. I have an JPanel and added JLabels to that panel to reprensent the folders. I think, I kind of have to add mouse listener to JPanel to interact with mouse clicks, gaining and losing focus of JLabels etc. instead of adding every JLabel to mouse listener. So when I added to JPanel a mouse listener, it didn't work how I had expected. When I clicked on labels mouse click events didn't fire but when I clicked somewhere else in the panel it did fire. Is this a bug or am I using mouse listener incorrectly??
    Thank for advance :)
    Here is my JPanel's mouse listener ->
    public void mouseClicked(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    System.out.println("Mouse Clicked");
    Component c = this.getComponentAt(x,y);
    if(c instanceof JLabel){
    JLabel label = (JLabel) c;
    label.setBackground(Color.LIGHT_GRAY);
    }

    My main problem is as in windows explorer (if CTRL or SHIFT not pressed) there is only one selected folder (in my case JLabel) and transfering "selection" to one label to another might need lots of extra code.. So I thought using JPanel's mouse listener can overcome this handling problem. But if you are saying, this is the way it has to be done, then so be it :D :D

  • In the new version there's no little arrow with back or forward so you can go back several pages in one click. I use that a lot. How can I get it back?

    I've just upgraded Firefox and no longer have little arrows by the back and forward buttons on the toolbar. This means I can only click back or forward one page at a time. I used to be able to click on the arrow, see a list of previous pages and then go back (or forward) several pages with one click. I looked at adding the History button to the tool bar but that's not as convenient.

    You can get the drop down list by either right-clicking on the back/forward buttons, or holding down the left button until the list appears.
    If you want the drop-down arrow you can add it with the Back/forward dropmarker add-on - https://addons.mozilla.org/firefox/addon/backforward-dropmarker

  • Mii attach multiple files in one e-mail

    Hello everyone
    This is Yuko.
    There are two MII may have a problem with email attachments.
    1. Once you attach multiple files in one e-mail
    Please tell me how this
    2. Can not be above 1, and compiled into a single ZIP file.
    Now, I can attach multiple files in one e-mail,
    When you extract the ZIP, just made away with the file directory path is created,
    you can not open the attachment and open the folder several times.
    Anyone know a solution to this problem, please tell me.

    Kevin, Thanks for answers.
    My English is poor. Sorry.
    Your answer is, we assume that the permit issue, and probably would not matter. Again, write the points in need.
    For example, the two CSV when put together in one ZIP file, the workbench in the CSV file to specify the full path. CSV file, the workbench under the Web folder and then five in the second tier. At this time, who received an email with this attachment is to open the attachments, ZIP and open the file, open the following folder hierarchy, the next ..., and, many times to open the folder , will finally open a CSV file. Many times without opening the folder you want to open a CSV file.
    We look forward advice.

  • Why does a JButton automatically have a mouse listener registered with it?

    If I instantiate a JButton, I find there's a mouse listener already registered (see code below). Does anyone know why?
    Looking at the source code for JButton, I can't see how this is. If a create a dummy subclass of AbstractButton (of which JButton is a direct subclass) and instantiate that, it has no mouse listeners, and likewize with Button. So what is it about JButton?
    The reason I ask is that I've seen in a book on swing that you must call enableEvents(AWTEvent.MOUSE_EVENT_MASK) on a JButton if you want processMouseEvent to get executed. But it actually gets executed even if enableEvents hasn't been called, and the only reason for this is surely that there is a mouse listener registered, which there is, but why?
    Might the reason be that JButton extends Accessible?
    Code:
    JButton jb = new JButton("Dummy");
    MouseListener[] mls = (MouseListener[])(jb.getListeners(MouseListener.class));
    JOptionPane.showMessageDialog(this, (new Integer(mls.length)).toString(), "Number of Mouse Listeners", JOptionPane.INFORMATION_MESSAGE);

    Hello,
    That listener is installed by the JButton's UI. You might want to have a look at the source code of BasicButtonUI and BasicButtonListener to understand what they are used for. For example, mousePressed in BasicButtonListener is used to call setArmed on the JButton.
    My best advice is for you not to worry about this at all.

  • TS3276 Hi.  Just started using Mac Mail on a macbookpro v10.6.8.  I tried to send a message with two excel (for mac) files attached.  One attached as a file, one inserted all the text into the message body.  Help?

    Just started using my Mac Mail program instead of web mail.  When I went to attach two pdf files, one attached as a file, the other inserted all the text into the body of the email message.  How do I get it to attach both pdf's as files?

    I think you're confusing two different things. If you attached PDF files and one of them displayed the PDF icon in the message window, that means it was more than one page. If you saw what appeared to be the actual document for the other PDF file, that means it's only one page and it's normal for it to display that way.
    However, I seem to recall there may (or should) be a button at the bottom-right of the message window that allows you to display those files as icons, even if they're one page. If not, there's a third-party addition you can use to add that feature:
    http://lokiware.info/Attachment-Tamer

  • Some one please Listen

    Hi,
    Please help I need to create a project in just 2 weeks, in which user inputs his ID and Password which has to be verified in database, I m new to Sun java Studio Creator
    how do i do this can anybody send me a code sample...
    i hv tried with tutorials but no success.... plz help...........
    Thanks!
    Priya

    This is a snippet from an internal application login page I'm working on. The rowsets have to be set up to retrieve whatever information your looking for. I opted to go for separate rowsets for each user type (region, center, user) rather than hand-code a specific query for each one.
    Here is the code from my login button:
    public String btnLogin_action() {
            String login = (String)txtLogin.getValue(); //Login value
            String pass = (String)txtPassword.getValue(); //Password value
            /** types:
             *  region 3
             *  center 2
             *  user   1
            try{
                 //set up rowset to match the required loginname and password
                 // if you don't know how to set up rowsets, I'm afraid you'll have to look elsewhere for a tutorial, too much for me to type!
                regionsRowSet.setString(1,login);
                regionsRowSet.setString(2,pass);
                regionsRowSet.execute();
                // if region exists, rowset.next() will return info specified in query
                if (regionsRowSet.next()){
                     //store login info in sessionbean
                    getSessionBean1().setUsertype(3);
                    getSessionBean1().setLoginname(login);
                    getSessionBean1().setPassword(pass);
                    getSessionBean1().setName(regionsRowSet.getString("region"));
                    // and finally switch to the admin login page
                    return "radmin";
                   //if rowset.next() returns nothing, try the next login class
                } else{
                    centersRowSet.setString(1,login);
                    centersRowSet.setString(2,pass);
                    centersRowSet.execute();
                    if (centersRowSet.next()){
                        getSessionBean1().setUsertype(2);
                        getSessionBean1().setLoginname(login);
                        getSessionBean1().setPassword(pass);
                        getSessionBean1().setName(centersRowSet.getString("center"));
                        return "cadmin";
                    }else{
                        usersRowSet.setString(1,login);
                        usersRowSet.setString(2,pass);
                        usersRowSet.execute();
                        if (usersRowSet.next()){
                            getSessionBean1().setUsertype(1);
                            getSessionBean1().setLoginname(login);
                            getSessionBean1().setPassword(pass);
                            getSessionBean1().setName(usersRowSet.getString("name"));
                            getSessionBean1().setId(usersRowSet.getInt("id"));
                            return "elogin";
            } catch (Exception e) {
                log("Page1 Initialization Failure", e);
                throw e instanceof javax.faces.FacesException ? (FacesException) e: new FacesException(e);
            return null;
        }Hope this helps abit.
    IMPORTANT SIDENOTE: If you title your post with "Some one please Listen" and then go on to say you have to develop an app in 2 weeks, and don't know the first thing about database queries or logins, most will laugh and move on to the next post. I feel a bit of pity and remember when I was starting out, perhaps it's just your poor English making me , and likely most others, misunderstand. In the future, if I were you, I would use a bit more professional language to describe my problem. Just some friendly advice,
    Cre

Maybe you are looking for

  • Custom Report taking more time to complete Normat

    Hi All, Custom report(Aging Report) in oracle is taking more time to complete Normal. In one instance, the same report is taking 5 min and the other instance this is taking 40-50 min to complete. We have enabled the trace and checked the trace file,

  • Configuration error when open admin tool in BIEE 11g client

    Hi All, I have installed BIEE 11g client in my laptop,the version is 11.1.6.2 ,it has show one error in the installation log : <action name="Custom Action" target="oracle.bi.CustomIAActionGetInstanceNumber" status="error"> - <AdditionalNotes> <error>

  • SQL error 1691 in qrfc monitor

    Hi, I am running a simple file - xi - mail scenario. In SXMB_MONI, the xml messages are showing a green flag, and messages are stuck in inbound queue. The error is SYSFAIL: SQL error 1691 occurred when accessing table SXMSCLUP2. Has anyone faced this

  • How do I get iTunes to list music in my iTunes library?

    All of my music appears to be correctly located in the iTunes library file, but none will display when I open iTunes.  As a test, I just purchased a song from the iTunes store; it downloaded into the same file where all my other songs reside, but the

  • Testing WebDynpro Adobe Interactive forms Using eCATT or any other testing

    Hi All, We are testing WebDynpro Adobe forms (Java). is there any methodology to test Interactive forms not normal webdynpro applications. Especially Interactive form with UI fields like dropdwons, datepickers dropdown values are from BAPI/RFC's  in