NewBie Problem [Event Handling]


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: NewBie Problem [Event Handling]

  1. #1
    Join Date
    Jan 2008
    Posts
    37

    Unhappy NewBie Problem [Event Handling]

    Hello All
    I did a simple GUI application in JAVA and it works fine, But when i tried to add Event Handling in it using an inner class

    it gives me following error
    "buttonHandler is not abstract and doesnt override abstract methods myButtonHandler(java.awt.event.ActionEvent) in java.awt.event.ActionListner


    overall code is

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class testGUI{
    
    
    
    	//Inner Class
    	public class buttonHandler implements ActionListner{
    	
    		public void myButtonHandler(ActionEvent event){
    		JOptionPane.showMessageDialog(null, "Message Updated");	
    	
    	}
    
    
    
    }


    Please Help

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    To implement a method from the Interface, your implementation of ActionListener must implement the abstract method in the Interface. So your myButtonHandler instance of your ButtonHandler class must use actionPerformed as the method which executes the action you want to perform when a user pushes the button.

    The signature of actionPerformed is:

    void actionPerformed(ActionEvent e)

    So the method should be re-written:

    public void actionPerformed (ActionEvent event)
    {
    JOptionPane.showMessageDialog(null, "Message Updated");
    }
    Last edited by nspils; 05-05-2008 at 08:58 AM.

  3. #3
    Join Date
    Jan 2008
    Posts
    37
    Thanks, It works Now

    But now I got a new problem

    Code:
    public void actionPerformed (ActionEvent event)
    {
         if(event.getSource() == myButton){
              JOptionPane.showMessageDialog(null, "Message Updated");
         }
    }
    my inner class is unable to identify the myButton from the main class, What to do?

    Thanks in advance

  4. #4
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    Declare the button as a class level variable, not in main.

  5. #5
    Join Date
    Jan 2008
    Posts
    37
    Thanks, It starts to work

Similar Threads

  1. App Problem with MS Office ...
    By Shannon in forum VB Classic
    Replies: 7
    Last Post: 06-24-2007, 09:47 PM
  2. login problem
    By dbrook007 in forum ASP.NET
    Replies: 0
    Last Post: 11-06-2006, 05:54 AM
  3. (newbie?) c# compilation problem
    By autoMagic in forum .NET
    Replies: 3
    Last Post: 11-05-2006, 07:20 PM
  4. ActiveX problem using VB
    By koraal in forum VB Classic
    Replies: 3
    Last Post: 11-03-2006, 04:50 PM
  5. Replies: 0
    Last Post: 12-13-2001, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center