The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Asserting Control Over the GUI: Commands, Defaults, and Resource Bundles
Subject:  Decoupling actions from handlers
Date:  2005-05-06 22:55:08
From:  metalotus


Hi,

This is a great article. I have a question about the MyCommands class (in the last section).

If I want to execute the quit action from several places in my GUI, and each of those places needs to run different code on a quit(), then how can I achieve this?

I think I would need to make a set of interfaces and have MyCommands implement each interface (one interface per command). Then we could quickly swap implementations as the user navigates around the GUI.


public interfact QuitActionHandler {
public void quit();
}

public class MyCommands implements QuitActionHandler {
public void quit() {
// Delegates work to the context-sensitive aciton handler
getQuitActionHandler().quit();
}
}

 Feed java.net RSS Feeds