From c87fcc8bdbd64206b85655abf22588084ee162ce Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 9 Feb 2023 20:50:25 +0100 Subject: [PATCH] added gui controll or back button --- src/main/java/src/MainFrame.java | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index 2e3a77d..7551c8c 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -18,6 +18,7 @@ import java.util.LinkedList; public class MainFrame extends JFrame { LinkedList history; + int historyPosition; private GameField gameField; @@ -30,6 +31,7 @@ public class MainFrame extends JFrame { history = new LinkedList<>(); + this.setLayout(null); this.setVisible(true); this.setBounds(300, 200, 500, 600); @@ -52,6 +54,8 @@ public class MainFrame extends JFrame { gameField.setBounds(70, 50, 360, 360); rootPanel.add(gameField); + history.add(new Model(gameField)); + int j = 0; JPanel boxPanel = setupJPanel(); @@ -118,17 +122,28 @@ public class MainFrame extends JFrame { } }); - JButton newButton = new JButton(); - newButton.setVisible(true); - newButton.setBounds(395, 5, 100, 25); - newButton.setText("Vorwärts"); - rootPanel.add(newButton); +// JButton newButton = new JButton(); +// newButton.setVisible(true); +// newButton.setBounds(395, 5, 100, 25); +// newButton.setText("Vorwärts"); +// rootPanel.add(newButton); JButton backButton = new JButton(); backButton.setVisible(true); backButton.setBounds(10, 5, 100, 25); backButton.setText("Rückwärts"); rootPanel.add(backButton); + backButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + int size = history.size(); + if (size > 1) { + Model model = history.get(size - 2); + history.removeLast(); + model.modelToGameField(); + } + } + }); JButton retryButton = new JButton(); retryButton.setVisible(true); @@ -183,8 +198,6 @@ public class MainFrame extends JFrame { numLabel1.setVisible(true); jPanel.add(numLabel1); - - return jPanel; } @@ -264,6 +277,7 @@ public class MainFrame extends JFrame { loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); currentPosition = 0; currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + history.add(new Model(gameField)); } }); @@ -282,6 +296,7 @@ public class MainFrame extends JFrame { loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); currentPosition = 0; currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + history.add(new Model(gameField)); } }); @@ -300,6 +315,7 @@ public class MainFrame extends JFrame { loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); currentPosition = 0; currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + history.add(new Model(gameField)); } });