FX My Life VIII: Why Do They Always Want To Do It The Hard Way?

public int getCoord(double width, double coord) {
long third = Math.round(width / 3);
if (coord < third) return 0;
else if (coord < (third*2)) return 1;
else return 2;
}
int row = getCoord(board.getWidth(), event.getX());
int column = getCoord(board.getHeight(), event.getY());
public int getCoord(double width, double coord, int numberOfSections) {
long dim = Math.round(width / numberOfSections);
long border = dim;
int val = 0;
while(coord > border) {
border += dim;
val++;
}
return val;
}

public void handleOnDragOver(DragEvent event) {
int row = getCoord(board.getWidth(), event.getX(), board.getRowCount());
int column = getCoord(board.getHeight(), event.getY(), board.getColumnCount());
public void handleOnDragDetected(MouseEvent event) {
Dragboard db = ((Node) event.getSource()).startDragAndDrop(TransferMode.ANY);

ClipboardContent content = new ClipboardContent();
content.putString(((ImageView) event.getSource()).getId());
db.setContent(content);
}
content.putString(((ImageView) event.getSource()).getId());
Dragboard db = ((Node) event.getSource()).startDragAndDrop(TransferMode.ANY);
Dragboard db = X.startDragAndDrop(TransferMode.ANY)
public String[][] state = new String[3][3];
public void handleOnDragOver(DragEvent event) {
int row = getCoord(board.getWidth(), event.getX(), board.getRowCount());
int column = getCoord(board.getHeight(), event.getY(), board.getColumnCount());

if (state[column][row]==null) {
if (event.getGestureSource() != board && event.getDragboard().hasString()) {
event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
}
event.consume();
}
public void handleOnDrop(DragEvent event) {
int row = getCoord(board.getWidth(), event.getX(), board.getRowCount());
int column = getCoord(board.getHeight(), event.getY(), board.getColumnCount());

ImageView xo = new ImageView();

if (event.getDragboard().getString().equals("X"))
xo.setImage(X.getImage());
else xo.setImage(O.getImage());
state[column][row] = event.getDragboard().getString();

xo.setFitWidth(Math.round(board.getWidth() / 3));
xo.setFitHeight(Math.round(board.getHeight() / 3));
GridPane.setRowIndex(xo, column);
GridPane.setColumnIndex(xo, row);
board.getChildren().addAll(xo);
}
  1. We get the row and column;
  2. Create a new image view;
  3. Put either an “X” or an “O” in it based on the event we created in handleOnDragDetected;
  4. Set the state to whatever’s in that event;
  5. Set the width and height of the image to fit on the board
  6. Set the row and column — probably should move that row/column code at the top down, may be into the setRowIndex/setColumnIndex code
  7. Add whatever it is to the board

--

--

--

I am a poor, wayfaring stranger, traveling through this world of woe.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Spoon Fed Guide to Your Own Private VPN with Google Compute Engine

CS 373 Fall 2020: Jonathan Randall

Nrwl Turns Three!

3 Pro Hacks For Beginners in Python

Agility Requires a Broader Understanding of the Agile Manifesto

Is Blazor Worth Your Time?

Blazor is worth your time, graphic of a girl sitting at a desk

Used dropbox/drive to upload files?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Blake

Blake

I am a poor, wayfaring stranger, traveling through this world of woe.

More from Medium

The FA domain

Use Cases: A Story of Four Tablets

How to speed up VTA transit in your city

A simple exercise in defying logic