Skip to content

Commit

Permalink
added images for buttons, removing some hard coded text
Browse files Browse the repository at this point in the history
  • Loading branch information
KelBell1009 committed Sep 23, 2017
1 parent 6c7fb64 commit 3b160c6
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="images"/>
<classpathentry kind="src" path="data"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file added images/fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gameoflife.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/restart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/resume.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/segregation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/wator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 10 additions & 31 deletions src/cellsociety_team04/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javafx.scene.text.TextAlignment;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
*
Expand All @@ -27,8 +28,15 @@
public class Driver extends Application {

private static final String TITLE = "Cell Society";
/* private static final double MILLISECOND_DELAY = 0;
private static final String SECOND_DELAY = null;*/
private boolean segregationWindow = false;
private boolean segregationRunning = false;
private boolean watorWindow = false;
private boolean watorRunning = false;
private boolean fireWindow = false;
private boolean fireRunning = false;
private boolean gameoflifeWindow = false;
private boolean gameoflifeRunning = false;

private Stage menuStage;

/**
Expand All @@ -42,37 +50,8 @@ public void start(Stage stage) {
Window menu = new MenuWindow();
menuStage.setScene(menu.getScene());
menuStage.show();

/*segregation.setOnAction(e -> {
Stage segStage = new Stage();
//segStage.run();
});
*//* //attach the game loop
KeyFrame frame = new KeyFrame(Duration.millis(MILLISECOND_DELAY),
e -> step(SECOND_DELAY, root));
Timeline animation = new Timeline();
animation.setCycleCount(Timeline.INDEFINITE);
animation.getKeyFrames().add(frame);
animation.play();*/
}

/* private Object step(String secondDelay, Group root2) {
// TODO Auto-generated method stub
return null;
}*/

/* private void formatStage(Rectangle2D dimensions, double width, double height) {
menuStage.setX(dimensions.getMinX());
menuStage.setY(dimensions.getMinY());
menuStage.setWidth(width);
menuStage.setHeight(height);
}*/

/* private Button simButton() {
}*/


/**
* Start of the program
*/
Expand Down
5 changes: 5 additions & 0 deletions src/cellsociety_team04/FireWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cellsociety_team04;

public class FireWindow extends Window {

}
15 changes: 15 additions & 0 deletions src/cellsociety_team04/GameOfLifeWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ public GameOfLifeWindow() {
super();

}

/**
* Updates the cells for each SimulationWindow
*/
public void step(double elapsedTime) {
// do nothing
if (windowOpen) {
if (simulationRunning) {

}
else {

}
}
}


}
62 changes: 40 additions & 22 deletions src/cellsociety_team04/MenuWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,74 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.ColumnConstraintsBuilder;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

public class MenuWindow extends Window {

private static final int BUTTONOFFSET = 10;
private static final int BUTTONOFFSET = 50;
private List<Button> buttons;
private List<String> buttonNames = new ArrayList<String>(Arrays.asList("Segregation", "Predator-Prey", "Fire", "Game of Life"));
private double BUTTONPADDING = (WIDTH - BUTTONOFFSET*2)/buttonNames.size();
private static final double buttonScale = 0.5;

private double buttonPadding;

public MenuWindow() {
super();
setupScene();
userInteraction();
}

private void userInteraction() {
/* for (int i = 0; i < buttons.size(); i++) {
buttonNames.get(i).setOnAction(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(ActionEvent e) {
label.setText("Accepted");
private void userInteraction() { //http://www.java2s.com/Code/Java/JavaFX/AddClickactionlistenertoButton.htm
for (int i = 0; i < buttons.size(); i ++) {
Button button = buttons.get(i);
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
//TODO need to have new stage open instead
}
});
}*/
}
}

@Override
public void setupScene() {
buttons = new ArrayList<Button>();
addButtons();
addTitle();
}

private void addButtons() { //https://stackoverflow.com/questions/40883858/how-to-evenly-distribute-elements-of-a-javafx-vbox
for (int i = 0; i < buttonNames.size(); i++) {
Button button = new Button(buttonNames.get(i));
button.setLayoutX(BUTTONOFFSET + i*BUTTONPADDING);
//http://docs.oracle.com/javafx/2/ui_controls/button.htm
Image segregationImage = new Image(getClass().getClassLoader().getResourceAsStream("segregation.png"));
Button segregationButton = new Button();
segregationButton.setGraphic(new ImageView(segregationImage));

Image watorImage = new Image(getClass().getClassLoader().getResourceAsStream("wator.png"));
Button watorButton = new Button();
watorButton.setGraphic(new ImageView(watorImage));

Image fireImage = new Image(getClass().getClassLoader().getResourceAsStream("fire.png"));
Button fireButton = new Button();
fireButton.setGraphic(new ImageView(fireImage));

Image gameoflifeImage = new Image(getClass().getClassLoader().getResourceAsStream("gameoflife.png"));
Button gameoflifeButton = new Button();
gameoflifeButton.setGraphic(new ImageView(gameoflifeImage));

buttons = new ArrayList<Button>(Arrays.asList(segregationButton, watorButton, fireButton, gameoflifeButton));
System.out.println(buttons);
buttonPadding = (WIDTH - BUTTONOFFSET*2 - buttons.get(0).getWidth())/buttons.size();

for (int i = 0; i < buttons.size(); i++) {
Button button = buttons.get(i);
//System.out.println(button);
button.setLayoutX(BUTTONOFFSET + buttons.get(i).getWidth() + i*buttonPadding);
button.setLayoutY(HEIGHT*2/3);
buttons.add(button);
myRoot.getChildren().add(button);
}
}
Expand Down
86 changes: 63 additions & 23 deletions src/cellsociety_team04/SimulationWindow.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,95 @@
package cellsociety_team04;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;

public abstract class SimulationWindow extends Window {
protected boolean start;
protected Button run;
protected Button step;
protected double mySpeed;
protected ArrayList<Button> myButtons;
protected double speed;
protected double numCells;
protected double cellSize;
private ArrayList<Button> buttons;

protected List<Button> buttons;
private List<String> buttonNames = new ArrayList<String>(Arrays.asList("Start", "Step"));

protected boolean windowOpen = false;
protected boolean simulationRunning = false;

private static final int FRAMES_PER_SECOND = 60;
private static final int MILLISECOND_DELAY = 1000 / FRAMES_PER_SECOND;
private static final double SECOND_DELAY = 1.0 / FRAMES_PER_SECOND;


public SimulationWindow() {
super();
setupScene();
userInteraction();

// attach "game loop" to timeline to play it
KeyFrame frame = new KeyFrame(Duration.millis(MILLISECOND_DELAY),
e -> step(SECOND_DELAY));
Timeline animation = new Timeline();
animation.setCycleCount(Timeline.INDEFINITE);
animation.getKeyFrames().add(frame);
animation.play();
}


private void userInteraction() {
// TODO Auto-generated method stub

}

/**
* Updates the cells for each SimulationWindow
*/
public void step(double elapsedTime) {
// do nothing
}

@Override
public void setupScene() {
buttons = new ArrayList<Button>();
addButtons();
addTitle();
}

private void addButtons() {

//TODO
}

private void addTitle() {
//TODO
}

private void addSlider() {

}

public GridPane addGridPane() { //https://stackoverflow.com/questions/35367060/gridpane-of-squares-in-javafx
GridPane grid = new GridPane();
for (int row = 0; row < numCells; row++) {
for (int col = 0; col < numCells; col++) {
Rectangle rect = new Rectangle();
rect.setWidth(cellSize);
rect.setHeight(cellSize);
GridPane.setRowIndex(rect, row);
GridPane.setColumnIndex(rect, col);
grid.getChildren().add(rect);
}
}
myRoot.getChildren().add(grid);
return grid;
GridPane grid = new GridPane();
for (int row = 0; row < numCells; row++) {
for (int col = 0; col < numCells; col++) {
Rectangle rect = new Rectangle();
rect.setWidth(cellSize);
rect.setHeight(cellSize);
GridPane.setRowIndex(rect, row);
GridPane.setColumnIndex(rect, col);
grid.getChildren().add(rect);
}
}
myRoot.getChildren().add(grid);
return grid;
}


}
5 changes: 5 additions & 0 deletions src/cellsociety_team04/WatorWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cellsociety_team04;

public class WatorWindow extends Window {

}
6 changes: 3 additions & 3 deletions src/cellsociety_team04/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ public abstract class Window {
protected Stage myStage;
protected Group myRoot;
protected Scene myScene;
protected static final double WIDTH = 500;
protected static final double WIDTH = 1000;
protected static final double HEIGHT = 500;

public Window() {
myStage = new Stage();
myRoot = new Group();
setSceneDimensions();
setupSceneDimensions();
myStage.setScene(myScene);
}

public void setupScene() {
//do nothing
}

public void setSceneDimensions() {
public void setupSceneDimensions() {
myScene = new Scene(myRoot, WIDTH, HEIGHT);
}

Expand Down

0 comments on commit 3b160c6

Please sign in to comment.