I have a Swing class:
public class PopUpContextMenu extends JPopupMenu {
public PopUpContextMenu() {
super();
JMenuItem loginMenuItem = new LoginMenuItem("Login");
JMenuItem logoutMenuItem = new LogoutMenuItem("Logout");
add(loginMenuItem);
add(logoutMenuItem);
}
}
I wat to change it to use Guice so that the two “new” statement can be removed. I want something like:
public class PopUpContextMenu extends JPopupMenu {
@Inject
public PopUpContextMenu(JMenuItem loginMenuItem, JMenuItem logoutMenuItem) {
super();
add(loginMenuItem);
add(logoutMenuItem);
}
}
My question is how can I configure bindings in Guice so that I can pass the string “Login” when constructing loginMenuItem and pass string “Logout” when constructing logoutMenuItem?
Many thanks
You could use
@Namedannotation for that:In your class:
So then in your Guice module configure() method you do: