Task 1: Simple GUI Form

package nmmu.wrap301.Task1;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;

/**
 * An implementation of a registration GUI that accepts a
 * Name, Surname, Student Number, Course and Year.
 *
 * @author  Sithe
 * @version 1.0
 */
public class Task1 extends Application{
    /**
     * This is the main method which implements the Application interface for jfx
     * @param args Unused.
     * @return Nothing.
     * @exception Exception On input error.
     * @see Application
     */
    public static void main(String[] args) {
        launch(args);
    }


    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("Personal Details");


        Label lblName = new Label("Name");
        TextField txtName = new TextField();

        Label lblSurName = new Label("Surname");
        TextField txtSurname = new TextField();

        Label lblStudNum = new Label("Student Number");
        TextField txtStudNum = new TextField();

        Label lblCourse = new Label("Course");
        TextField txtCourse = new TextField();

        Label lblYear = new Label("Year");
        TextField txtYear = new TextField();

        Button btnok = new Button("Ok");
        Button btnCancel = new Button("Cancel");

        GridPane root=new GridPane();
        root.setHgap(5);
        root.setVgap(5);
        root.setPadding(new Insets(0, 5, 0, 5));

        root.add(lblName, 0, 0);
        root.add(txtName,1,0);

        root.add(lblSurName,0,1);
        root.add(txtSurname,1,1);

        root.add(lblStudNum,0,2);
        root.add(txtStudNum,1,2);

        root.add(lblCourse,0,3);
        root.add(txtCourse,1,3);

        root.add(lblYear,0,4);
        root.add(txtYear,1,4);

        BorderPane pane=new BorderPane();
        pane.setRight(btnok);
        root.add(pane, 0, 5);
        root.add(btnCancel,1,5);

        btnok.setOnAction(event ->
                {
                    System.out.println("Student number: " + txtStudNum.getText());
                    System.out.println("Name: " + txtName.getText());
                    System.out.println("Surname: " + txtSurname.getText());
                    System.out.println("Course: " + txtCourse.getText());
                    System.out.println( "Year: " + txtYear.getText());
                }
        );

        btnCancel.setOnAction(event ->
                {
                    txtName.clear();
                    txtCourse.clear();
                    txtStudNum.clear();
                    txtSurname.clear();
                    txtYear.clear();
                }
        );

        primaryStage.setScene(new Scene(root));

        primaryStage.show();
    }
}

Task 2: Other form controls

package nmmu.wrap301.Task2;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * An implementation of a printer GUI that accepts a
 * Name, Surname, Student Number, Course and Year.
 *
 * @author  Sithe
 * @version 1.0
 */
public class Task2 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        //set scene title
        primaryStage.setTitle("Print Dialog");

        //create gridpane layout
        GridPane Layout = new GridPane();
        ToggleGroup group = new ToggleGroup();

        Layout.setHgap(5);
        Layout.setVgap(5);
        Layout.setPadding(new Insets(0, 5, 0, 5));

        Label title = new Label("Printer Epson Epl-700");
        Layout.add(title,0,0,4,1);

        RadioButton radioImage = new RadioButton();
        radioImage.setText("Image");
        radioImage.setToggleGroup(group);

        RadioButton radioText = new RadioButton();
        radioText.setText("Text");
        radioText.setToggleGroup(group);

        RadioButton radioCode = new RadioButton();
        radioCode.setText("Code");
        radioCode.setToggleGroup(group);


        Layout.add(radioImage,1,1);
        Layout.add(radioText,1,2);
        Layout.add(radioCode,1,3);

        ObservableList<String> options = FXCollections.observableArrayList("Low", "Medium", "High");

        Label Quality = new Label("Print Quality:");
        ComboBox comboPrint = new ComboBox(options);
        //comboPrint.getSelectionModel().select(0);
        CheckBox option = new CheckBox();
        Label PrintCheck = new Label("Print to File");

        Layout.add(Quality, 0,4,1,1);
        Layout.add(comboPrint,1,4,1,1);
        Layout.add(option,2,4,1,1);
        Layout.add(PrintCheck,3,4,1,1);

        //create buttons
        Button btnOk = new Button("OK");
        Button btnCancel = new Button("Cancel");
        Button btnSetup = new Button("Setup...");
        Button btnHelp = new Button("Help");

        //set button width and height to max value
        btnOk.setMaxWidth(Double.MAX_VALUE);
        btnCancel.setMaxWidth(Double.MAX_VALUE);
        btnSetup.setMaxWidth(Double.MAX_VALUE);
        btnHelp.setMaxWidth(Double.MAX_VALUE);

        btnOk.setMaxHeight(Double.MAX_VALUE);
        btnCancel.setMaxHeight(Double.MAX_VALUE);
        btnSetup.setMaxHeight(Double.MAX_VALUE);
        btnHelp.setMaxHeight(Double.MAX_VALUE);

        //Vertical box for buttons
        VBox vbButtons = new VBox(btnOk,btnCancel,btnSetup,btnHelp);
        Layout.add(vbButtons,4,0,1,5);

        Layout.setHalignment(vbButtons, HPos.RIGHT);

        //setscene and dimensions
        primaryStage.setScene(new Scene(Layout,335,135));
        primaryStage.show();
    }
}

Task 3: SOS Game

Game

package nmmu.wrap301.Task3;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * An implementation of a printer GUI that accepts a
 * Name, Surname, Student Number, Course and Year.
 *
 * @author  Sithe
 * @version 1.0
 */
public class Task3 extends Application{
    public static Player player1;
    public static Player player2;
    public static Tile Current;
    public static Scanner in;
    public static ArrayList<Tile> list;
    public static ArrayList<Tile> played;
    public static int playerturn = -1; //used to alternate turns


    public static void main(String[] args) {
        launch(args);
    }

    public static void changebutton(Tile x)
    {
        switch(x.getText())
        {
            case "S" : x.setText("O");
                x.setValue(13);
                break;
            case "O" : x.setText("");
                x.setValue(0);
                break;
            default: x.setText("S");
                x.setValue(11);
                break;

        }
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setTitle("SOS game");

        System.out.println("Game has started.....");
        list = new ArrayList<>();

        played = new ArrayList<>();
        player1 = new Player("p1",0);

        player2 = new Player("p2",0);

        Current = new Tile();
        Current.setText("");


        GridPane box = new GridPane();
        box.setMaxHeight(Double.MAX_VALUE);
        box.setMaxWidth(Double.MAX_VALUE);
        VBox container = new VBox();
        for(int x = 0; x < 5; x++)
        {
            RowConstraints rows = new RowConstraints(100);
            box.getRowConstraints().add(rows);

            for(int y = 0; y < 5; y++)
            {
                ColumnConstraints column = new ColumnConstraints(100);
                box.getColumnConstraints().add(column);
                Tile cur = new Tile();
                cur.setMaxHeight(Double.MAX_VALUE);
                cur.setMaxWidth(Double.MAX_VALUE);


                cur.setOnAction(event -> {
                    Current = cur;
                    if(!Current.isSelected()) {
                        resetgrid(cur);
                        changebutton(Current);
                    }

                });




                cur.setId(x + ":" + y);
                cur.setColval(y);
                cur.setRowval(x);
                box.add(cur,x,y);
                list.add(cur);



            }

        }


        Button btnDone = new Button("Done");
        btnDone.setMaxWidth(Double.MAX_VALUE - 1);
        btnDone.setMaxHeight(Double.MAX_VALUE);

        container.setSpacing(10);


        btnDone.setOnAction(event ->{


            if(!Current.getText().equals("")) {
                checkgamestatus(box);
                Current.setSelected(true);
                Current.setStyle("-fx-text-fill: white; -fx-background-color: #A9A9A9;");
                playerturn = playerturn * -1;
            }
        });
        Label lblPlayer1 = new Label(player1.getName() + ":");
        Label lblPlayer2 = new Label(player2.getName() + ":");
        HBox hbcurrentstate = new HBox();
        hbcurrentstate.setSpacing(50);
        hbcurrentstate.getChildren().addAll(lblPlayer1,lblPlayer2);
        container.getChildren().addAll(box,btnDone,hbcurrentstate);


        primaryStage.setScene(new Scene(container,500,600));
        primaryStage.show();




    }

    private void resetgrid(Tile cur) {
        for(Tile x:list)
        {
            if(!x.getId().equals(cur.getId()) && !x.isSelected())
                x.setText("");
        }

    }

    private void checkgamestatus(GridPane box) {

        Tile temp = new Tile();
        played.clear();
        if(list.size() > 0) {
            for (int x = 1; x <= 25; x++) {
                temp =  list.get(x - 1);
                if(temp.isSelected())
                    played.add(temp);
            }
            for(Tile x:played)
            {
                String result = "";
                switch (x.getText())
                {
                    case "S": checkadjacentO(x);
                        break;
                    case "O": checkadjacentS(x.getId());
                        break;

                }
            }
        }
    }

    private void checkadjacentS(String id) {

    }

    private void checkadjacentO(Tile x) {

        String result = "";
        result.concat(x.getText());
        ArrayList<Tile> row = new ArrayList<>();
        //check sos horizontal
        for(int a = 0; a < 5; a++) {
            Tile cur = list.get(x.getColval()+1);
            if (cur.getText().equals("O"))
                result.concat(cur.getText());

        }
        System.out.println(result);


    }
}

Player

package nmmu.wrap301.Task3;

/**
 * Created by Sithe on 4/24/2017.
 */
public class Player {
    private String name;
    private int score;

    public Player(String name, int score) {
        this.name = name;
        this.score = score;
    }

    public Player() {
    }

    public String getName() {

        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Player name: " + name + ">>>Score: " + score;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }
}

Tile

package nmmu.wrap301.Task3;

import javafx.scene.control.Button;

/**
 * Created by Sithe on 4/24/2017.
 */
public class Tile extends Button{
    private boolean selected;
    private int value;
    private int rowval;
    private int colval;

    public Tile() {
        selected = false;
    }

    public Tile(String text) {
        super(text);
        selected = false;
    }

    public int getRowval() {
        return rowval;
    }

    public void setRowval(int rowval) {
        this.rowval = rowval;
    }

    public int getColval() {
        return colval;
    }

    public void setColval(int colval) {
        this.colval = colval;
    }

    public boolean isSelected() {
        return selected;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
}