move the code from B's actionListener into it's own method, which will be
called by B, and can be called by A
eg
instead of
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("Hello World");}});
you have this
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
doSomething();}});
public void doSomething()
{
System.out.println("Hello World");
}
now, doSomething() is available to be called from A