From 6371f822403214b30100dac15e9d76dac22acfa5 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 12:39:27 +0100 Subject: [PATCH] wrote sandbox --- src/main/java/src/MainFrame.java | 1 + src/main/java/src/Model.java | 4 + src/main/java/src/SandboxFrame.java | 222 +++++++++++++++++++++++++- src/test/java/src/TasksFrameTest.java | 2 +- 4 files changed, 227 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index 0071c01..0fbde13 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -97,6 +97,7 @@ public class MainFrame extends JFrame { private JPanel setupNums(String number) { + JPanel jPanel = new JPanel(); jPanel.setBackground(Color.BLUE); jPanel.setVisible(true); diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index 57ebad5..bfed87c 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -348,4 +348,8 @@ public class Model { throw new RuntimeException(e); } } + + public void createNewGame(String difficulty) { + + } } diff --git a/src/main/java/src/SandboxFrame.java b/src/main/java/src/SandboxFrame.java index 0d2a89a..4fffa86 100644 --- a/src/main/java/src/SandboxFrame.java +++ b/src/main/java/src/SandboxFrame.java @@ -1,15 +1,235 @@ package src; import javax.swing.*; +import javax.swing.border.LineBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; public class SandboxFrame extends JFrame { + private GameField gameField; + private JPanel rootPanel; + + private String difficulty = "easy"; + public void run() { this.setLayout(null); this.setVisible(true); - this.setBounds(400, 200, 500, 500); + this.setBounds(400, 200, 500, 550); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setupLayout(); + + } + + private void setupLayout() { + + rootPanel = new JPanel(); + rootPanel.setVisible(true); + rootPanel.setBounds(0, 0, 500, 500); + rootPanel.setBackground(Color.LIGHT_GRAY); + rootPanel.setLayout(null); + this.setContentPane(rootPanel); + + JPanel header = setupHeader(20, 10); + header.setBounds(125, 5, 250, 50); + rootPanel.add(header); + + gameField = new GameField(360); + gameField.setBounds(70, 50, 360, 360); + rootPanel.add(gameField); + + JPanel diff = setupDifficulty(); + diff.setBounds(80, 420, 300, 35); + rootPanel.add(diff); + + JButton saveBtn = setupSaveButton(); + saveBtn.setBounds(400, 420, 100, 30); + rootPanel.add(saveBtn); + + JPanel numberField = setupNumberField(); + numberField.setBounds(100, 470, 300, 35); + + rootPanel.add(numberField); + } + + private JButton setupSaveButton() { + JButton save = new JButton("Save"); + save.setVisible(true); + + save.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + Model model = new Model(gameField); + model.createNewGame(difficulty); + + SandboxFrame.this.dispose(); + + } + }); + return save; + } + + private JPanel setupNumberField() { + + JPanel boxPanel = setupJPanel(); + boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.X_AXIS)); + + JPanel jPanel1 = setupNums("1"); + boxPanel.add(jPanel1); + + JPanel jPanel2 = setupNums("2"); + boxPanel.add(jPanel2); + + JPanel jPanel3 = setupNums("3"); + boxPanel.add(jPanel3); + + JPanel jPanel4 = setupNums("4"); + boxPanel.add(jPanel4); + + JPanel jPanel5 = setupNums("5"); + boxPanel.add(jPanel5); + + JPanel jPanel6 = setupNums("6"); + boxPanel.add(jPanel6); + + JPanel jPanel7 = setupNums("7"); + boxPanel.add(jPanel7); + + JPanel jPanel8 = setupNums("8"); + boxPanel.add(jPanel8); + + JPanel jPanel9 = setupNums("9"); + boxPanel.add(jPanel9); + + return boxPanel; + } + + private JPanel setupDifficulty() { + + JPanel jPanel = new JPanel(); + jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS)); + + JButton easy = new JButton("Easy"); + easy.setPreferredSize(new Dimension(100, 30)); + easy.setVisible(true); + jPanel.add(easy); + + easy.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "easy"; + } + }); + + jPanel.add(Box.createHorizontalStrut(10)); + + JButton medium = new JButton("Medium"); + medium.setPreferredSize(new Dimension(100, 30)); + medium.setVisible(true); + jPanel.add(medium); + medium.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "medium"; + } + }); + + jPanel.add(Box.createHorizontalStrut(10)); + + JButton hard = new JButton("Hard"); + hard.setPreferredSize(new Dimension(100, 30)); + hard.setVisible(true); + jPanel.add(hard); + hard.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "hard"; + } + }); + + + return jPanel; + } + + private JPanel setupHeader(int headerSize, int subheaderSize) { + + JPanel jPanel = new JPanel(); + jPanel.setVisible(true); + jPanel.setBackground(new Color(0, 0, 0, 0)); + jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); + + JLabel header = new JLabel(); + header.setAlignmentX(Component.CENTER_ALIGNMENT); + header.setText("Sudoku Sandbox"); + header.setVisible(true); + header.setForeground(Color.BLACK); + header.setFont(new Font("Times New Roman", Font.BOLD, headerSize)); + jPanel.add(header); + + JLabel subheader = new JLabel(); + subheader.setAlignmentX(Component.CENTER_ALIGNMENT); + subheader.setText("Represented by Team Deep Thought"); + subheader.setVisible(true); + subheader.setForeground(Color.BLACK); + subheader.setFont(new Font("Times New Roman", Font.ITALIC, subheaderSize)); + jPanel.add(subheader); + + return jPanel; + } + + private JPanel setupNums(String number) { + + JPanel jPanel = new JPanel(); + jPanel.setBackground(Color.BLUE); + jPanel.setVisible(true); + jPanel.setBorder(new LineBorder(Color.PINK, 1)); + jPanel.addMouseListener(new MouseListener() { + @Override + public void mouseClicked(MouseEvent e) { + + } + + @Override + public void mousePressed(MouseEvent e) { + gameField.getActivePanel().setValue(Integer.valueOf(number)); + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + }); + JLabel numLabel1 = new JLabel(); + numLabel1.setText(number); + numLabel1.setLayout(null); + numLabel1.setVisible(true); + jPanel.add(numLabel1); + + return jPanel; + } + + public JPanel setupJPanel() { + JPanel panel = new JPanel(); + panel.setBounds(100, 450, 300, 30); + panel.setVisible(true); + panel.setBackground(Color.GREEN); + return panel; } } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 00e5c38..d20745d 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -103,7 +103,7 @@ class TasksFrameTest { assertEquals(1,p3); } - } +}