• Advertisement
Sign in to follow this  

[java] ActionListeners

This topic is 2893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Sign in to follow this  

  • Advertisement