From c3e00a4cfce9ac819fcc34b11332f28454aa6ff9 Mon Sep 17 00:00:00 2001 From: Leon Montag Date: Fri, 30 Dec 2022 00:55:17 +0100 Subject: [PATCH] refactoring: Add Buttons to a new Panel instead of the Frame --- src/main/java/Gui/gui.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/Gui/gui.java b/src/main/java/Gui/gui.java index 820fbb0..ed1835f 100644 --- a/src/main/java/Gui/gui.java +++ b/src/main/java/Gui/gui.java @@ -1,11 +1,15 @@ package Gui; +import java.awt.GridBagLayout; + import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JPanel; public class gui { JFrame jf; JButton StartBtn, CloseBtn; + JPanel Panel; public static int width = 800, height = 600; @@ -18,10 +22,16 @@ public class gui { jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StartBtn = new JButton("Starte Spiel"); StartBtn.setSize(300,100); - jf.add(StartBtn); CloseBtn = new JButton("Schlieen"); CloseBtn.setSize(300,100); - jf.add(CloseBtn); + Panel = new JPanel(); + Panel.setSize(width,height); + Panel.setLayout(new GridBagLayout()); + Panel.add(StartBtn); + Panel.add(CloseBtn); + jf.add(Panel); + Panel.setVisible(true); + } }