Skip to content

Instantly share code, notes, and snippets.

View sedj601's full-sized avatar
😂
Happy Coding!

Sedrick Jefferson sedj601

😂
Happy Coding!
  • Auburn, AL
View GitHub Profile
@james-d
james-d / Book.fxml
Last active June 27, 2023 19:40
Demo of a MVC-like approach to managing view switching in JavaFX. Contains three views: a login screen, and two other pages. The model holds a user and a "browse state". A view manager determines the current view based on values in the model. The FXML controllers/presenters have a reference to a shared model whose properties they update.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
spacing="20"
package tankgame;
import java.util.ArrayList;
import java.util.List;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Insets;
@james-d
james-d / FXCamTest.java
Last active May 18, 2018 16:11
JavaFX wrapper classes for sarxos webcam Java library. Wraps a web cam as a JavaFX Service and provides a View class for the service.
import com.github.sarxos.webcam.Webcam;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
@james-d
james-d / SunEarthMoon.java
Last active May 18, 2018 16:16
Very simple (and not intended to be accurate) model of the sun, earth and moon to demonstrate rotations applied to circles in JavaFX.
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
@james-d
james-d / RectangleDrawing.java
Last active June 27, 2023 19:50
Demo of event handling and consuming events. Double click to add a rectangle. Selected rectangles have a gold border. Drag a rectangle to move it; drag on empty space to select.
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener.Change;
@james-d
james-d / AnimationTimerTest.java
Last active May 28, 2023 08:02
Experiment to see how smooth animation is in JavaFX using an AnimationTimer to update the view on each pulse. This simulates 300 balls of various sizes bouncing (with perfect elasticity) off each other and the edges of the Pane in which they're contained. It could easily be extended to a simulation where the pressure on each wall was measured by…
import static java.lang.Math.PI;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.sqrt;
import static javafx.scene.paint.Color.BLACK;
import static javafx.scene.paint.Color.BLUE;
import static javafx.scene.paint.Color.BROWN;
import static javafx.scene.paint.Color.GREEN;
import static javafx.scene.paint.Color.PINK;
import static javafx.scene.paint.Color.RED;
@james-d
james-d / ShootingGame.java
Last active March 26, 2021 23:15
Demo of using Shape.intersect(...) in conjunction with a TranslateTransition to test for collisions.
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@james-d
james-d / ZoomableLineChart.java
Created October 31, 2013 16:29
Example of a LineChart that can be zoomed via mouse.
import java.util.Collections;
import java.util.Random;
import javafx.application.Application;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
@jewelsea
jewelsea / ChartGrid.java
Created December 12, 2012 02:28
JavaFX sample of a 4x4 grid of charts which, on click, explode to fill the grid and implode to return their original position.
import javafx.animation.*;
import javafx.application.Application;
import javafx.beans.property.*;
import javafx.event.*;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.chart.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.stage.Stage;