Browse Source
Merge remote-tracking branch 'origin/develop' into develop
Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # src/main/java/src/TasksFrame.javaremotes/origin/develop
fdai7460
2 years ago
7 changed files with 868 additions and 25 deletions
-
10src/main/java/src/GameField.java
-
96src/main/java/src/MainFrame.java
-
77src/main/java/src/Model.java
-
223src/main/java/src/SandboxFrame.java
-
405src/main/java/src/TasksFrame.java
-
5src/test/java/ModelTest.java
-
77src/test/java/src/TasksFrameTest.java
@ -1,15 +1,236 @@ |
|||
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; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue