• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to handle an event in separate class as written

 
Rambir Jakhar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 48652
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic