Browse Source

added gui controll or back button

main
fdai6499 2 years ago
committed by fdai6040
parent
commit
c87fcc8bdb
  1. 30
      src/main/java/src/MainFrame.java

30
src/main/java/src/MainFrame.java

@ -18,6 +18,7 @@ import java.util.LinkedList;
public class MainFrame extends JFrame {
LinkedList<Model> 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));
}
});

Loading…
Cancel
Save