GUI

How to create a GUI

Create a class that extends to Menu
1
public class ExampleMenu extends Menu {
2
}
3
Copied!

Create the constructor

1
public class ExampleMenu extends Menu {
2
3
public ExampleMenu(MenuUtility menuUtility) {
4
super(menuUtility);
5
}
6
7
}
8
Copied!

Implement all methods

1
public class ExampleMenu extends Menu {
2
3
public ExampleMenu(MenuUtility menuUtility) {
4
super(menuUtility);
5
}
6
7
@Override
8
public String getMenuName() {
9
return "§e§lExample Menu";
10
}
11
12
@Override
13
public int getSlots() {
14
return 9;
15
}
16
17
@Override
18
public void handleMenu(InventoryClickEvent inventoryClickEvent) {
19
}
20
21
@Override
22
public void setMenuItems() {
23
}
24
25
}
26
Copied!

Create an item, add it in the GUI:

1
public ItemStack example = makeItem(Material.COAL, "§7Example COAL", "§7This is an example coal");
2
3
@Override
4
public void setMenuItems() {
5
this.getInventory().setItem(1, example);
6
}
7
Copied!

Create a Click Event

1
public ItemStack example = makeItem(Material.COAL, "§7Example COAL", "§7This is an example coal");
2
3
@Override
4
public void handleMenu(InventoryClickEvent event) {
5
if (event.getCurrentItem().equals(example)) {
6
event.setCancelled(true);
7
event.getWhoClicked().closeInventory();
8
event.getWhoClicked().sendMessage("Yay, it works!");
9
}
10
}
Copied!
ExampleMenu.java
1KB
Binary
Download the file
Last modified 9mo ago