Add main menu as separate field
This commit is contained in:
parent
9b4cecc406
commit
eef936e397
@ -23,16 +23,23 @@ public class Main extends JFrame {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Component mainMenu;
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
super("Turrets");
|
super("Turrets");
|
||||||
setResizable(Constants.RESIZABLE);
|
setResizable(Constants.RESIZABLE);
|
||||||
setLocationByPlatform(true);
|
setLocationByPlatform(true);
|
||||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
add(new JLayer<>(new MenuPanel(), new GuiUtil.PlanetBackground()));
|
mainMenu = new JLayer<>(new MenuPanel(), new GuiUtil.PlanetBackground());
|
||||||
|
add(mainMenu);
|
||||||
pack();
|
pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Component getMainMenu() {
|
||||||
|
return mainMenu;
|
||||||
|
}
|
||||||
|
|
||||||
public void switchLayout(Component component) {
|
public void switchLayout(Component component) {
|
||||||
getContentPane().removeAll();
|
getContentPane().removeAll();
|
||||||
getContentPane().add(component);
|
getContentPane().add(component);
|
||||||
|
@ -69,7 +69,7 @@ public class MenuPanel extends JPanel {
|
|||||||
|
|
||||||
final int index = menuList.getSelectedIndex();
|
final int index = menuList.getSelectedIndex();
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0: // Create sever
|
case 0: // Create server
|
||||||
case 1: // Join client
|
case 1: // Join client
|
||||||
GameCanvas canvas = new GameCanvas(index == 0);
|
GameCanvas canvas = new GameCanvas(index == 0);
|
||||||
Main.getInstance().switchLayout(canvas);
|
Main.getInstance().switchLayout(canvas);
|
||||||
|
Loading…
Reference in New Issue
Block a user