Adding a menu - dev-cuttlefish/cuttlefish GitHub Wiki
This is a brief tutorial about adding an addition menu to the Cuttlefish menu.
First, we need to create the Menu. It can be placed in the ch.ethz.sg.cuttlefish.menus package, and it needs to implement the AbstractMenu abstract class:
package ch.ethz.sg.cuttlefish.gui2.menus;
import javax.swing.JMenuItem; import ch.ethz.sg.cuttlefish.gui2.CuttlefishToolbars; import ch.ethz.sg.cuttlefish.gui2.NetworkPanel;
public DummyMenu(NetworkPanel networkPanel, CuttlefishToolbars toolbars) { super(networkPanel, toolbars); this.setText("Dummy menu"); this.add(new JMenuItem("Dummy menuitem")); } }
The above code declares the DummyMenu with a single dummy menu item.
The next step is to add it to the CuttlefishMenu. Go to the initialization() method in the implementation of the CuttlefishMenu class and add the DummyMenu as follows:
private void initialize() { ... add(new DummyMenu(networkPanel, toolbars); }
That's all. Now you can recompile Cuttlefish and you will see the dummy menu when it is started. The menu has access to the network panel and the toolbars, hence you can implement the functionality that you need.