Registering an action listener interface

How do i register an action listener interface to a java program which has three textfields and three buttons. addition,multiplication and subtraction respectively so that when i click on a button it sums,multiply,and subtracts the numbers and displays the output in the third textfield box using the swing components.

** BUT a more important point i wanted to
express/share is that... it is actually better if we
TRY to avoid using ActionCommand while
handling such scenarios !!!Let me show the way i modified the Calculate.java pgm..
(Thanks to @Wildcard82 )
//~~~~~~~~~~~~
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Calculate extends JFrame implements ActionListener
    private static final long serialVersionUID = -1558653254398328438L;
    private JTextField field1, field2, field3;
    private JButton add, subtract, multiply;
    // HAVE to be instance fields now...
    // so that they're visible in the actionPerformed() method...! :)
    private enum Operations{
        add,subtract,multiply
    public Calculate()
        setLayout(new GridLayout(2,3));
        field1=new JTextField(5);
        field2=new JTextField(5);
        field3=new JTextField(5);
        add = new JButton("add");
        //add.setActionCommand("add"); // * NO need to set the Action-Command..!
        add.addActionListener(this);
        subtract = new JButton("subtract");
        subtract.addActionListener(this);
        multiply = new JButton("multiply");
        multiply.addActionListener(this);
        add(field1);add(field2);add(field3);
        add(add); add(subtract); add(multiply);
    } /* default c'tor */
     * @param args
    public static void main(String[] args)
        Calculate c = new Calculate();
        c.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        c.setVisible(true);
        c.pack();
    } /* end main() */
     * A simpler & nicer version of actionPerformed() that works
     * even when you internationalize your Calculator App...
     * ..since, it does NOT depend on Action-Commands but just on the
     * Event-Source objects, which DON"T change when you do I18N...! :)
    public void actionPerformed(ActionEvent ae)
        Object source = ae.getSource();
        if(source==add)calculate(Operations.add);       
        else if(source==subtract)calculate(Operations.subtract);       
        else if(source==multiply)calculate(Operations.multiply);       
    } /* end method() */
    private void calculate(Operations operation)
        int n1, n2;
        n1=Integer.parseInt(field1.getText());
        n2=Integer.parseInt(field2.getText());
        if(operation==Operations.add)
            field3.setText(String.valueOf(n1+n2));
        else if(operation==Operations.subtract)
            field3.setText(String.valueOf(n1-n2));
        else if(operation==Operations.multiply)
            field3.setText(String.valueOf(n1*n2));
         else
            field3.setText("");
    } /* end method() */
} /* end class */
//~~~~~~~~~~~~
Thanks,
"r a g h u"
// [email protected]

Similar Messages

  • JComboBox action listener

    I have registered an action listener on a JComboBox.. I change the selected value of this combobox from another component's actions also.. My question is how can i distinguish between an action event in which an item was selected using the combo box directly and an event in which the selected value in the combo box was set by different comopnent.. the actionEvent.getSource gives the combo box itself..
    Is using a mouselistener the only way out??

    You can't and its a bad design to attempt to do so.dont know about bad design but.. in my case its required. I have to make a file chooser type User interface for browsing an ftp site.. So the combo box needs to be updated when the user changes a directory by double clicking on the directory.. Could i do something else?? please suggest anything u can
    >
    Is using a mouselistener the only way out?? What about if the user uses the key board to select
    the item from the combo box? Would you also need to
    write your own KeyListener? Getting very ugly.good point.. didnt think about this....now i understand why they used action listener
    >
    As a workaround, you could add code to your "other"
    compnent:
    comboBox.removeActionListener(...);
    comboBox.setSelectedItem(...);
    comboBox.addActionListener(...);thanks, does this have a significant performance penalty.. I mean it does not look good does it??

  • XE is not registering with the listener

    hi forum,
    i installed oracle xe on an empty xp box. everything went smoothly but - like for so many others - my db homepage is not showing (http://127.0.0.1:8080/apex). but thats a different story.
    i can connect with sqlplus, i can create, insert into and select from tables. tnsping is resolving localhost, xe, puss (my xp host name), 127.0.0.1 as well as the host ip (192.168.1.102).
    my problem is that the db instance doesn't seem to register with the listener, so that when i do a sqlplus andy/passwd@XE i get the german version of what would be ORA-12514: TNS: Listener can't resolve service listed in connect discriptor
    when i do a lsnrctl status i get the following:
    LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 01-AUG-2010 11:53:26
    Copyright (c) 1991, 2005, Oracle.  All rights reserved.
    Anmeldung bei (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
    STATUS des LISTENER
    Alias                     LISTENER
    Version                   TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ
    ction
    Startdatum                31-JUL-2010 22:52:37
    Uptime                    0 Tage 13 Std. 0 Min. 48 Sek.
    Trace-Ebene               off
    Sicherheit                ON: Local OS Authentication
    SNMP                      OFF
    Standard-Service           XE
    Parameterdatei des Listener C:\oraclexe\app\oracle\product\10.2.0\server\network\admin\listener.ora
    Log-Datei des Listener    C:\oraclexe\app\oracle\product\10.2.0\server\network\log\listener.log
    Zusammenfassung Listening-Endpunkte...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC_FOR_XEipc)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=puss)(PORT=1521)))
    Services Übersicht...
    Dienst "CLRExtProc" hat 1 Instance(s).
      Instance "CLRExtProc", Status UNKNOWN, hat 1 Handler für diesen Dienst...
    Dienst "PLSExtProc" hat 1 Instance(s).
      Instance "PLSExtProc", Status UNKNOWN, hat 1 Handler für diesen Dienst...
    Der Befehl wurde erfolgreich ausgeführt.the german msgs say that everything is in order basically, but what is certainly not in order is that there is no XE listed.
    show parameter local_listener; revealed: no local listener set.
    alter system set local_listener=XE; or
    alter system set local_listener='(address=(protocol=tcp)(host=puss)(port=1521))'; and then
    alter system register; didn't make the instance show in listener status
    i would at least expect to see the attempt to register in the listener.log but nothing.
    when i added the host to SID_LIST in listener.ora the instance was listed in the listener status, but status remained unknown, what ever i tried.
    i know that there are other threads dealing with the same issue, but none of the solutions provided worked for me.
    i am in a home network with two other macs connected via wlan. my firewall is turned off. i've tryed every combination of tnsnames.ora and listener.ora settings but nothing worked. after 13 hours of trail and error, reading a lot, wiping the whole box and reinstalling everything from scratch, sitting in front of my vanilla xp plus oracle xe installation, i'm tyred. i need your help.
    Andy
    tnsnames.ora
    XE =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = puss)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = XE)
    EXTPROC_CONNECTION_DATA =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
        (CONNECT_DATA =
          (SID = PLSExtProc)
          (PRESENTATION = RO)
    ORACLR_CONNECTION_DATA =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
        (CONNECT_DATA =
          (SID = CLRExtProc)
          (PRESENTATION = RO)
    listener.ora
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = PLSExtProc)
          (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
          (PROGRAM = extproc)
        (SID_DESC =
          (SID_NAME = CLRExtProc)
          (ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
          (PROGRAM = extproc)
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
          (ADDRESS = (PROTOCOL = TCP)(HOST = puss)(PORT = 1521))
    DEFAULT_SERVICE_LISTENER = (XE)
    sqlnet.ora
    SQLNET.AUTHENTICATION_SERVICES = (NTS)

    It turned out that the failing http://127.0.0.1:8080/apex actually was related.
    After cutting the network connection and restarting the listener and the db everything worked fine, even the web admin interface.

  • In JavaFX, is binding an alternative to action-listener ?

    Hi , I was wondering if in JavaFX, binding can be an alternative to action listener/events ? Can we handle all actions with binding instead of event handling ?

    Bindings can't be used as an alternative to handling events that represent a user action, such as ActionEvents, MouseEvents, or KeyEvents. ActionEvents are generated when the user takes a specific action, such as pressing a button, or pressing the Enter key in a TextField. There is nothing you can really bind to in this situation.
    JavaFX defines a Property API which enables the creation of observable properties (and observable values, of which observable properties are a specific example). You can register ChangeListeners with these observable properties to be notified when their values change. So for example, TextField has a textProperty containing the value of the text in the text field. If you register a change listener with the text field's textProperty, it will be notified whenever the text in the text field changes. (Note that the notification will happen essentially on every key stroke in the text field, not just when the user commits a value with Enter.)
    Bindings present a simpler alternative to a particular use case for change listeners on these properties: namely when the change listener would simply update the value of another property. For example the following:
    final Label label = new Label();
    final TextField textField = new TextField();
    final VBox vbox = new VBox();
    vbox.getChildren().addAll(label, textField);
    label.textProperty().bind(textField.textProperty());
    will cause the label to change to match the text in the text field.
    See Using JavaFX Properties and Binding | JavaFX 2 Tutorials and Documentation for a fuller discussion of properties and binding.

  • Export collection action listener error after second call

    Hi all,
    I am using the operation export collection action listener to export to excel the content of a table. The first time I clicked the button to export, Microsoft Excel open with the table  information correctly but if  I want to export again then I got the following error:
    <08-ago-2013 21H54' VET> <Error> <oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter> <BEA-000000> <ADF_FACES-60096:Excepción del Servidor durante PPR, #1
    java.lang.IllegalStateException: ADF_FACES-60003: Component with ID: pt1:r8:4:b1 not registered for Active Data.
      at oracle.adfinternal.view.faces.activedata.PageDataUpdateManager.unregisterComponent(PageDataUpdateManager.java:615)
      at oracle.adfinternal.view.faces.context.RichPhaseListener.handleStartAndStopActiveData(RichPhaseListener.java:478)
      at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:540)
      at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:225)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:192)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:478)
      at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:478)
      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:303)
      at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:208)
      at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:202)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:137)
      at java.security.AccessController.doPrivileged(Native Method)
      at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
      at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
      at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:120)
      at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:217)
      at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:81)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:225)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3367)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
      at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
      at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
    Any Idea?
    Jhon Carrillo
    Jdev 12c

    Hi,
    there is a bug filed for this that has been fixed for the first (upcoming) Patch Set of 12c. Until then the solution seems to be to get the current row before exporting the table and then to set it back afterwards. So what you can try is to create a hidden button for the export of the table. Say you name the button "expBut". Then have another button with a action reference to a managed bean. This button now will invoke the following code
    1. read the current row from the table iterator (bindings --> (DCIteratorBinding) bindings.get("iteratorName") --> (Row) dcIterator.getCurrentRow()
    2. invoke the hidden button: ActionEvent ae = new ActionEvent(expBut); ae.queue();
    3. Set current row back to where it was: dcIterator.setCurrentRowWithKey(row.getKey().toStringFormat(true));
    At least this seems to be the internal bug fix.
    Alternatively, disable PPR on the binding layer (ChangeEventPolicy=None on the iterator) and set the same on the PartialTrigger property of the component.
    Frank

  • Action listener activation in many phases

    I need action listener (methods) to be activated in many phases. I.e., when the user clicks a submit button, I want code to be executed (in my case) after the validation phase and after (during) the invoke application phase. In earlier version of the standard, I would just register 2 listeners, returning the appropriate getPhaseId() value. Since this method is removed from the current standard, things get more complicated.
    QUESTION: Why in heavens name was this method removed from the standard? I suppose, because it is difficult to support with listener methods (in contrast to instances)? Bit of a rough solution, no? Or am I missing something?
    I have a solution now, I think, that is based on getting the action event immediate, and requeuing the event again and again.
    In the JSP, in the JSF form, I have a submit button as follows:
    <h:commandButton id="buttonId" value="ButtonText"
                     actionListener="#{handler.buttonListener}"
                     immediate="true"/>The method Handler.buttonListener is:
      public final void buttonListener(ActionEvent ae) {
        LOG.debug("Handler. buttonListener called ("
                  + "ActionEvent.getPhaseId() = " + ae.getPhaseId()
                  + "; ActionEvent.getComponent() = " + ae.getComponent()
                  + ")");
        PhaseId phaseId = ae.getPhaseId();
        if (phaseId.equals(PhaseId.APPLY_REQUEST_VALUES)) {
          LOG.debug("-- processing during " + ae.getPhaseId());
          // meaningful stuff here
          // prepare for execution in next phase
          ae.queue();
            /* this sets phase id to the current phase, so it is extremely important that
             * we set the necessary phase id AFTER queuing the event */
          ae.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
          LOG.debug("-- ActionEvent (getPhaseId() = " + ae.getPhaseId() + ") queued");     
        else if (phaseId.equals(PhaseId.PROCESS_VALIDATIONS)) {
          LOG.debug("-- processing during " + ae.getPhaseId());
          // meaningful stuff here
          // prepare for execution in next phase
          ae.queue();
          /* this sets phase id to the current phase, so it is extremely important that
           * we set the necessary phase id AFTER queuing the event */
          ae.setPhaseId(PhaseId.INVOKE_APPLICATION);
          LOG.debug("-- ActionEvent (getPhaseId() = " + ae.getPhaseId() + ") queued");     
        else if (phaseId.equals(PhaseId.INVOKE_APPLICATION)) {
          LOG.debug("-- processing during " + ae.getPhaseId());
          // meaningful stuff here
        LOG.debug("Handler. buttonListener done");
      }The /* */ comment in the code is there because the queue methods (on the event as well as the component) set the phase id of the event to the current phase. If I set the phase id of the event before queuing it, that setting is undone, and I get an infinite loop! This is weird, and my solution is at least shaky: it doesn't feel stable across JSF implementations and future releases. I could not find a queue method that leaves the phase id alone.
    QUESTION: am I missing something?
    The output however is:
    Mar 21, 2005 12:51:11 PM org.exadel.jsf.PhaseTracker beforePhase
    INFO: BEFORE RESTORE_VIEW 1
    Mar 21, 2005 12:51:11 PM org.exadel.jsf.PhaseTracker afterPhase
    INFO: AFTER RESTORE_VIEW 1
    Mar 21, 2005 12:51:11 PM org.exadel.jsf.PhaseTracker beforePhase
    INFO: BEFORE APPLY_REQUEST_VALUES 2
    12:51:12,119 DEBUG Handler:550 - Handler.buttonListener called
          (ActionEvent.getPhaseId() = APPLY_REQUEST_VALUES 2;
           ActionEvent.getComponent() = javax.faces.component.html.HtmlCommandButton@33b99a)
    12:51:12,171 DEBUG Handler:556 - -- processing during APPLY_REQUEST_VALUES 2
    12:51:12,184 DEBUG Handler:564 - -- ActionEvent (getPhaseId() = PROCESS_VALIDATIONS 3) queued
    12:51:12,189 DEBUG Handler:580 - Handler.buttonListener done
    12:51:12,220 DEBUG Handler:550 - Handler.buttonListener called
         (ActionEvent.getPhaseId() = PROCESS_VALIDATIONS 3;
          ActionEvent.getComponent() = javax.faces.component.html.HtmlCommandButton@33b99a)
    12:51:12,255 DEBUG Handler:567 - -- processing during PROCESS_VALIDATIONS 3
    12:51:12,256 DEBUG Handler:574 - -- ActionEvent (getPhaseId() = INVOKE_APPLICATION 5) queued
    12:51:12,257 DEBUG Handler:580 - Handler.buttonListener done
    12:51:12,265 DEBUG Handler:550 - Handler.buttonListener called
        (ActionEvent.getPhaseId() = INVOKE_APPLICATION 5;
         ActionEvent.getComponent() = javax.faces.component.html.HtmlCommandButton@33b99a)
    12:51:12,267 DEBUG Handler:577 - -- processing during INVOKE_APPLICATION 5
    12:51:12,268 DEBUG Handler:580 - Handler.buttonListener done
    Mar 21, 2005 12:51:12 PM org.exadel.jsf.PhaseTracker afterPhase
    INFO: AFTER APPLY_REQUEST_VALUES 2
    Mar 21, 2005 12:51:12 PM org.exadel.jsf.PhaseTracker beforePhase
    INFO: BEFORE RENDER_RESPONSE 6
    Mar 21, 2005 12:51:12 PM org.exadel.jsf.PhaseTracker afterPhase
    INFO: AFTER RENDER_RESPONSE 6The info is generated by a phase listener I found somewhere (sorry for the lack of reference here to the author). As you can see, I get 3 consecutive calls of my listener method, but they are all during the apply request values phase, and we jump from the apply request values phase immediately to the render response phase, skipping all the other phases, although my listener is actually called 3 times.
    QUESTION: what the fuck? What is happening here, and more important, how can I fix it?

    I am in touch with IBM about any patch they might have for this. I just thought I'd post details from what I researched.
    Basically I found that if I had CommandButton and/or CommandLink components on my page and clicked them for a total greater than 15 times, the application just quit reacting to any of the clicks. After writing a PhaseListener I discovered that after 15 clicks the JSF lifecycle was going straight from the Restore View (1) to Render Response (6) phase instead of going through the ones in between.
    I downloaded the JSF source code and tracked down the magic number 15. As mentioned earlier in this forum it has to do with the number of views per session. In the Sun JSF-RI com.sun.faces.application.StateManagerImpl class
    the number of views is defaulted to 15. When the number of views hits the max the oldest view is deleted. Somehow I don't think they are deleting the oldest view or else why my app quits after 15 clicks I do not know. Anyway this is a known issue with the Sun JSF-RI and documented in their Release Notes.
    Depending on the JSF implementation there may or may not be a workaround. I mean to say the the workaround is not part of the JSF spec but Sun's implementation has a feature where you can configure the com.sun.faces.NUMBER_OF_VIEWS_IN_SESSION value in the web.xml file under the <context-param> tag. If you set the value sufficiently high you lower the risk of the app quitting on you (like a user may be unlikely to make 100 or even 50 clicks on the same page). You might also want to set the state to be saved on the server by setting javax.faces.STATE_SAVING_METHOD to server in another <context-param> tag. Somehow setting this state to client caused errors (NullPointerException) in our app in one of the Faces classes itself.
    Hope this helps someone out there.

  • Notify JComboBox action listener ?

    Hi,
    i would like to notify the action listener of a JComboBox by myself (like doing a doClick for a JButton). What is the method that i could use for it ?

    JComboBox cbo1;
    cbo1.addItemListener(this);
    or you could use
    cbo1.addActionListener(this);
    for the first one have
    public void itemStateChanged(ItemEvent ie)
    if(ie.getSource()==cbo1)
    your code
    extend interface ItemListener
    for second one have
    public void actionPerformed(ActionEvent ae)
    if(ie.getSource()==cbo1)
    your code
    extend interface ActionListener
    Is this what u need ?

  • JTextField action listener

    Hi All,
         I have added an action listener to a TextField,im printing the text entered in textfiled by pressing the enter key of keyboard.
          public void actionPerformed(ActionEvent ae) {
                   System.out.println(jtf.getText());
             } my question is as an when i enterd the text in the textfield i want to printit . please help me to solve this.
    Thanks

    Yannix wrote:
    Add a keyListener in your JTextField.
    http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html
    I've always thought that it is better to use solutions that use a higher level of abstraction compared to solutions that use a lower level. If so, then using key Binding may be a better solution. If this is wrong, please let me know. You can learn about key Bindings here:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
    One statement in this tutorial compares key bindings to keylisteners:
    An alternative to key bindings is using key listeners. Key listeners have their place as a
    low-level interface to keyboard input, but for responding to individual keys key bindings are more
    appropriate and tend to result in more easily maintained code. Key listeners are also difficult if
    the key binding is to be active when the component doesn't have focus. Some of the advantages
    of key bindings are they're somewhat self documenting, take the containment hierarchy into
    account, encourage reusable chunks of code (Action objects), and allow actions to be easily
    removed, customized, or shared. Also, they make it easy to change the key to which an action
    is bound. Another advantage of Actions is that they have an enabled state which provides an
    easy way to disable the action without having to track which component it is attached to.
    In the future Swing related question should be posted in the Swing forum.
    http://forum.java.sun.com/forum.jspa?forumID=57
    Agree 100%

  • ADF TUTORIAL: PROBLEMS WITH "Export Collection Action Listener"

    hello all,
    environment:
    windows xp
    jedev 11.1.1.3.0
    firefox 3.6.13
    tutorial: Developing Ajax-Based User Interfaces with JSF: An Introduction to ADF Faces Rich Client Components
    url: http://st-curriculum.oracle.com/obe/jdev/obe11jdev/ps1/adf_richclient/adfrichclient.htm
    mainstep: "working with menus"
    substep: number 5 "add collection action listener"
    until the step "working with menus" works everthing fine. after i added the collection action listener and saved my work, the webapplication will not open. i see only a blank page and no error message.
    when i delete the action listener works everything fine again.
    how can i fix this issue? thx to everyone.
    best regards
    gunnar

    I'm not sure if this is going to help anyone , but if you're stuck at that point of the tutorial , try to drop the "Export Collection Action Listener" onto the menuItem "Export To Excel" not under it;
    So the xml under the source tab should look something like this :
    <f:facet name="menus">
    <af:menu text="My Options" id="m2" detachable="true">
    <af:commandMenuItem text="Export To Excel" id="cmi1">
    <af:exportCollectionActionListener type="excelHTML"
    exportedId="t1"/>
    </af:commandMenuItem>
    <af:commandMenuItem text="Show Specials" id="cmi2">
    <af:showPopupBehavior popupId=":::p1"/>
    </af:commandMenuItem>
    </af:menu>
    Hope this helped somebody .

  • Event delegation model VS Listener interfaces?

    hello again,
    i got confused with "event delegation model and Listener interfaces".are both of these things are same or they are completely opposite, or they go hand in hand?
    can any body help me understand that concept.
    thanks

    event delegation would be the concept, passing out events to interested parties. listener interfaces and registering them with the event sources would be the implementation of that concept.

  • How can i disable an Action listener temporary?

    hi folks,
    I have a GUI with many Jcomboxes. Each one of them has an actionlistener.
    The idea was: when one of those comboboxes is selected, then the selected value will appear on ALL the comboboxes (by using setSelectedIndex(int index)).
    The problem is when i select a value on ONE of those comboboxes and set it on the others, the actionListener thinks that i selcted a value on the other comboboxes and starts setting the values again... I other words if i select one combobox i obtain an endless loop...
    Is it possible to disable the action listener temporary when setting the selectd values on the other comboboxes?

    Just use removeActionListener and then addActionListener
    Noah

  • Property on Backing Bean is Not set when Action Listener is Fired

    Why is it that when my action listener is invoked, the property for my other component on the page has not been reflected in model yet?
    Here is what I have:
    My JSP has the following two components:
    <h:inputText value="#{manageQuestionBean.newStory}"></h:inputText>
    <h:commandButton value="add" actionListener="#{manageQuestionBean.onAddStory}"></h:commandButton> My Java code has the following:
    public void onAddStory(ActionEvent event) {
           //This always prints out 'null'
           System.out.println("The value of 'newStory' is: " + newStory);
          //TO DO: this is where the logic would go for creating a new story object.
        } When I put logging statements inside my setter for the newStory property, I see that it is being set to the right value, but then it being reset to empty string. Why is that? During what phase do the action listeners get invoked?

    Which JSF implementation/version are you using?
    mczauz wrote:
    When I put logging statements inside my setter for the newStory property, I see that it is being set to the right value, but then it being reset to empty string. Why is that? When exactly happens when exactly?
    During what phase do the action listeners get invoked?The invoke application phase, after the update model values phase.
    You may find this article useful to learn about phases and how to add a 'phase debugger' yourselfl: [http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html].

  • Transaction Posting Confirmation Message and Action Listener behaviour

    Hi, I have a scenario that a user is Posting a Transaction and when he press the “Post” Button a, confirmation dialog box should popup asking “Do you really want to Post the record ?”. If the user press “Yes” the record is further process and If the user press “No” then the transaction should not proceed.
    I have implemented the main screen(PostTransaction.java) and the popup confirmation window(ConfirmationWindow.java)
    Question 1 ) Why the code is not stoping in the Post Button Action listener as in JOptionPane, then how do i know that the user has selected "Yes" or "No" ?
    Question 2) Do I have to write the code for posting of a Transaction(postTransaction() method) in the “ConfirmationWindow”? or it should be in “PostTransaction”.
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    public class PostTransaction extends Application{
           public void start(final Stage stage) throws Exception {
                  Group root = new Group();
                  Scene scene = new Scene(root, 300,300);
                  stage.setScene(scene);
                  stage.setTitle("Transaction Post Screen");
                  GridPane gp = new GridPane();
                  Label lblName = new Label("Name");
                  Label lblAmount = new Label("Amount");
                  TextField txtName = new TextField();
                  TextField txtAmount = new TextField();
                  Button btnPost = new Button("Post Record");
                  gp.add(lblName, 1, 1);
                  gp.add(lblAmount, 1, 2);
                  gp.add(txtName, 2, 1);
                  gp.add(txtAmount, 2, 2);
                  gp.add(btnPost, 2, 3);
                  btnPost.setOnAction(new EventHandler<ActionEvent>() {
                        @Override
                        public void handle(ActionEvent arg0) {
                             //The code does not stop here as in JOptionPane, then how do i know that the user has selected "Yes" or "No" ??
                             boolean popupResult = ConfirmationWindow.confirmTranactionPosting(stage, "Please Confirm");
                             if(popupResult==true){
                                  //This line is printed before the user selects yes or no
                                  System.out.println("Proceeding with Tranaction Posting");
                                  //postTransaction();
                             if(popupResult==false){
                                  //This line is printed before the user selects yes or no
                                  System.out.println("Do not Proceed with Tranaction Posting");
                 root.getChildren().add(gp);
                stage.show();
                public static void main(String[] args) {
                  launch(args);
              private void postTransaction(){
                   //write the code for posting here
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.control.Label;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.layout.HBox;
    import javafx.stage.Modality;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    public class ConfirmationWindow extends Stage {
         Stage owner;
         Stage stage;
         BorderPane root;
         static boolean postStatus = false;
      public ConfirmationWindow( Stage owner, String title){
        root = new BorderPane();
        stage = this;
        this.owner = owner;
        initModality( Modality.APPLICATION_MODAL );
        initOwner( owner );
        initStyle( StageStyle.UTILITY );
        setTitle( title );
        setContents();
      public void setContents(){
        Scene scene = new Scene(root,250,150);
        setScene(scene);
        Group groupInDialog = new Group();
        groupInDialog.getChildren().add( new Label("Do you really want to Post this record ?") );
        root.setCenter( groupInDialog );
        Button yes = new Button( "Yes" );
        yes.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent e) {
                   postStatus =true;
                   stage.close(); // Close the pop up. Transfer control to PostTransaction.java and execute the PostTransaction() method.
        Button no  = new Button( "No" );
        no.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent e) {
                   postStatus =false;
                   stage.close(); // Close the pop up only
        HBox buttonPane = new HBox();
        buttonPane.setSpacing(10);
        buttonPane.getChildren().addAll(yes,no);
        root.setBottom(buttonPane);
        stage.show();
      public static boolean confirmTranactionPosting(Stage owner, String title) {
           new ConfirmationWindow(owner, title);
           return postStatus;
    }

    The MII Message listener is a queue. But when I understand you correctly, you do not want to process the messages immediately after arriving in the Listener.
    Maybe the categorization of messages is an option for you (see [Sap Help: Processing Rule Editor - Category|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm]. You can enter a category for the control recipe messages. The messages will then be placed in the Listener queue. You can use the [Message Services|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm] actions to read the categorized messages and process them as you need.
    In addition to Manoj, you may also use the [Queueing actions|http://help.sap.com/saphelp_mii121/helpdata/en/43/e80b59ad40719ae10000000a1553f6/frameset.htm] of MII, where you can queue xml contents.
    Hope this helps.
    Michael

  • I need a code example for an action listener for a jcheckbox using matisse

    I am trying to make it so that when some body clicks a jcheckbox it will put a figure into a jtextfield. Because I am using matisse I need to know the code for the action listener and I need to know quickly as well so I don't have time to look it up with searches etc.
    Can anbody provide me with some example code please.

    I thought that as you are all more experienced than I am that you would know where to look and as you would have already been to all of the sites you would have been able to save me a lot of time looking for the best one. I didn't mean to insult you sorry, I knew that I would be looking for a long time and hoped that some one could help speed that up for me.
    Any way I have obviously annoyed you in that thread earlier this week. I know that you are all pee'd at me and don't believe me and that is fine. I have learnt every thing that I need to learn and would like to thank you for your help although I think that your language in your last post was not very pleasant, but that is ok.
    I don't want to continue posting any more. But thank you for your help.

  • Issue with setting an Action Listener for a Command Button

    Hi all,
    I'm trying to set an action listener for a CoreCommanButton in a backing bean. Here's my code:
         CoreCommandButton editBtn = new CoreCommandButton();
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",null);
              editBtn.setActionListener(mb);
    //Action listener method
         public void doButtonAct(ActionEvent actionEvent)
    I keep getting a javax.faces.el.MethodNotFoundException error. However when I remove the ActionEvent parameter in doButtonAct(), I get a wrong number of arguments error.
    So i'm guessing there is something wrong with the parameters i accept in my action listener method. what can be causing this issue?
    Cheers.

    I figured this out.
    Since doButtonAct() requires an ActionEvent object as a parameter, i needed to define the parameter type when I create the method binding.
    Solution:
         Class argsString[] = new Class[] { ActionEvent.class };
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",argsString);

Maybe you are looking for

  • ALE configuration in ECC and 4.7

    Hello guys Is there any difference in ALE configuration in ECC and 4.7??

  • Html5 video doesn't play

    I was on the People magazine site and where there was supposed to be a video it said this player cannot play HTML video. I thought iOS can't play Flash video but that HTML 5 is what apple supports. Am I wrong?

  • After Mountain Lion, function buttons are not working.

    I just installed Montain Lion on my MacBook Pro(13-inch, Mid 2010) and those "F" buttons don't work properly. I think just one of them is working, but it opens the Dashboard instead of put the volume up and the rest don't give signal of life. I don't

  • How do i find out if i can renew ?

    I have heard stories from people that purchase a new iphone but att wont let them switch their old phone to it? I am searching for a new one, having bought the original in september. The only thing I need to do is buy a new phone and start a new 2 ye

  • Can't ReOpen PP CC after it "quit unexpectedly"

    When I try to open Premiere Pro CC, it begins to load but immediately goes to an Apple Problem Report page saying "Adobe Premiere Pro CC quit unexpectedly".  It says to click the reopen button to start Premiere again, but when I do this, it goes stra