Adding actionListener to JOptionPane

how do you add an actionListener to a JOptionPane?
im using JOptionPane.showMessageDialog, and i want an event to happen when the user clicks on the "Okay" button

Can you do something like this instead? Use a showConfirmDialog(...) istead of the showMessageDialog(...), then use the return value to determine which button the user pushed?
int retValue = JOptionPane.showConfirmDialog(parent, message, Title, JOptionPane.OK_CANCEL_OPTION );
if (retValue == JOptionPane.OK_OPTION)
  doOkayEvent();
else
  doNotOkayEvent();

Similar Messages

  • Added actionListener, then GUI broke

    Hi,
    1. first i ran my menu GUI, it worked fine
    2. then i added the actionListener code... now she no workie...
    what did i do wrong???
    ERROR MSG:
    C:\jLotto\LotFrame.java:34: cannot resolve symbol
    symbol : class ActionListener
    location: class LottoFrame
              new ActionListener(){
    ^
    1 error
    Tool completed with exit code 1
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    import java.awt.Event;
    import javax.swing.JOptionPane; //print menu trial run
    public class LotFrame extends JFrame
      // Constructor
      public LotFrame(String title)
        setTitle(title);                             // Set the window title
        setDefaultCloseOperation(EXIT_ON_CLOSE);     // handle exit operation
        setJMenuBar(menuBar);                        // Add the menu bar to the window
        //MAIN MENU
        JMenu fileMenu    = new JMenu("File");          // Create File menu
        JMenu findMenu    = new JMenu("Find");
        // Construct the file pull down menu
        newItem   = fileMenu.add("New");             // Add New item
        openItem  = fileMenu.add("Open");            // Add Open item
        closeItem = fileMenu.add("Close");           // Add Close item
        fileMenu.addSeparator();                      // Add separator
        saveItem  = fileMenu.add("Save");            // Add Save item
        saveAsItem= fileMenu.add("Save As...");      // Add Save As item
        fileMenu.addSeparator();                      // Add separator
        printItem.addActionListener(
               new ActionListener(){
                    public void actionPerformed( ActionEvent e )
                         JOptionPane.showMessageDialog( LotFrame.this,
                         "adding actionListener at end of GUI setup",
                         "action at end", JOptionPane.PLAIN_MESSAGE);
                    }//end of actionPerformed
              }//end of actionLinstener
         );//endof .addActionListener
       printItem = fileMenu.add("Print");           // Add Print item
        menuBar.add(fileMenu);                       // Add the file menu
        menuBar.add(findMenu);
      }//end of constructor
      private JMenuBar menuBar = new JMenuBar();     // Window menu bar
      // File menu items
      private JMenuItem newItem, openItem, closeItem, saveItem, saveAsItem, printItem;
    }//end of class LotFrame

    java.awt.event.*;
    import java.awt.Event;

  • Adding actionListener to JComboBox

    Hi there
    I have added actionListener to a JComboBox. I only want the actionPerformed() get called when the user choose the item in the JComboBox, however, it also get called whenever I change the items in the JComboBox.
    I have tried to call the ActionEvent.getID() method to identify the action, however, changing the items and choosing the item give me the same ID - 1001.
    Has anyone got this problem before? How did you solve it?
    Should I use other Listener for listening only the choosing event?
    In advance thanks!
    From
    Edmond

    I had many problems using actionListeners with JComboBox because it gets called all the time, I have had much better luck using mouseListener and the events getClickCount() method for single and double click selections, this avoided many of the problems for me.

  • Adding actionlistener to JTextArea

    I'm trying to add an actionListener to my JTextArea, so that when the user hits 'enter', the action occurs.
    sort of like this:
    JTextArea.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ??????) {
    doSomethingToTextArea();
    but I'm having problems (e.g. how to make enter the action event, and some problem that says JTextArea can't use actionlisteners???)
    any ideas?
    thanks,
    n00bProgrammer

    Like serveral of the more complex swing gadgets the JTextarea uses model/view architecture. In this case the model behind the textarea is a Document, and the text change listener needs to be added to the Document, not the gadget itself. i.e. area.getModel().addDocumentListener();
    However JTextArea still inherits the methods of java.awt.Component including addKeyListener();

  • Adding actionlistener to menuItem

    hi...i'm trying to add an actionListener to a menuItem. i looked at the tutorial on "how to use menus" but i cant seem to execute the menuitem. here's my code...
    public class Controller implements ActionListener
        GUI gui;
        public Controller(GUI g)
            gui = g;
            gui.menuItem.addActionListener(this);
        public void actionPerformed(ActionEvent e)
            gui.menuItem = (JMenuItem)(e.getSource());
            if (gui.menuItem.getText().equals("New Database"))
                System.out.println("Hello");
    }where the class GUI is where the menItems have been added to the menus. i'm just trying out for one menuItem first but i wont get the "hello" printed on the screen...can someone give me some assistance on this given that i havent used JMenuItems before...thx in advance...

    As carnickr said we really need the source from GUI to be able to help you more. Even without looking at GUI it's apparent that you're methodology is lacking. Depending on design and requirements I can think of many different ways you might need to handle menu item actions. I can't think of a single one that would involve comparing the text, which is what you're doing.
    First of all, adding a listener to a public field of a different class is inherently the product of a flawed design or bad design itself. Your code should look more like this:
    JMenuItem newDatabase = new JMenuItem("New Database");
    JMenuItem openDatabase = new JMenuItem("Open Database");
    JMenuItem closeDatabase = new JMenuItem("Close Database");
    ActionListener listener = new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == newDatabase) {
                   System.out.println("New database clicked");
              } else if (e.getSource() == openDatabase) {
                   System.out.println("Open database clicked");
              } else fi (e.getSource() == closeDatabase) {
                   System.out.println("Close database clicked");
    newDatabase.addActionListener(listener);
    openDatabase.addActionListener(listener);
    closeDatabase.addActionListener(listener);Obviously an anonymous class is not always appropriate. The important thing here is that you're comparing the reference to see if it's the same Object, not trying to compare the text. If you post GUI and a little more about what you're trying to do we can try and give you some pointers on how to design it better.

  • Adding ActionListener to JMenu

    Is it possible to add actionListener to Jmenu object
    for example File, Format, Exit these are Menus added in the menuBar not menu items
    on clicking the Exit the frame shuld get closed.
    For detecting the action clicked on the Menu shall i use actionListener?
    I have tried using MenuListener its getting invoked on selection
    I dont want it on selection , I want the frame to be displayed only on clicking that menu.

    Alas, whilst a JMenu is-a JMenuItem (the Composite Pattern at work), it doesn't function entriely like on,
    and registering ActionListeners with a JMenu doesn't work. Try MenuListener:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ActionExample {
        public static void main(String[] args) {
            Action sample = new SampleAction();
            JMenu menu = new JMenu("Menu");
            menu.setMnemonic(KeyEvent.VK_M);
            menu.add(sample);
            menu.addMenuListener(new SampleMenuListener());
            JToolBar tb = new JToolBar();
            tb.add(sample);
            JTextField field = new JTextField(10);
            field.setAction(sample);
            JFrame f = new JFrame("ActionExample");
            JMenuBar mb = new JMenuBar();
            mb.add(menu);
            f.setJMenuBar(mb);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(tb, BorderLayout.NORTH);
            f.getContentPane().add(field, BorderLayout.SOUTH);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    class SampleMenuListener implements MenuListener {
        public void menuSelected(MenuEvent e) {
            System.out.println("menuSelected");
        public void menuDeselected(MenuEvent e) {
            System.out.println("menuDeelected");
        public void menuCanceled(MenuEvent e) {
            System.out.println("menuCanceled");
    class SampleAction extends AbstractAction {
        public SampleAction() {
            super("Sample");
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("alt S"));
            putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
            putValue(SHORT_DESCRIPTION, "Just a sample action");
        public void actionPerformed(ActionEvent evt) {
            System.out.println("sample...");
    }

  • Adding actionListener to a button

    pls i want to create an applet with buttons rectangle,circle,and polygon and having a textArea.when someone clicks on the rectangle buttons it draws a rectangle,on the circle buttons it draws a circle and on the polygon button it draws a polygon.pls i have already created the user interface how do i add the actionListeners to the respective buttons and reggister them.

    Hi,
    try something like this:
    JButton jButton1 = new JButton("yourbutton");
    jButton1.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                    someMethodThatDoesWhatYouNeed();
    });this is just a way to do it, there are other ways, just look around in the forum to discover them.
    JoY?TiCk

  • Adding ActionListener to JPanel or equivalent

    Hi all.
    I am trying to add an actionListener for mouse clicks on a JPanel, ideally using something like this:
    panel.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e)
              //do something
       });However, JPanel does not implement addActionListener, and as far as I can see the only components which do are buttons, radio buttons and the like.
    I tried extending JPanel to implement ActionListener, but had no success.
    Is there an easy way to monitor for mouse clicks on a JPanel or container? Bearing in mind there will be several of these containers at different locations, so using a global mouse listener would not be useful.
    Thanks

    Hi all.
    I am trying to add an actionListener for mouse clicks
    on a JPanel, ideally using something like this:
    panel.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    //do something
    });owever, JPanel does not implement addActionListener,
    and as far as I can see the only components which do
    are buttons, radio buttons and the like.
    I tried extending JPanel to implement ActionListener,
    but had no success.
    Is there an easy way to monitor for mouse clicks on a
    JPanel or container? Use a MouseListener.
    Bearing in mind there will be
    several of these containers at different locations,
    so using a global mouse listener would not be
    useful.So add individual MouseListeners to each container.
    >
    Thanks

  • Trouble adding actionlistener to a panel in a tabbed pane

    Hi, please help me! this is the code i wrote, with the error given below:
    CODE:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class tabslisten extends JApplet
         JPanel RecPanel;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         public void init ()
              FlowLayout flow;
              flow = new FlowLayout();     
              Container content = getContentPane();
              content.setLayout(new GridLayout());
              JTabbedPane tabpane = new JTabbedPane();
              content.add(tabpane, flow);
              RecPanel = new JPanel();
              recipientDetails();
              tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");     
         public void recipientDetails()
              JLabel lblRecFName;
              JLabel lblRecLName;
              JTextField txtRecFName;
              JTextField txtRecLName;
              JButton btnValidate;
              gbl = new GridBagLayout();
              gbc = new GridBagConstraints();
              RecPanel.setLayout(gbl);
              lblRecFName = new JLabel("First Name");
              lblRecLName = new JLabel("Last Name");
              txtRecFName = new JTextField(8);
              txtRecLName = new JTextField(5);
              btnValidate= new JButton("Validate");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 8;
              gbl.setConstraints(lblRecFName, gbc);
              RecPanel.add(lblRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 8;
              gbl.setConstraints(txtRecFName, gbc);
              RecPanel.add(txtRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gbl.setConstraints(lblRecLName, gbc);
              RecPanel.add(lblRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 11;
              gbl.setConstraints(txtRecLName, gbc);
              RecPanel.add(txtRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 32;
              gbl.setConstraints(btnValidate, gbc);
              RecPanel.add(btnValidate);
              validateAction validateButton = new validateAction();
              btnValidate.addActionListener(validateButton);
         class validateAction implements ActionListener
              public void actionPerformed(ActionEvent evt)
                   Object obj = evt.getSource();
                   if (obj == btnValidate)
                        String fName = txtRecFName.getText();
                        String lName = txtRecLName.getText();
                        if (fName.length()==0)
                             getAppletContext().showStatus("First Name not entered.");
                             return;
                        else if (lName.length()==0)
                             getAppletContext().showStatus("Last Name not entered.");
                             return;
                        else
                             getAppletContext().showStatus("Successful.");
    ERROR:
    tabslisten.java:90: Undefined variable: btnValidate
    if (obj == btnValidate)
    ^
    tabslisten.java:92: Undefined variable or class name: txtRecFName
    String fName = txtRecFName.getText();
    ^
    tabslisten.java:93: Undefined variable or class name: txtRecLName
    String lName = txtRecLName.getText();
    ^
    3 errors
    Press any key to continue...
    I'm sure I'm doing something really stupid, but I don't know what! ANY and ALL help will be appreciated! Thanks!

    I copied your program and ran it. It works fine. Make sure the three variables you made class variables are only defined in one place. (ie you moved them not copied them). Other than that I have no ideas.
    With regards to naming conventions. My only comment is, take a look at the Java API.
    1) classes have uppercased words. Examples from your program - JTextField, Container, FlowLayout, GridLayout...
    2) methods and variable names don't upper case the first word - getContentPane(), setLayout()...
    Here is the program that works for me:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class FirstApplet extends JApplet
         JPanel RecPanel;
         GridBagLayout gbl;
         GridBagConstraints gbc;
         JTextField txtRecFName;
         JTextField txtRecLName;
         JButton btnValidate;
         public void init ()
              System.out.println("hello there");
              FlowLayout flow;
              flow = new FlowLayout();
              Container content = getContentPane();
              content.setLayout(new GridLayout());
              JTabbedPane tabpane = new JTabbedPane();
              content.add(tabpane, flow);
              RecPanel = new JPanel();
              recipientDetails();
              tabpane.addTab("Recipient Details", null, RecPanel, "Recipient Details");
         public void recipientDetails()
              JLabel lblRecFName;
              JLabel lblRecLName;
              gbl = new GridBagLayout();
              gbc = new GridBagConstraints();
              RecPanel.setLayout(gbl);
              lblRecFName = new JLabel("First Name");
              lblRecLName = new JLabel("Last Name");
              txtRecFName = new JTextField(8);
              txtRecLName = new JTextField(5);
              btnValidate= new JButton("Validate");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 8;
              gbl.setConstraints(lblRecFName, gbc);
              RecPanel.add(lblRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 8;
              gbl.setConstraints(txtRecFName, gbc);
              RecPanel.add(txtRecFName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gbl.setConstraints(lblRecLName, gbc);
              RecPanel.add(lblRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 11;
              gbl.setConstraints(txtRecLName, gbc);
              RecPanel.add(txtRecLName);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 4;
              gbc.gridy = 32;
              gbl.setConstraints(btnValidate, gbc);
              RecPanel.add(btnValidate);
              validateAction validateButton = new validateAction();
              btnValidate.addActionListener(validateButton);
         class validateAction implements ActionListener
              public void actionPerformed(ActionEvent evt)
                   Object obj = evt.getSource();
                   if (obj == btnValidate)
                        String fName = txtRecFName.getText();
                        String lName = txtRecLName.getText();
                        if (fName.length()==0)
                             getAppletContext().showStatus("First Name not entered.");
                             return;
                        else if (lName.length()==0)
                             getAppletContext().showStatus("Last Name not entered.");
                             return;
                        else
                             getAppletContext().showStatus("Successful.");

  • ActionListener for JOptionPane.showConfirmDialog

    Is it possible to handle JOptionPane.showConfirmDailog 's button click events through action listeners?
    I want to execute some code on the "Save" button click and want to do it like my JFileChooser window stays in the background until either of the Yes,No or Cancel buttons of the showConfirmDialog is pressed.In fact I'm able to get the state of the button pressed using,
    int i=JOptionPane.showConfirmDialog(null,"Confirm file overwrite?")but can't make the showConfirmDialog window stay in the background,,,
    Can anybody please help?
    Thanks in advance...

    There are forums specifically for GUI questions.
    I believe there is also a forum for international issues.

  • Adding Actionlistener to a cell in a JTable?

    is this possible? how would i go among doing this?

    use the ListSelectionListener.
    In "valueChanged(ListSelectionEvent e)" you get the row with "e.getFirstIndex()".

  • Strange error while using ActionListener with RichCommandLink

    Hi,
    I am using Technology preview 3.
    I have RichTable bound to af:table in my JSF page.
    I am showing database contents inside richTable.
    Inside richTable i have one extra column in which i am showing remove link. So every row of table will have remove link. I have added ActionListener as inner class for the backing bean. and this actionlistener i am adding into RichCommandLink(remove link)
    But when i click on remove link I am getting weired exception. And i am not able to get why this error is coming.
    This problem occures whenever I use contentDelivery parameter with <af:table>
    Here is the stack trace of the error.
    java.lang.InstantiationException: com.backingBean.UpdateSampleTypeB
    ackingBean$MyLinkActionListener
    at java.lang.Class.newInstance0(Class.java:335)
    at java.lang.Class.newInstance(Class.java:303)
    at org.apache.myfaces.trinidad.bean.util.StateUtils$Saver.restoreState(S
    tateUtils.java:286)
    at org.apache.myfaces.trinidad.bean.util.StateUtils.restoreStateHolder(S
    tateUtils.java:202)
    at org.apache.myfaces.trinidad.bean.util.StateUtils.restoreList(StateUti
    ls.java:257)
    at org.apache.myfaces.trinidad.bean.PropertyKey.restoreValue(PropertyKey
    .java:231)
    at org.apache.myfaces.trinidad.bean.util.StateUtils.restoreState(StateUt
    ils.java:148)
    at org.apache.myfaces.trinidad.bean.util.FlaggedPropertyMap.restoreState
    (FlaggedPropertyMap.java:194)
    at org.apache.myfaces.trinidad.bean.FacesBeanImpl.restoreState(FacesBean
    Impl.java:358)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.restoreState(U
    IXComponentBase.java:881)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:861)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponent
    Base.java:1154)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at org.apache.myfaces.trinidad.component.TreeState.restoreState(TreeStat
    e.java:96)
    at org.apache.myfaces.trinidad.component.UIXComponentBase.processRestore
    State(UIXComponentBase.java:855)
    at javax.faces.component.UIComponentBase.processRestoreState(UIComponent
    Base.java:1154)
    at org.apache.myfaces.trinidadinternal.application.StateManagerImpl.rest
    oreView(StateManagerImpl.java:487)
    at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl
    .java:287)
    at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWra
    pper.java:193)
    at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.resto
    reView(ViewHandlerImpl.java:258)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._restoreView(Li
    fecycleImpl.java:438)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(L
    ifecycleImpl.java:229)
    at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(Lifecyc
    leImpl.java:155)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterC
    hain.java:65)
    at oracle.adfinternal.view.faces.webapp.rich.SharedLibraryFilter.doFilte
    r(SharedLibraryFilter.java:135)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterL
    istChain.doFilter(TrinidadFilterImpl.java:284)
    at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter
    (RegistrationFilter.java:69)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterL
    istChain.doFilter(TrinidadFilterImpl.java:284)
    at oracle.adfinternal.view.faces.activedata.ADSFilter.doFilter(ADSFilter
    .java:74)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterL
    istChain.doFilter(TrinidadFilterImpl.java:284)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invoke
    DoFilter(TrinidadFilterImpl.java:208)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilt
    erImpl(TrinidadFilterImpl.java:165)
    at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilte
    r(TrinidadFilterImpl.java:138)
    at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFi
    lter.java:92)
    at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterC
    hain.java:15)
    at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:1
    18)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletReque
    stDispatcher.java:611)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(Ser
    vletRequestDispatcher.java:362)
    at com.evermind.server.http.HttpRequestHandler.doDispatchRequest(HttpReq
    uestHandler.java:915)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequ
    estHandler.java:821)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpReques
    tHandler.java:626)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpReques
    tHandler.java:599)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpReque
    stHandler.java:383)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
    va:161)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.ja
    va:142)
    at oracle.oc4j.network.ServerSocketReadHandler$ClientRunnable.run(Server
    SocketReadHandler.java:275)
    at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(Server
    SocketAcceptHandler.java:237)
    at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocket
    AcceptHandler.java:29)
    at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(
    ServerSocketAcceptHandler.java:878)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
    utor.java:650)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:675)
    Can anybody please provide any help on this?
    Regards,
    Hiren

    Hi Simon,
    I am using addActionListener method of RichCommandLink
    Here is how i am trying to use it.
    public class backingBean {
         private RichTable table;
         public backingBean() {
         RichColumn rc = new RichColumn();
         RichCommandLink cmd = new RichCommandLink();
         MyActionListener listener = new MyActionListener();
         cmd.addActionListener(listener);
         public RichTable getTable() {
         return table;
         class MyActionListener implements ActionListener {
              public void processAction (ActionEvent actionEvent) throws AbortProcessingException {
              // Processing related to edit components of backing bean
    Hiren

  • Bug? Unable to add ActionListener using Anonymous class.

    Hi,
    I come accross one strange behaviour while adding ActionListener to RCF component.
    I am trying to add the ActionListener in the managed bean using the Anonymous.
    We can add the actionListener to a button using following methods. I am talking about the the first case. Only this case is not working. Rest other 2 cases are working properly.
    Case 1:
    class MyClass {
         RichCommmandButton btnTest = new RichCommmandButton();
         public MyClass(){
              btnTest.addActionListener(new ActionListener(){
                   public void processAction(ActionEvent event){
    Case 2:
    class MyClass implements ActionListener {
         RichCommmandButton btnTest = new RichCommmandButton();
         public void processAction(ActionEvent event){
    <af:button binding="#{myClassBean.btnTest}" actionListener="#{myClassBean.processAction}"/>
    Case 3:
    class MyClass implements ActionListener {
         RichCommmandButton btnTest = new RichCommmandButton();
         public void addActionLister(){
              //Use EL to add processAction(). Create MethodBinding
              FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory exprfactory = facesContext.getApplication().getExpressionFactory();
              MethodExpression actionListener =
    exprfactory.createMethodExpression(elContext, "#{myClassBean.processAction}", null, new Class[] { ActionEvent.class });
              btnTest.setActionListener(actionListener);
         public void processAction(ActionEvent event){
    Java has provided good way to use the Anonymous classes while adding the listeners. It should work with the RCF also.
    Some how i found the case 1 usefull, as i can have as many buttons in my screen and i can add the actionListener in one method. Also it is easy to read. I dont have to see the JSPX page to find the associated actionListener method.
    Is it a bug or i am wrong at some point?
    Any sujjestions are welcome.
    - Sujay.

    Hello Sujay,
    As I said in my previous reply, you can try with request scope. In JSF you shouldn't use the binding attribute very often. I agree that anonymous class is nice, but don't forget that you might be dealing with client state saving here so it cannot be perfectly compared with Swing that maintains everything in RAM. What I think happens with you currently is the following:
    1. Bean is created and the button instance as well. The ActionListener is added to the button;
    2. The view is rendered and while it is, the binding attribute is evaluated, resulting in the get method of your bean being called;
    3. Since the method returns something different than null, the button instance created in 1. get used in the component tree;
    4. The tree's state is saved on the client, since your class isn't a StateHolder, nor Serializable, the StateManager doesn't know how to deal with it so it gets discarded from the saved state and maybe from the component itself (would have to debug the render view phase to be sure);
    5. The postback request arrives, the tree is restored. When the handler reaches the button, it call the bean that returns the same instance that was used in the previous tree (since not request scoped), which is BAD because the remaining of the tree is not made of the same object instances, but rather new deserialized ones. The component then gets updated from the client state saved in 4, this might also be where the listener get removed (again debugging would tell you this, but I would tend more with the previous possibility). Note that with a request scoped bean you would have to add the listener during the first get method call (by checking if the component is null) or in the constructor as you're doing right now. It would be a very clean way and you could give the request bean (and thus the listener) access to the conversation scoped bean through injection which is very nice as well.
    6. The invoke application phase occurs and the listener is no longer there.
    Btw, this isn't a rich client issue, more a specification one. I'm curious if it works in a simple JSF RI application, if it does then I guess it would be a bug in Trinidad and/or rich client state handling architecture (using FacesBean).
    Regards,
    ~ Simon

  • ActionListener in JMenuItem

    Hi!
    I'm having problems with adding ActionListener on JMenuItem. I do it like this:
        JMenuItem saveMenuItem = new JMenuItem();
        saveMenuItem.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
            System.out.println("actionPerformed!");
            saveActionPerformed(e);       
        });No even when I select that menu item from my GUI, the action is not launched! Compiler does not give any errors, so it should be ok. Can anyone tell me what's the problem?? I'm using JDK 1.3.1-b24, btw.
    /jasurakk

    Hi jasurakka,
    just reading the source code, nothing seems to be
    wrong. May be there's a problem using an adapter class
    as listener. I suggest you try to write an own class
    implementing the ActionListener interface and then add
    this class as ActionListener to your menu items.
    Appears to me, that this is anyway the better
    solution, cause you create only one ActionListener
    listening for all the menu items you're adding instead
    of creating a new listener instance for each menu
    item. In the latter case, you have to add and check a
    unique action command for each item.Yeah, that's pretty much what I had before... But when I couldn't make it work, I tried to add own actionlistener for all menu items. Unfortunately it didn't help at all:=( Might you have any other ideas of what to do?

  • I need help about my database! Please help me!!! I really need help!!!!!

    Hey I done my database code through JCreator but it did not seemed to work. This is the buy ticket page whereby you buy the movie ticket online that i am creating.
    The java file is called BuyTextBox.java with database by microsoft access called buy.db .
    I will want the information that the user entered saved be stored in the database. I tried but it did not seemed to work!
    Here is the code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    public class BuyTextBox extends JPanel  implements ActionListener  {
         //Instance Variables
         private String FirstName = "fn";
         private String LastName = "ln";
         private String Address = "addr";
         private String ContactNumber ="1234567";
         private String CreditCardNumber ="111111";
         private String Email="[email protected]";
         private int NumberTickets;
         public String getFirstName(){
              return FirstName;
         public String getLastName(){
              return LastName;
         public String getAddress(){
             return Address;
         public String getContactNumber(){
              return ContactNumber;
        public String getCreditCardNumber(){
              return CreditCardNumber;
         public String getEmail(){
              return Email;
         public int getNumberTickets(){
             return NumberTickets;
    private JLabel movieLabel = new JLabel("Select movie ticket:");
    private JLabel blankLabel = new JLabel("        ");
    private JLabel blank2Label = new JLabel("        ");
    private JLabel blank3Label = new JLabel("        ");
    private JLabel blank4Label = new JLabel("        ");
    private JLabel blank5Label = new JLabel("        ");
    private JLabel FirstNameLabel = new JLabel("First Name:");
    private JTextField FirstNameTextField = new JTextField();
    private JLabel LastNameLabel = new JLabel("Last Name:");
    private JTextField LastNameTextField = new JTextField();
    private JLabel AddressLabel = new JLabel("Address:");
    private JTextArea AddressTextArea = new JTextArea();
    private JLabel contactLabel = new JLabel("Contact number:");
    private JTextField ContactNumberTextField = new JTextField();
    private JLabel creditLabel = new JLabel("Credit card number:");
    private JTextField CreditCardNumberTextField = new JTextField();
    private JLabel emailLabel = new JLabel("Email:");
    private JTextField EmailTextField = new JTextField();
    private JLabel numberLabel = new JLabel("Enter number of tickets:");
    private JTextField NumberTextField = new JTextField();
    private JButton saveButton;
    private JButton resetButton;
    public BuyTextBox() {
    JPanel inputPanel=new JPanel();
    inputPanel.setBorder(new TitledBorder("Please enter your informations:"));
    inputPanel.setLayout(new GridLayout(0,4,40,40));
    inputPanel.add(FirstNameLabel);
    inputPanel.add(FirstNameTextField);
    inputPanel.add(LastNameLabel);
    inputPanel.add(LastNameTextField);
    inputPanel.add(AddressLabel);
    inputPanel.add(AddressTextArea);
    inputPanel.add(contactLabel);
    inputPanel.add(ContactNumberTextField);
    inputPanel.add(creditLabel);
    inputPanel.add(CreditCardNumberTextField);
    inputPanel.add(emailLabel);
    inputPanel.add(EmailTextField);
    inputPanel.add(movieLabel);
    inputPanel.add(new Checkbox("Chicken Little"));
    inputPanel.add(new Checkbox("King Kong"));
    inputPanel.add(new Checkbox("Elizabeth Town"));
    inputPanel.add(blankLabel);
    inputPanel.add(new Checkbox("Curse Of Were Rabbit"));
    inputPanel.add(new Checkbox("Derailed"));
    inputPanel.add(new Checkbox("In Her Shoes"));
    inputPanel.add(new Checkbox("Proved"));
    inputPanel.add(new Checkbox("Family Stone"));
    inputPanel.add(new Checkbox("TinMine"));
    inputPanel.add(new Checkbox("Narnia"));
    inputPanel.add(blank2Label);
    inputPanel.add(numberLabel);
    inputPanel.add(NumberTextField);
    JPanel confirmPanel=new JPanel();
    saveButton=new JButton("Save");
    resetButton=new JButton("Reset");
    confirmPanel.add(saveButton);
    confirmPanel.add(resetButton);
    setLayout(new BorderLayout());
    add(inputPanel,  BorderLayout.PAGE_START);
    add(confirmPanel, BorderLayout.PAGE_END);
    resetButton.addActionListener(this);
    saveButton.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == resetButton)
    resetButtonClicked();
    else if (e.getSource() == saveButton)
    saveButtonClicked();
         public BuyTextBox(String aName){
              name = aName;
    public boolean insertDetails(){
              boolean success = false;
              DBController db = new DBController();
    //          buy db = new buy();
                 db.setUp("buy");
              String sql = "INSERT INTO buy(FirstName,LastName, Address,ContactNumber,CreditCardNumber,Email,NumberTickets)";
                sql += "values("+FirstName+", '"+LastName+"', "+Address+"', "+ContactNumber+
                "', "+CreditCardNumber+"', "+Email+"', "+NumberTickets+");";
              db.updateRequest(sql);
                 db.terminate();
                success = true;          
              return success;
    private void resetButtonClicked()
    FirstNameTextField.setText("");
    private void saveButtonClicked()
    FirstName = FirstNameTextField.getText().trim();
    LastName = LastNameTextField.getText().trim();
    Address = AddressTextArea.getText().trim();
    ContactNumber = ContactNumberTextField.getText().trim();
    CreditCardNumber = CreditCardNumberTextField.getText().trim();
    Email = EmailTextField.getText().trim();
    NumberTickets = NumberTextField.getText().trim();
    if  (FirstName.length() == 0)
    JOptionPane.showMessageDialog(this ," Name cannot be blank" , "Invalid Field", JOptionPane.ERROR_MESSAGE);
    else
    JOptionPane.showMessageDialog(this, "Record added.", "Confirmation", JOptionPane.INFORMATION_MESSAGE);
    if (insertDetails())
         System.out.println("DB Update OK");
    else
         System.out.println("DB Update Failed");
    public static void main(String args[]) {
    JFrame app=new JFrame();
    //Container contentPane = getContentPane ();
    BuyTextBox p=new BuyTextBox();
    app.getContentPane().add(p);
    app.setTitle ("Buy tickets ");
    app.setSize(1050,740);
    app.setBackground (new Color(0,160,198));
    app.setResizable (false);
    app.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    app.setVisible(true);
    If you know whats wrong with the code, please teach me what to do to make my databse successful!

    and now that one try to hack my icound but i set password so strong cuz it associat me just i little bit you will check me cuz i have your product all i used to use my username nerdseery but ha hacked me all every email addrese i used username nerdsery but now i must changed to nerrdsurery

Maybe you are looking for

  • Email Issue in GRC 10

    Dear Expert, Currently i am facing a strange issue regarding email notification and I am not sure where was the problem stuck even I have raised a message to SAP but till no any success. In our case we are getting a notification and approval mail in

  • JSF error on Tomcat

    Hi I am getting a strange error when I deploy the war file for JSF on tomcat as follows 2006-12-01 10:19:51 StandardContext[/manager]HTMLManager: start: Starting web application at '/campman' 2006-12-01 10:19:51 StandardContext[/campman]Exception sen

  • Adding part of table as header to every page in RTF template

    Hi, We have requirement where we need a part of table to be repeated as header of all the pages please let me know if any one has worked on similar issue Thanks

  • Oracle R12 Application

    Hi, What is the space required to copy Oracle r12 Apps software(How much GB) and the space required to installation??? Thanks Ankita

  • REST call response encoding

    Hi All, I have a json message received from http call. If I set <par id="htta.returnpltypeforce" value="json"> in call payload then my response is fine, for example: <bfa:io>     <bfa:object>         <bfa:object name="response">             <bfa:stri