Sign in to follow this  
overeasy

[java] ActionListeners

Recommended Posts

overeasy    100
I'm looking for a quick explanation on how I should handle menus in my RTS. When I right click on a cell, I want a menu customized for that cell to show.
public final class xMenuCreator{
	
	private static JPopupMenu popup_menu;		
	private static JMenuItem properties;
	private static JMenuItem move_to;
		
	public static void init(){
		
		popup_menu = new JPopupMenu();
		properties = new JMenuItem();
		move_to = new JMenuItem();
		
		
	}
	public static JPopupMenu getMenuFor(xCell c){
		
		popup_menu.removeAll();
		
		// movement
		if(c.isOpenAndEmpty()){
			
		        [color=red]
			move_to = new JMenuItem("Move here."){
				public void actionPerformed(ActionEvent e){
					xGame.player.moveTo(c);
				}				
			};
			[/color]
			popup_menu.add(move_to);
		}
		
		// contents properties
		if(!c.isEmpty())
			popup_menu.add(c.getContents().getMenu());		

		// properties
		properties.setText("Cell Properties: " + c);
		popup_menu.add(properties);
				
		return popup_menu;
		
	}
}
How do I make the highlighted portion work?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this