aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to handle an event in separate class as written Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to handle an event in separate class as written " Watch "how to handle an event in separate class as written " New topic
Author

how to handle an event in separate class as written

Rambir Jakhar
Greenhorn

Joined: Sep 15, 2010
Posts: 5


Jakhar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38902
    
  23
Welcome to the Ranch

Your code is very difficult to read without code tags; since you are new I have edited your post, and you can see how much better it looks.
Please always tell us the details of what the problem is; you don't actually say what it going wrong.

I can see at least two problems.
  • Your class x should not extend a. It should only implement ActionListener.
  • You are adding a new b to your button. You would probably have to add something which is an ActionListener, eg an x.

  • Your class names are poorly-chosen. Nobody knows what class a is for, and class names should start with capital letters.
    Why are you using AWT components (Frame) rather than Swing (JFrame)?
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38902
        
      23
    More that I can see: You will have no end of problems if you use the == operator to test Strings for equality.

    I have my own opinion about ActionCommands, and don't like them. Have a look at this old thread, and the thread it sprang from, which you will find quoted in the first posting. You find your action command is quite unnecessary in this instance.
    Rambir Jakhar
    Greenhorn

    Joined: Sep 15, 2010
    Posts: 5
    thank you.

    Later On solved the problem.

    I just wanted to handle an event in a separate handler class as most of coder handle them either through inner classes.

    I will take care now onwards that i could write explicitely what all constructs are doing.

    Thanks again.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: how to handle an event in separate class as written