<commit_before>/*
* This class gets the user to setup their ships. It validates their locations as well
*/

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BattleshipsSetupShips extends JFrame implements ActionListener {
    //location of starting square
    private String aircraftLocation;
    private String battleshipLocation;
    private String submarineLocation;
    private String destroyerLocation;
    private String minesweeperLocation;
    
    //lengths of each ship
    private final int AIRCRAFT_LENGTH = 5;
    private final int BATTLESHIP_LENGTH = 4;
    private final int SUBMARINE_LENGTH = 3;
    private final int DESTROYER_LENGTH = 3;
    private final int MINESWEEPER_LENGTH = 2;
    
    //stores the locations of the ships
    private ArrayList<String> aircraftLocations;
    private ArrayList<String> battleshipLocations;
    private ArrayList<String> submarineLocations;
    private ArrayList<String> destroyerLocations;
    private ArrayList<String> minesweeperLocations;
    
    private Ship aircraftShip;
    private Ship battleshipShip;
    private Ship submarineShip;
    private Ship destroyerShip;
    private Ship minesweeperShip;
    
    private JButton directionButton;
    private JButton doneButton;
    private JButton aircraftButton;
    private JButton battleshipButton;
    private JButton submarineButton;
    private JButton destroyerButton;
    private JButton minesweeperButton;
    
    private JPanel actionPanel;
    private JPanel fieldPanel;
    
    private String currentDirection = "Down";
    private String currentLocation = "A1";
    private String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
    
    private boolean aircraftSet = false;
    private boolean battleshipSet = false;
    private boolean submarineSet = false;
    private boolean destroyerSet = false;
    private boolean minesweeperSet = false;
    
    private int shipsPlaced = 0; //number of ships placed
    
    private JLabel selectedLabel = new JLabel(currentLocation);
    private JLabel directionLabel = new JLabel(currentDirection);
    private JLabel numberSetLabel = new JLabel("Ships set: " + shipsPlaced + "/5");
    
    private ArrayList<BattleshipsSetupShipsPanel> setupPanelList = new ArrayList<BattleshipsSetupShipsPanel>();
    
    public BattleshipsSetupShips() {
        setTitle("Place Your Ships!");
        setBackground(BattleshipsMainFrame.BG_COLOUR);
        setSize(1000, 550);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLayout(new GridLayout(1, 2));
        
        
        selectedLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        selectedLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        directionLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        directionLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        numberSetLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        numberSetLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
               
        
        GridBagLayout panelLayout = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        
        actionPanel = new JPanel();
        actionPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        actionPanel.setLayout(panelLayout);
        
        
        //
        //direction button
        //
        directionButton = new JButton("Swap Direction");
        directionButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        directionButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        directionButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        directionButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 2;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(directionButton, c);
        
        
        //
        //done button
        //
        doneButton = new JButton("Battle!");
        doneButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        doneButton.setFont(BattleshipsMainFrame.MAIN_FONT);
        doneButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        doneButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(25, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 4;
        c.gridwidth = 2;
        //finally add
        actionPanel.add(doneButton, c);
        
        
        //
        //number set label
        //
        c.insets = new Insets(25, 5, 5, 5); //the padding around the component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 4;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(numberSetLabel, c);
        
        
        //
        //aircraft button
        //
        aircraftButton = new JButton("Aircraft Carrier");
        aircraftButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        aircraftButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        aircraftButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        aircraftButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(aircraftButton, c);
        
        
        //
        //battleship button
        //
        battleshipButton = new JButton("Battleship");
        battleshipButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        battleshipButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        battleshipButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        battleshipButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(battleshipButton, c);
        
        
        //
        //submarine button
        //
        submarineButton = new JButton("Submarine");
        submarineButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        submarineButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        submarineButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        submarineButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 2;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(submarineButton, c);
        
        
        //
        //destroyer button
        //
        destroyerButton = new JButton("Destroyer");
        destroyerButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        destroyerButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        destroyerButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        destroyerButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(destroyerButton, c);
        
        
        //
        //minesweeper button
        //
        minesweeperButton = new JButton("Minesweeper");
        minesweeperButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        minesweeperButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        minesweeperButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        minesweeperButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(minesweeperButton, c);
        
        
        //set constraints for direction label
        c.insets = new Insets(20, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 3;
        actionPanel.add(directionLabel, c);
        
        
        //set constraints for selected label
        c.insets = new Insets(20, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 3;
        c.gridwidth = 3;
        actionPanel.add(selectedLabel, c);
        
                
        //
        //setup fieldPanel that has all the squares in it
        //
        fieldPanel = new JPanel();
        GridLayout fieldLayout = new GridLayout(11, 11);
        
        JPanel blankPanel = new JPanel();
        blankPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        fieldPanel.setLayout(fieldLayout);
        fieldPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        fieldPanel.setPreferredSize(new Dimension(600, 600));
        fieldPanel.add(blankPanel);
        
        //add number labels
        for(int i = 0; i<10; i++) {
            JLabel l = new JLabel(Integer.toString(i+1));
            l.setFont(BattleshipsMainFrame.MAIN_FONT);
            l.setForeground(Color.WHITE);
            fieldPanel.add(l);
        }
        
        //add the rest
        for(int i = 0; i<10; i++) {
            String letter = letters[i];
            
            JLabel l = new JLabel();
            l.setForeground(Color.WHITE);
            l.setFont(BattleshipsMainFrame.MAIN_FONT);
            l.setText(letter);
            
            fieldPanel.add(l); //add letter label
            
            //add the field panel
            for(int y = 0; y < 10; y++) {
                String fullName = letter + Integer.toString(y+1);
                
                BattleshipsSetupShipsPanel p = new BattleshipsSetupShipsPanel(fullName);
                
                fieldPanel.add(p);
                setupPanelList.add(p);
            }
        }<commit_msg>Changed acces of arraylists and centered text<commit_after>/*
* This class gets the user to setup their ships. It validates their locations as well
*/

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class BattleshipsSetupShips extends JFrame implements ActionListener {
    //location of starting square
    private String aircraftLocation;
    private String battleshipLocation;
    private String submarineLocation;
    private String destroyerLocation;
    private String minesweeperLocation;
    
    //lengths of each ship
    private final int AIRCRAFT_LENGTH = 5;
    private final int BATTLESHIP_LENGTH = 4;
    private final int SUBMARINE_LENGTH = 3;
    private final int DESTROYER_LENGTH = 3;
    private final int MINESWEEPER_LENGTH = 2;
    
    //stores the locations of the ships
    public static ArrayList<String> aircraftLocations;
    public static ArrayList<String> battleshipLocations;
    public static ArrayList<String> submarineLocations;
    public static ArrayList<String> destroyerLocations;
    public static ArrayList<String> minesweeperLocations;
    
    private Ship aircraftShip;
    private Ship battleshipShip;
    private Ship submarineShip;
    private Ship destroyerShip;
    private Ship minesweeperShip;
    
    private JButton directionButton;
    private JButton doneButton;
    private JButton aircraftButton;
    private JButton battleshipButton;
    private JButton submarineButton;
    private JButton destroyerButton;
    private JButton minesweeperButton;
    
    private JPanel actionPanel;
    private JPanel fieldPanel;
    
    private String currentDirection = "Down";
    private String currentLocation = "A1";
    private String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
    
    private boolean aircraftSet = false;
    private boolean battleshipSet = false;
    private boolean submarineSet = false;
    private boolean destroyerSet = false;
    private boolean minesweeperSet = false;
    
    private int shipsPlaced = 0; //number of ships placed
    
    private JLabel selectedLabel = new JLabel(currentLocation, JLabel.CENTER);
    private JLabel directionLabel = new JLabel(currentDirection, JLabel.CENTER);
    private JLabel numberSetLabel = new JLabel("Ships set: " + shipsPlaced + "/5", JLabel.CENTER);
    
    private ArrayList<BattleshipsSetupShipsPanel> setupPanelList = new ArrayList<BattleshipsSetupShipsPanel>();
    
    public BattleshipsSetupShips() {
        setTitle("Place Your Ships!");
        setBackground(BattleshipsMainFrame.BG_COLOUR);
        setSize(1000, 550);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setResizable(false);
        setLayout(new GridLayout(1, 2));
        
        
        selectedLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        selectedLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        directionLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        directionLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        numberSetLabel.setFont(BattleshipsMainFrame.MAIN_FONT);
        numberSetLabel.setBackground(BattleshipsMainFrame.BG_COLOUR);
               
        
        GridBagLayout panelLayout = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        
        actionPanel = new JPanel();
        actionPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        actionPanel.setLayout(panelLayout);
        
        
        //
        //direction button
        //
        directionButton = new JButton("Swap Direction");
        directionButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        directionButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        directionButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        directionButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 2;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(directionButton, c);
        
        
        //
        //done button
        //
        doneButton = new JButton("Battle!");
        doneButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        doneButton.setFont(BattleshipsMainFrame.MAIN_FONT);
        doneButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        doneButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(25, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 4;
        c.gridwidth = 2;
        //finally add
        actionPanel.add(doneButton, c);
        
        
        //
        //number set label
        //
        c.insets = new Insets(25, 5, 5, 5); //the padding around the component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 4;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(numberSetLabel, c);
        
        
        //
        //aircraft button
        //
        aircraftButton = new JButton("Aircraft Carrier");
        aircraftButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        aircraftButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        aircraftButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        aircraftButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(aircraftButton, c);
        
        
        //
        //battleship button
        //
        battleshipButton = new JButton("Battleship");
        battleshipButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        battleshipButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        battleshipButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        battleshipButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(battleshipButton, c);
        
        
        //
        //submarine button
        //
        submarineButton = new JButton("Submarine");
        submarineButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        submarineButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        submarineButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        submarineButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 2;
        c.gridy = 0;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(submarineButton, c);
        
        
        //
        //destroyer button
        //
        destroyerButton = new JButton("Destroyer");
        destroyerButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        destroyerButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        destroyerButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        destroyerButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(destroyerButton, c);
        
        
        //
        //minesweeper button
        //
        minesweeperButton = new JButton("Minesweeper");
        minesweeperButton.setBackground(BattleshipsMainFrame.BUTTON_COLOUR);
        minesweeperButton.setFont(BattleshipsMainFrame.MEDIUM_FONT);
        minesweeperButton.setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
        minesweeperButton.addActionListener(this);
        //set constraints
        c.insets = new Insets(5, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 1;
        c.gridy = 1;
        c.gridwidth = 1;
        //finally add
        actionPanel.add(minesweeperButton, c);
        
        
        //set constraints for direction label
        c.insets = new Insets(20, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 3;
        actionPanel.add(directionLabel, c);
        
        
        //set constraints for selected label
        c.insets = new Insets(20, 5, 5, 5); //the padding around component
        c.ipadx = 5;
        c.ipady = 5;
        c.gridx = 0;
        c.gridy = 3;
        c.gridwidth = 3;
        actionPanel.add(selectedLabel, c);
        
                
        //
        //setup fieldPanel that has all the squares in it
        //
        fieldPanel = new JPanel();
        GridLayout fieldLayout = new GridLayout(11, 11);
        
        JPanel blankPanel = new JPanel();
        blankPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        
        fieldPanel.setLayout(fieldLayout);
        fieldPanel.setBackground(BattleshipsMainFrame.BG_COLOUR);
        fieldPanel.setPreferredSize(new Dimension(600, 600));
        fieldPanel.add(blankPanel);
        
        //add number labels
        for(int i = 0; i<10; i++) {
            JLabel l = new JLabel(Integer.toString(i+1), JLabel.CENTER);
            l.setFont(BattleshipsMainFrame.MAIN_FONT);
            l.setForeground(Color.WHITE);
            
            fieldPanel.add(l);
        }
        
        //add the rest
        for(int i = 0; i<10; i++) {
            String letter = letters[i];
            
            JLabel l = new JLabel(letter, JLabel.CENTER);
            l.setForeground(Color.WHITE);
            l.setFont(BattleshipsMainFrame.`MAIN_FONT);
            
            fieldPanel.add(l); //add letter label
            
            //add the field panel
            for(int y = 0; y < 10; y++) {
                String fullName = letter + Integer.toString(y+1);
                
                BattleshipsSetupShipsPanel p = new BattleshipsSetupShipsPanel(fullName);
                
                fieldPanel.add(p);
                setupPanelList.add(p);
            }
        }
{'fraction_non_alphanumeric': 0.09315679574791193, 'fraction_numerical': 0.013192862566438876, 'mean_word_length': 2.1021639923450612, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2111158', 'n_tokens_mistral': 6447, 'n_tokens_neox': 6151, 'n_words': 1349}