I forgor to push

master
Caleb Fontenot 2023-09-08 09:17:53 +07:00
parent de8e3acf40
commit 6f5582f86e
64 changed files with 13137 additions and 141 deletions

3
.gitignore vendored

@ -150,3 +150,6 @@
/Semester 3/Assignments/MP2-chapter4_CalebFontenot/build/
/Semester 3/Assignments/MP2-chapter4_CalebFontenot/nbproject/private/
/Semester 3/Assignments/MP2-chapter4_CalebFontenot/dist/
/Semester 3/Assignments/MP2FX_Stelly/nbproject/private/
/Semester 3/Assignments/DonorProject/nbproject/private/
/Semester 3/Assignments/DonorProject/build/

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?><!-- You may freely edit this file. See commented blocks below for --><!-- some examples of how to customize the build. --><!-- (If you delete it and reopen the project it will be recreated.) --><!-- By default, only the Clean and Build commands use this build script. --><project name="DonorProject" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<description>Builds, tests, and runs the project DonorProject.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. Those of them relevant for JavaFX project are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-jfx-jar: called before FX SDK specific <fx:jar> task
-post-jfx-jar: called after FX SDK specific <fx:jar> task
-pre-jfx-deploy: called before FX SDK specific <fx:deploy> task
-post-jfx-deploy: called after FX SDK specific <fx:deploy> task
-pre-jfx-native: called just after -pre-jfx-deploy if <fx:deploy> runs in native packaging mode
-post-jfx-native: called just after -post-jfx-deploy if <fx:deploy> runs in native packaging mode
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting a HTML postprocessor after javaFX SDK deployment:
<target name="-post-jfx-deploy">
<basename property="jfx.deployment.base" file="${jfx.deployment.jar}" suffix=".jar"/>
<property name="jfx.deployment.html" location="${jfx.deployment.dir}${file.separator}${jfx.deployment.base}.html"/>
<custompostprocess>
<fileset dir="${jfx.deployment.html}"/>
</custompostprocess>
</target>
Example of calling an Ant task from JavaFX SDK. Note that access to JavaFX SDK Ant tasks must be
initialized; to ensure this is done add the dependence on -check-jfx-sdk-version target:
<target name="-post-jfx-jar" depends="-check-jfx-sdk-version">
<echo message="Calling jar task from JavaFX SDK"/>
<fx:jar ...>
...
</fx:jar>
</target>
For more details about JavaFX SDK Ant tasks go to
http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
For list of available properties check the files
nbproject/build-impl.xml and nbproject/jfx-impl.xml.
-->
</project>

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

@ -0,0 +1,2 @@
# Do not modify this property in this configuration. It can be re-generated.
$label=Run as WebStart

@ -0,0 +1,2 @@
# Do not modify this property in this configuration. It can be re-generated.
$label=Run in Browser

@ -0,0 +1,8 @@
build.xml.data.CRC32=6e52aa2c
build.xml.script.CRC32=47905a69
build.xml.stylesheet.CRC32=f85dc8f2@1.107.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=6e52aa2c
nbproject/build-impl.xml.script.CRC32=a0105a46
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48

File diff suppressed because it is too large Load Diff

@ -0,0 +1,120 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=DonorProject
application.vendor=caleb
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
compile.on.save=true
compile.on.save.unsupported.javafx=true
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/DonorProject.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects
jar.archive.disabled=true
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
javafx.application.implementation.version=1.0
javafx.binarycss=false
javafx.deploy.allowoffline=true
# If true, application update mode is set to 'background', if false, update mode is set to 'eager'
javafx.deploy.backgroundupdate=false
javafx.deploy.embedJNLP=true
javafx.deploy.includeDT=true
# Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs)
javafx.disable.concurrent.runs=false
# Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project
javafx.enable.concurrent.external.runs=false
# This is a JavaFX project
javafx.enabled=true
javafx.fallback.class=com.javafx.main.NoJavaFXFallback
# Main class for JavaFX
javafx.main.class=donorproject.DonorProject
javafx.preloader.class=
# This project does not use Preloader
javafx.preloader.enabled=false
javafx.preloader.jar.filename=
javafx.preloader.jar.path=
javafx.preloader.project.path=
javafx.preloader.type=none
# Set true for GlassFish only. Rebases manifest classpaths of JARs in lib dir. Not usable with signed JARs.
javafx.rebase.libs=false
javafx.run.height=600
javafx.run.width=800
# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects
jnlp.enabled=false
# Main class for Java launcher
main.class=com.javafx.main.Main
# For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed
manifest.custom.codebase=*
# Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions)
manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
run.classpath=\
${dist.jar}:\
${javac.classpath}:\
${build.classes.dir}
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1">
<extension file="jfx-impl.xml" id="jfx3">
<dependency dependsOn="-jfx-copylibs" target="-post-jar"/>
<dependency dependsOn="-rebase-libs" target="-post-jar"/>
<dependency dependsOn="jfx-deployment" target="-post-jar"/>
<dependency dependsOn="jar" target="debug"/>
<dependency dependsOn="jar" target="profile"/>
<dependency dependsOn="jar" target="run"/>
</extension>
</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>DonorProject</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

@ -0,0 +1,160 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package anim;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
/**
*
* @author asdv
*/
public class BouncingBall extends Pane
{
public int pScore = 0;
public int cScore = 0;
GridPane textDisplay = new GridPane();
Rectangle racket = new Rectangle();
public final double radius = 10; // ball size 40
private double x = radius, y = radius; // coordinates of ball
private double dx = 1, dy = 1; // direction of the ball
private Circle circle = new Circle(x, y, radius); // her majesty, the ball
private Timeline animation; // animate the ball
private Label playerScore = new Label("Your Score: 0");
private Label compScore = new Label("Computer Score: 0");
public BouncingBall()
{
racket.setWidth(70);
racket.setHeight(20);
racket.relocate(0, 580);
textDisplay.add(playerScore, 0, 0);
textDisplay.add(compScore, 0, 1);
circle.setFill(Color.BROWN);
getChildren().addAll(circle, racket, textDisplay);
animation = new Timeline(
new KeyFrame(Duration.millis(50), (ActionEvent event)
->
{
moveBall();
if (y >= (getHeight() - 20))
{
boolean intersected = intersection();
if (intersected && circle.getCenterX() <= racket.getX() / 2)
{
System.out.println("Intersected.");
dx *= -1;
dy *= -1;
playerScored();
}
else
{
if (intersected && circle.getCenterX() >= racket.getX() / 2)
{
playerScored();
dy *= -1;
}
else
{
if (y >= (getHeight() - 40))
{
computerScored();
dy *= -1;
}
}
}
}
}));
animation.setCycleCount(Timeline.INDEFINITE);
animation.setRate(animation.getRate() * 20);
animation.play();
}
private void moveBall()
{
if (x < radius || x > getWidth() - radius)
{
dx *= -1;
}
if (y < radius || y > getHeight() - radius)
{
dy *= -1;
}
x += dx;
y += dy;
circle.setCenterX(x);
circle.setCenterY(y);
}
public void playerScored()
{
playerScore.setText("Your Score: " + (++this.pScore));
}
public void computerScored()
{
compScore.setText("Computer Score: " + (++this.cScore));
}
public boolean intersection()
{
boolean intersected = racket.getBoundsInParent().intersects(circle.getBoundsInParent());
if (intersected)
{
return true;
}
else
{
return false;
}
}
public void moveRacket(double x)
{
racket.relocate(x, 580);
}
public void play()
{
animation.play();
}
public void pause()
{
animation.pause();
}
public void increaseSpeed()
{
animation.setRate(animation.getRate() * 1.5);
}
public void decreaseSpeed()
{
animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
}
public DoubleProperty rateProperty()
{
return animation.rateProperty();
}
}

@ -0,0 +1,65 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package anim;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
*
* @author asdv
*/
public class Tennis extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
BouncingBall bouncingBall = new BouncingBall();
Scene scene = new Scene(bouncingBall, 800, 600);
primaryStage.setTitle("Play Tennis");
primaryStage.setScene(scene);
primaryStage.show();
bouncingBall.requestFocus();
bouncingBall.setOnMousePressed((MouseEvent event) ->
{
bouncingBall.pause();
});
bouncingBall.setOnMouseReleased((MouseEvent event) ->
{
bouncingBall.play();
});
bouncingBall.setOnKeyPressed(e ->
{
if(e.getCode() == KeyCode.UP)
{
bouncingBall.increaseSpeed();
}
else if(e.getCode() == KeyCode.DOWN)
{
bouncingBall.decreaseSpeed();
}
});
bouncingBall.setOnMouseMoved((MouseEvent event) ->
{
bouncingBall.moveRacket(event.getSceneX() - bouncingBall.racket.getWidth() / 2);
});
}
public static void main(String[] args)
{
launch(args);
}
}

@ -0,0 +1,50 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/javafx/FXMain.java to edit this template
*/
package donorproject;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author caleb
*/
public class DonorProject extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

@ -9,16 +9,10 @@ body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-we
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
.ST5 {font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.number {color: #6897bb}
.string {color: #6a8759}
.ST1 {color: #ffc66d}
.ST2 {color: #9876aa}
.comment {color: #808080}
.whitespace {color: #505050}
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST4 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
@ -26,8 +20,8 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP2-chapter4_CalebFontenot/src/MP2_chapter4_CalebFontenot/BallControl.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> MP2_chapter4_CalebFontenot;
@ -44,30 +38,37 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> BallControl <span class="literal">extends</span> Application {
<span class="literal">private</span> <span class="literal">boolean</span> mouseFocus = <span class="literal">false</span>;
<span class="literal">private</span> <span class="literal">int</span> racketPosition = <span class="number">0</span>;
@Override
<span class="literal">public</span> <span class="literal">void</span> <span class="ST1">start</span>(Stage primaryStage) <span class="literal">throws</span> Exception {
<span class="literal">public</span> <span class="literal">void</span> start(Stage primaryStage) <span class="literal">throws</span> Exception
{
BouncingBall bouncingBall = <span class="literal">new</span> BouncingBall();
<span class="comment">// Create a scene and place it in the stage</span>
Scene scene = <span class="literal">new</span> Scene(bouncingBall, <span class="number">8</span><span class="number">00</span>, <span class="number">6</span><span class="number">00</span>);
Scene scene = <span class="literal">new</span> Scene(bouncingBall, <span class="number">800</span>, <span class="number">600</span>);
primaryStage.setTitle(<span class="string">&quot;</span><span class="string">Bouncing Ball Control</span><span class="string">&quot;</span>);
primaryStage.setScene(scene);
primaryStage.show();
bouncingBall.requestFocus();
bouncingBall.showInfoLabel();
bouncingBall.setOnMouseEntered(e
-&gt; {
mouseFocus = <span class="literal">true</span>;
bouncingBall.hideInfoLabel();
bouncingBall.play();
});
bouncingBall.setOnMouseExited(e -&gt; {
bouncingBall.showInfoLabel();
bouncingBall.pause();
mouseFocus = <span class="literal">false</span>;
});
bouncingBall.setOnMouseMoved(<span class="literal">new</span> EventHandler&lt;MouseEvent&gt;() {
@Override
<span class="literal">public</span> <span class="literal">void</span> <span class="ST1">handle</span>(MouseEvent event) {
<span class="literal">double</span> mouseX = event.getSceneX() - (bouncingBall.<span class="ST2">RACKET_LENGTH</span> / <span class="number">2</span>); <span class="comment">// set relative to center of racket</span>
<span class="literal">public</span> <span class="literal">void</span> handle(MouseEvent event)
{
<span class="literal">double</span> mouseX = event.getSceneX() - (bouncingBall.RACKET_LENGTH / <span class="number">2</span>); <span class="comment">// set relative to center of racket</span>
bouncingBall.moveRacket(mouseX);
}
@ -76,9 +77,23 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="comment">// Increase and decrease animation</span>
bouncingBall.setOnKeyPressed(e
-&gt; {
<span class="literal">if</span> (e.getCode() == KeyCode.<span class="ST3">UP</span>) {
<span class="literal">if</span> (e.getCode() == KeyCode.LEFT &amp;&amp; mouseFocus == <span class="literal">false</span>) {
bouncingBall.hideInfoLabel();
<span class="literal">if</span> (racketPosition &gt; <span class="number">0</span>) {
racketPosition = racketPosition - <span class="number">30</span>;
}
bouncingBall.moveRacket(racketPosition);
}
<span class="literal">if</span> (e.getCode() == KeyCode.RIGHT &amp;&amp; mouseFocus == <span class="literal">false</span>) {
bouncingBall.hideInfoLabel();
<span class="literal">if</span> (racketPosition &lt; bouncingBall.getWidth()) {
racketPosition = racketPosition + <span class="number">30</span>;
}
bouncingBall.moveRacket(racketPosition);
}
<span class="literal">if</span> (e.getCode() == KeyCode.UP) {
bouncingBall.increaseSpeed();
} <span class="literal">else</span> <span class="literal">if</span> (e.getCode() == KeyCode.<span class="ST3">DOWN</span>) {
} <span class="literal">else</span> <span class="literal">if</span> (e.getCode() == KeyCode.DOWN) {
bouncingBall.decreaseSpeed();
}
@ -86,8 +101,9 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">main</span>(String[] args) {
<span class="ST5">launch</span>(args);
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
launch(args);
}
}

@ -31,12 +31,13 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="literal">package</span> MP2_chapter4_CalebFontenot;
<span class="literal">import</span> java.io.File;
<span class="literal">import</span> java.util.ArrayList;
<span class="literal">import</span> java.util.List;
<span class="literal">import</span> javafx.animation.KeyFrame;
<span class="literal">import</span> javafx.animation.Timeline;
<span class="literal">import</span> javafx.beans.property.DoubleProperty;
<span class="literal">import</span> javafx.event.ActionEvent;
<span class="literal">import</span> javafx.event.EventHandler;
<span class="comment">import</span> <span class="comment">javafx</span><span class="comment">.</span><span class="comment">geometry</span><span class="comment">.</span><span class="comment">Pos</span><span class="comment">;</span>
<span class="literal">import</span> javafx.scene.control.Label;
<span class="literal">import</span> javafx.scene.layout.GridPane;
<span class="literal">import</span> javafx.scene.layout.Pane;
@ -53,7 +54,10 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> BouncingBall <span class="literal">extends</span> Pane {
<span class="literal">private</span> List&lt;MediaPlayer&gt; <span class="ST1">mediaPlayers</span> = <span class="literal">new</span> ArrayList&lt;&gt;();
GridPane <span class="ST1">textPane</span> = <span class="literal">new</span> GridPane();
<span class="literal">private</span> String <span class="ST1">currentlyPlaying</span>;
<span class="literal">private</span> <span class="literal">final</span> <span class="literal">int</span> <span class="ST1">COLLISION_COOLDOWN</span> = <span class="number">20</span>;
<span class="literal">private</span> <span class="literal">long</span> <span class="ST1">timeSinceLastCollisionEvent</span> = <span class="number">0</span>;
<span class="literal">final</span> <span class="literal">double</span> <span class="ST1">RACKET_LENGTH</span> = <span class="number">100</span>;
<span class="literal">final</span> <span class="literal">double</span> <span class="ST1">radius</span> = <span class="number">20</span>;
@ -66,8 +70,7 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="literal">private</span> Label <span class="ST1">ballCords</span> = <span class="literal">new</span> Label();
<span class="literal">private</span> Label <span class="ST1">playerScoreLabel</span> = <span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">Player Score: 0</span><span class="string">&quot;</span>);
<span class="literal">private</span> Label <span class="ST1">computerScoreLabel</span> = <span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">Computer Score: 0</span><span class="string">&quot;</span>);
<span class="literal">private</span> Label <span class="ST1">nowPlaying</span> = <span class="literal">new</span> Label();
<span class="literal">private</span> Timeline <span class="ST1">animation</span>;
@ -80,20 +83,32 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="ST1">textPane</span>.add(<span class="ST1">b</span><span class="ST1">allCords</span>, <span class="number">0</span>, <span class="number">1</span>);
<span class="ST1">textPane</span>.add(<span class="ST1">p</span><span class="ST1">layerScoreLabel</span>, <span class="number">0</span>, <span class="number">2</span>);
<span class="ST1">textPane</span>.add(<span class="ST1">c</span><span class="ST1">omputerScoreLabel</span>, <span class="number">0</span>, <span class="number">3</span>);
getChildren().addAll(<span class="ST1">c</span><span class="ST1">ircle</span>, <span class="ST1">r</span><span class="ST1">acket</span>, <span class="ST1">t</span><span class="ST1">extPane</span>, <span class="ST1">i</span><span class="ST1">nfoLabel</span>); <span class="comment">// Place a ball into this pane</span>
<span class="ST1">textPane</span>.add(<span class="ST1">n</span><span class="ST1">owPlaying</span>, <span class="number">0</span>, <span class="number">4</span>);
getChildren().addAll(<span class="ST1">c</span><span class="ST1">ircle</span>, <span class="ST1">r</span><span class="ST1">acket</span>, <span class="ST1">t</span><span class="ST1">extPane</span>); <span class="comment">// Place a ball into this pane</span>
<span class="ST1">racket</span>.relocate(<span class="number">0</span>, <span class="number">5</span><span class="number">80</span>);
<span class="ST1">infoLabel</span>.relocate(getHeight() / <span class="number">4.0</span>, getWidth() / <span class="number">2.0</span>);
playSound(<span class="string">&quot;</span><span class="string">bgm</span><span class="string">&quot;</span>);
<span class="comment">// Create an animation for moving the ball</span>
<span class="ST1">animation</span> = <span class="literal">new</span> Timeline(<span class="literal">new</span> KeyFrame(Duration.<span class="ST3">millis</span>(<span class="number">1</span>), <span class="literal">new</span> EventHandler&lt;ActionEvent&gt;() {
@Override
<span class="literal">public</span> <span class="literal">void</span> <span class="ST4">handle</span>(ActionEvent t) {
<span class="ST1">timeSinceLastCollisionEvent</span>++;
<span class="ST1">racketTime</span>.setText(<span class="string">&quot;</span><span class="string">Frames since last collision: </span><span class="string">&quot;</span> + <span class="ST1">timeSinceLastCollisionEvent</span>);
moveBall();
<span class="literal">if</span> (<span class="ST1">y</span> &gt;= (getHeight() - <span class="number">20</span>) &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="number">500</span>)) {
<span class="comment">// Process collisions</span>
<span class="literal">if</span> (<span class="ST1">y</span> &gt;= (getHeight() - <span class="number">20</span>) &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="ST1">COLLISION_COOLDOWN</span>)) {
<span class="ST1">timeSinceLastCollisionEvent</span> = <span class="number">0</span>;
playSound(<span class="string">&quot;</span><span class="string">collision</span><span class="string">&quot;</span>);
incrementComputerScore();
}
<span class="literal">if</span> ((<span class="ST1">x</span> &lt;= <span class="number">20</span> &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="ST1">COLLISION_COOLDOWN</span>)) || ((<span class="ST1">x</span> &gt;= getWidth() - <span class="number">20</span>) &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="ST1">COLLISION_COOLDOWN</span>))) {
<span class="ST1">timeSinceLastCollisionEvent</span> = <span class="number">0</span>;
playSound(<span class="string">&quot;</span><span class="string">collision</span><span class="string">&quot;</span>);
}
<span class="literal">if</span> (<span class="ST1">y</span> &lt;= <span class="number">20</span> &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="ST1">COLLISION_COOLDOWN</span>)) {
<span class="ST1">timeSinceLastCollisionEvent</span> = <span class="number">0</span>;
playSound(<span class="string">&quot;</span><span class="string">collision</span><span class="string">&quot;</span>);
}
}
})
);
@ -105,10 +120,11 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST4">processRacketCollision</span>() {
<span class="literal">boolean</span> racketCollision = <span class="ST1">racket</span>.getBoundsInParent().intersects(<span class="ST1">c</span><span class="ST1">ircle</span>.getBoundsInParent());
<span class="literal">if</span> (racketCollision &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="number">500</span>)) { <span class="comment">// This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles.</span>
<span class="literal">if</span> (racketCollision &amp;&amp; (<span class="ST1">timeSinceLastCollisionEvent</span> &gt; <span class="ST1">COLLISION_COOLDOWN</span>)) { <span class="comment">// This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles.</span>
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Racket collision detected!</span><span class="string">&quot;</span>);
<span class="ST1">timeSinceLastCollisionEvent</span> = <span class="number">0</span>;
incrementPlayerScore();
playSound(<span class="string">&quot;</span><span class="string">racket</span><span class="string">&quot;</span>);
<span class="literal">return</span> <span class="literal">true</span>;
} <span class="literal">else</span> {
<span class="literal">return</span> <span class="literal">false</span>;
@ -173,30 +189,88 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
<span class="literal">private</span> <span class="literal">void</span> <span class="ST4">incrementPlayerScore</span>() {
<span class="ST1">playerScoreLabel</span>.setText(<span class="string">&quot;</span><span class="string">Player score: </span><span class="string">&quot;</span> + ++<span class="ST1">playerScore</span>);
playSound();
}
<span class="literal">private</span> <span class="literal">void</span> <span class="ST4">incrementComputerScore</span>() {
<span class="ST1">computerScoreLabel</span>.setText(<span class="string">&quot;</span><span class="string">Computer score: </span><span class="string">&quot;</span> + ++<span class="ST1">computerScore</span>);
<span class="comment">//playSound();</span>
}
<span class="literal">private</span> <span class="literal">void</span> <span class="ST4">ballCoordsToLabel</span>() {
<span class="ST1">ballCords</span>.setText(<span class="string">&quot;</span><span class="string">Ball coords: </span><span class="string">&quot;</span> + <span class="ST1">x</span> + <span class="string">&quot;</span><span class="string">, </span><span class="string">&quot;</span> + <span class="ST1">y</span>);
}
<span class="literal">private</span> <span class="literal">void</span> <span class="ST4">playSound</span>() {
<span class="literal">private</span> <span class="literal">void</span> <span class="ST4">playSound</span>(String sampleType) {
<span class="literal">boolean</span> isSfx = <span class="literal">true</span>;
String sample = <span class="string">&quot;</span><span class="string">sound/sfx/Sample_00</span><span class="string">&quot;</span>;
<span class="literal">int</span> randInt = (<span class="literal">int</span>) (Math.<span class="ST3">random</span>() * <span class="number">2</span>);
String sample;
<span class="literal">if</span> (randInt == <span class="number">0</span>) {
sample = <span class="string">&quot;</span><span class="string">5</span><span class="string">&quot;</span>;
} <span class="literal">else</span> {
sample = <span class="string">&quot;</span><span class="string">7</span><span class="string">&quot;</span>;
<span class="literal">switch</span> (sampleType) {
<span class="literal">case</span> <span class="string">&quot;</span><span class="string">collision</span><span class="string">&quot;</span>:
randInt = (<span class="literal">int</span>) (Math.<span class="ST3">random</span>() * <span class="number">2</span>);
isSfx = <span class="literal">true</span>;
<span class="literal">switch</span> (randInt) {
<span class="literal">case</span> <span class="number">0</span>:
sample += <span class="string">&quot;</span><span class="string">05</span><span class="string">&quot;</span>;
<span class="literal">break</span>;
<span class="literal">case</span> <span class="number">1</span>:
sample += <span class="string">&quot;</span><span class="string">07</span><span class="string">&quot;</span>;
<span class="literal">break</span>;
}
<span class="literal">break</span>;
<span class="literal">case</span> <span class="string">&quot;</span><span class="string">racket</span><span class="string">&quot;</span>:
randInt = (<span class="literal">int</span>) (Math.<span class="ST3">random</span>() * <span class="number">2</span>);
isSfx = <span class="literal">true</span>;
<span class="literal">switch</span> (randInt) {
<span class="literal">case</span> <span class="number">0</span>:
sample += <span class="string">&quot;</span><span class="string">10</span><span class="string">&quot;</span>;
<span class="literal">break</span>;
<span class="literal">case</span> <span class="number">1</span>:
sample += <span class="string">&quot;</span><span class="string">12</span><span class="string">&quot;</span>;
<span class="literal">break</span>;
}
<span class="literal">break</span>;
<span class="literal">case</span> <span class="string">&quot;</span><span class="string">bgm</span><span class="string">&quot;</span>:
sample = <span class="string">&quot;</span><span class="string">sound/bgm/</span><span class="string">&quot;</span>;
randInt = (<span class="literal">int</span>) (Math.<span class="ST3">random</span>() * <span class="number">3</span>);
isSfx = <span class="literal">false</span>;
<span class="literal">switch</span> (randInt) {
<span class="literal">case</span> <span class="number">0</span>:
<span class="ST1">currentlyPlaying</span> = <span class="string">&quot;</span><span class="string">Caleb Fontenot - Blips</span><span class="string">&quot;</span>;
<span class="ST1">nowPlaying</span>.setText(<span class="string">&quot;</span><span class="string">Now playing: </span><span class="string">&quot;</span> + <span class="ST1">currentlyPlaying</span>);
<span class="literal">break</span>;
<span class="literal">case</span> <span class="number">1</span>:
<span class="ST1">currentlyPlaying</span> = <span class="string">&quot;</span><span class="string">Caleb Fontenot - DEAL WITH IT</span><span class="string">&quot;</span>;
<span class="ST1">nowPlaying</span>.setText(<span class="string">&quot;</span><span class="string">Now playing: </span><span class="string">&quot;</span> + <span class="ST1">currentlyPlaying</span>);
<span class="literal">break</span>;
<span class="literal">case</span> <span class="number">2</span>:
<span class="ST1">currentlyPlaying</span> = <span class="string">&quot;</span><span class="string">Caleb Fontenot - Tomodachi Moment</span><span class="string">&quot;</span>;
<span class="ST1">nowPlaying</span>.setText(<span class="string">&quot;</span><span class="string">Now playing: </span><span class="string">&quot;</span> + <span class="ST1">currentlyPlaying</span>);
<span class="literal">break</span>;
}
sample += <span class="ST1">currentlyPlaying</span>;
<span class="literal">break</span>;
}
Media sound = <span class="literal">new</span> Media(<span class="literal">n</span><span class="literal">ew</span> File(<span class="string">&quot;</span><span class="string">sound/Sample_000</span><span class="string">&quot;</span>+sample+<span class="string">&quot;</span><span class="string">.wav</span><span class="string">&quot;</span>).toURI().toString());
Media sound = <span class="literal">new</span> Media(<span class="literal">n</span><span class="literal">ew</span> File(sample + <span class="string">&quot;</span><span class="string">.wav</span><span class="string">&quot;</span>).toURI().toString());
MediaPlayer mediaPlayer = <span class="literal">new</span> MediaPlayer(sound);
mediaPlayer.setStartTime(Duration.<span class="ST2">ZERO</span>);
mediaPlayer.setAutoPlay(<span class="literal">t</span><span class="literal">rue</span>);
<span class="comment">// If we&#39;re playing BGM, lower the volume a little</span>
<span class="literal">if</span> (!isSfx) {
mediaPlayer.setVolume(<span class="number">0</span><span class="number">.6</span>);
mediaPlayer.setCycleCount(MediaPlayer.<span class="ST2">INDEFINITE</span>);
}
mediaPlayer.play();
<span class="comment">//mediaPlayer.setOnEndOfMedia();</span>
<span class="ST1">mediaPlayers</span>.add(mediaPlayer); <span class="comment">// Prevent the JVM&#39;s GC from deleting our media player if there&#39;s already one running</span>
<span class="comment">// Free the media player when it has finished playing a sound.</span>
mediaPlayer.setOnEndOfMedia(<span class="literal">new</span> Runnable() {
@Override
<span class="literal">public</span> <span class="literal">void</span> <span class="ST4">run</span>() {
<span class="comment">//System.out.println(&quot;I&#39;m done playing sound! Please take me to the ether, Java GC!&quot;);</span>
mediaPlayer.stop();
mediaPlayer.dispose();
<span class="ST1">mediaPlayers</span>.remove(mediaPlayer);
}
});
}
}

@ -120,43 +120,7 @@ is divided into following sections:
<property name="module.name" value=""/>
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property,-init-modules-supported" name="-do-init">
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
<condition property="platform.javac" value="${platform.home}/bin/javac">
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
</condition>
<property name="platform.javac" value="${platform.javac.tmp}"/>
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
<condition property="platform.java" value="${platform.home}/bin/java">
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
</condition>
<property name="platform.java" value="${platform.java.tmp}"/>
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
</condition>
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
<condition property="platform.invalid" value="true">
<or>
<contains string="${platform.javac}" substring="$${platforms."/>
<contains string="${platform.java}" substring="$${platforms."/>
<contains string="${platform.javadoc}" substring="$${platforms."/>
</or>
</condition>
<fail unless="platform.home">Must set platform.home</fail>
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
<fail unless="platform.java">Must set platform.java</fail>
<fail unless="platform.javac">Must set platform.javac</fail>
<fail if="platform.invalid">
The J2SE Platform is not correctly set up.
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
Either open the project in the IDE and setup the Platform with the same name or add it manually.
For example like this:
ant -Duser.properties.file=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
</fail>
<property name="platform.java" value="${java.home}/bin/java"/>
<available file="${manifest.file}" property="manifest.available"/>
<condition property="splashscreen.available">
<and>
@ -279,6 +243,20 @@ is divided into following sections:
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
<isset property="profile.available"/>
</condition>
<condition else="false" property="jdkBug6558476">
<and>
<matches pattern="1\.[56]" string="${java.specification.version}"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
<condition else="false" property="javac.fork">
<or>
<istrue value="${jdkBug6558476}"/>
<istrue value="${javac.external.vm}"/>
</or>
</condition>
<property name="jar.index" value="false"/>
<property name="jar.index.metainf" value="${jar.index}"/>
<property name="copylibs.rebase" value="true"/>
@ -366,7 +344,7 @@ is divided into following sections:
</path>
</resourcecount>
</condition>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -417,7 +395,7 @@ is divided into following sections:
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<mkdir dir="@{apgeneratedsrcdir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -459,7 +437,7 @@ is divided into following sections:
<sequential>
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -538,7 +516,7 @@ is divided into following sections:
<element name="customizePrototype" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -566,7 +544,7 @@ is divided into following sections:
<element name="customizePrototype" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -642,7 +620,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MP2-chapter4_CalebFontenot" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="MP2-chapter4_CalebFontenot" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@ -873,9 +851,6 @@ is divided into following sections:
<classpath>
<path path="@{classpath}"/>
</classpath>
<bootclasspath>
<path path="${platform.bootcp}"/>
</bootclasspath>
</nbjpdastart>
</sequential>
</macrodef>
@ -925,7 +900,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}" module="@{modulename}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
<classpath>
<path path="@{classpath}"/>
</classpath>
@ -959,7 +934,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<classpath>
<path path="@{classpath}"/>
</classpath>
@ -991,7 +966,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
@ -1225,7 +1200,7 @@ is divided into following sections:
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
@ -1327,8 +1302,8 @@ is divided into following sections:
<isset property="main.class.available"/>
</and>
</condition>
<property name="platform.jlink" value="${platform.home}/bin/jlink"/>
<property name="jlink.systemmodules.internal" value="${platform.home}/jmods"/>
<property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
<property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
<exec executable="${platform.jlink}">
<arg value="--module-path"/>
<arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.jar}"/>
@ -1521,19 +1496,16 @@ is divided into following sections:
</not>
</and>
</condition>
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
<arg value="-version"/>
</exec>
<condition else="" property="bug5101868workaround" value="*.java">
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
</condition>
<condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
<and>
<isset property="javadoc.html5"/>
<available file="${platform.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
<available file="${jdk.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
</and>
</condition>
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<classpath>
<path path="${javac.classpath}"/>
</classpath>

@ -3,6 +3,6 @@ build.xml.script.CRC32=f4beac8b
build.xml.stylesheet.CRC32=f85dc8f2@1.107.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=1d3703fe
nbproject/build-impl.xml.script.CRC32=4d538bea
nbproject/build-impl.xml.data.CRC32=14971581
nbproject/build-impl.xml.script.CRC32=e3cc13c1
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48

@ -107,7 +107,7 @@ manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=JDK_1.8
platform.active=default_platform
run.classpath=\
${dist.jar}:\
${javac.classpath}:\

@ -14,7 +14,6 @@
</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>MP2-chapter4_CalebFontenot</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>

@ -5,12 +5,14 @@
package MP2_chapter4_CalebFontenot;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
@ -27,7 +29,9 @@ import javafx.util.Duration;
*/
public class BouncingBall extends Pane {
private List<MediaPlayer> mediaPlayers = new ArrayList<>();
GridPane textPane = new GridPane();
private String currentlyPlaying;
private final int COLLISION_COOLDOWN = 20;
private long timeSinceLastCollisionEvent = 0;
final double RACKET_LENGTH = 100;
@ -41,27 +45,33 @@ public class BouncingBall extends Pane {
private Label ballCords = new Label();
private Label playerScoreLabel = new Label("Player Score: 0");
private Label computerScoreLabel = new Label("Computer Score: 0");
private Label nowPlaying = new Label();
private Button restartBgm = new Button("Restart BGM");
private Timeline animation;
private int computerScore, playerScore = 0;
public BouncingBall()
{
public BouncingBall() {
restartBgm.setOnMouseClicked(e -> {
playSound("bgm");
});
circle.setFill(Color.RED); // Set ball color
racket.setFill(Color.BLUE);
textPane.add(racketTime, 0, 0);
textPane.add(ballCords, 0, 1);
textPane.add(playerScoreLabel, 0, 2);
textPane.add(computerScoreLabel, 0, 3);
textPane.add(nowPlaying, 0, 4);
textPane.add(restartBgm, 0, 5);
getChildren().addAll(circle, racket, textPane); // Place a ball into this pane
racket.relocate(0, 580);
playSound("bgm");
// Create an animation for moving the ball
animation = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t)
{
public void handle(ActionEvent t) {
timeSinceLastCollisionEvent++;
racketTime.setText("Frames since last collision: " + timeSinceLastCollisionEvent);
moveBall();
@ -87,8 +97,7 @@ public class BouncingBall extends Pane {
}
private boolean processRacketCollision()
{
private boolean processRacketCollision() {
boolean racketCollision = racket.getBoundsInParent().intersects(circle.getBoundsInParent());
if (racketCollision && (timeSinceLastCollisionEvent > COLLISION_COOLDOWN)) { // This is second condition is a cooldown. It prevents odd behavior happening with the ball and the racket if the racket hits the ball at certain angles.
@ -102,8 +111,7 @@ public class BouncingBall extends Pane {
}
}
private void moveBall()
{
private void moveBall() {
// Check boundaries
if (x < radius || x > getWidth() - radius) {
@ -121,40 +129,33 @@ public class BouncingBall extends Pane {
ballCoordsToLabel();
}
public void play()
{
public void play() {
animation.play();
}
public void pause()
{
public void pause() {
animation.pause();
}
public void increaseSpeed()
{
public void increaseSpeed() {
animation.setRate(animation.getRate() * 1.5);
System.out.println(animation.getRate());
}
public void decreaseSpeed()
{
public void decreaseSpeed() {
animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
System.out.println(animation.getRate());
}
public DoubleProperty rateProperty()
{
public DoubleProperty rateProperty() {
return animation.rateProperty();
}
public void moveRacket(double x)
{
public void moveRacket(double x) {
racket.relocate(x, 580);
}
public void showInfoLabel()
{
public void showInfoLabel() {
double paneHeight = getHeight();
double paneWidth = getWidth();
getChildren().add(infoLabel);
@ -162,59 +163,93 @@ public class BouncingBall extends Pane {
infoLabel.relocate(paneWidth / 4.0, paneHeight / 2.0);
}
public void hideInfoLabel()
{
public void hideInfoLabel() {
getChildren().remove(infoLabel);
}
private void incrementPlayerScore()
{
private void incrementPlayerScore() {
playerScoreLabel.setText("Player score: " + ++playerScore);
}
private void incrementComputerScore()
{
private void incrementComputerScore() {
computerScoreLabel.setText("Computer score: " + ++computerScore);
}
private void ballCoordsToLabel()
{
private void ballCoordsToLabel() {
ballCords.setText("Ball coords: " + x + ", " + y);
}
private void playSound(String sampleType)
{
String sample = "";
private void playSound(String sampleType) {
boolean isSfx = true;
String sample = "sound/sfx/Sample_00";
int randInt = (int) (Math.random() * 2);
switch (sampleType) {
case "collision":
randInt = (int) (Math.random() * 2);
isSfx = true;
switch (randInt) {
case 0:
sample = "05";
sample += "05";
break;
case 1:
sample = "07";
sample += "07";
break;
}
break;
case "racket":
randInt = (int) (Math.random() * 2);
isSfx = true;
switch (randInt) {
case 0:
sample = "10";
sample += "10";
break;
case 1:
sample = "12";
sample += "12";
break;
}
break;
case "bgm":
sample = "sound/bgm/";
randInt = (int) (Math.random() * 3);
isSfx = false;
switch (randInt) {
case 0:
currentlyPlaying = "Caleb Fontenot - Blips";
nowPlaying.setText("Now playing: " + currentlyPlaying);
break;
case 1:
currentlyPlaying = "Caleb Fontenot - DEAL WITH IT";
nowPlaying.setText("Now playing: " + currentlyPlaying);
break;
case 2:
currentlyPlaying = "Caleb Fontenot - Tomodachi Moment";
nowPlaying.setText("Now playing: " + currentlyPlaying);
break;
}
sample += currentlyPlaying;
break;
}
Media sound = new Media(new File("sound/Sample_00" + sample + ".wav").toURI().toString());
Media sound = new Media(new File(sample + ".wav").toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(sound);
mediaPlayer.setStartTime(Duration.ZERO);
mediaPlayer.setAutoPlay(true);
// If we're playing BGM, lower the volume a little
if (!isSfx) {
mediaPlayer.setVolume(0.6);
mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
}
mediaPlayer.play();
//mediaPlayer.setOnEndOfMedia();
mediaPlayers.add(mediaPlayer); // Prevent the JVM's GC from deleting our media player if there's already one running
// Free the media player when it has finished playing a sound.
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
//System.out.println("I'm done playing sound! Please take me to the ether, Java GC!");
mediaPlayer.stop();
mediaPlayer.dispose();
mediaPlayers.remove(mediaPlayer);
}
});
}
}

@ -0,0 +1,26 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package MP2_chapter4_CalebFontenot;
import javafx.scene.media.MediaPlayer;
/**
*
* @author caleb
*/
public class MediaType {
private MediaPlayer mediaPlayer;
private boolean isBgm;
public MediaType(MediaPlayer mediaPlayer, boolean isBgm) {
this.mediaPlayer = mediaPlayer;
this.isBgm = isBgm;
}
public boolean isIsBgm() {
return isBgm;
}
}

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?><!-- You may freely edit this file. See commented blocks below for --><!-- some examples of how to customize the build. --><!-- (If you delete it and reopen the project it will be recreated.) --><!-- By default, only the Clean and Build commands use this build script. --><project name="Lab1FX_Stelly" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
<description>Builds, tests, and runs the project Lab1FX_Stelly.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. Those of them relevant for JavaFX project are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-jfx-jar: called before FX SDK specific <fx:jar> task
-post-jfx-jar: called after FX SDK specific <fx:jar> task
-pre-jfx-deploy: called before FX SDK specific <fx:deploy> task
-post-jfx-deploy: called after FX SDK specific <fx:deploy> task
-pre-jfx-native: called just after -pre-jfx-deploy if <fx:deploy> runs in native packaging mode
-post-jfx-native: called just after -post-jfx-deploy if <fx:deploy> runs in native packaging mode
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting a HTML postprocessor after javaFX SDK deployment:
<target name="-post-jfx-deploy">
<basename property="jfx.deployment.base" file="${jfx.deployment.jar}" suffix=".jar"/>
<property name="jfx.deployment.html" location="${jfx.deployment.dir}${file.separator}${jfx.deployment.base}.html"/>
<custompostprocess>
<fileset dir="${jfx.deployment.html}"/>
</custompostprocess>
</target>
Example of calling an Ant task from JavaFX SDK. Note that access to JavaFX SDK Ant tasks must be
initialized; to ensure this is done add the dependence on -check-jfx-sdk-version target:
<target name="-post-jfx-jar" depends="-check-jfx-sdk-version">
<echo message="Calling jar task from JavaFX SDK"/>
<fx:jar ...>
...
</fx:jar>
</target>
For more details about JavaFX SDK Ant tasks go to
http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
For list of available properties check the files
nbproject/build-impl.xml and nbproject/jfx-impl.xml.
-->
</project>

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

@ -0,0 +1,2 @@
# Do not modify this property in this configuration. It can be re-generated.
$label=Run as WebStart

@ -0,0 +1,2 @@
# Do not modify this property in this configuration. It can be re-generated.
$label=Run in Browser

@ -0,0 +1,8 @@
build.xml.data.CRC32=5221739b
build.xml.script.CRC32=e15c08d4
build.xml.stylesheet.CRC32=f85dc8f2@1.103.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=811c71b0
nbproject/build-impl.xml.script.CRC32=98d2f61a
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.107.0.48

File diff suppressed because it is too large Load Diff

@ -0,0 +1,134 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=MP2FX_Stelly
application.vendor=asdv
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
compile.on.save=true
compile.on.save.unsupported.javafx=true
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/MP2FX_Stelly.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects
jar.archive.disabled=true
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
javafx.application.implementation.version=1.0
javafx.binarycss=false
javafx.deploy.adddesktopshortcut=false
javafx.deploy.addstartmenushortcut=false
javafx.deploy.allowoffline=true
# If true, application update mode is set to 'background', if false, update mode is set to 'eager'
javafx.deploy.backgroundupdate=false
javafx.deploy.disable.proxy=false
javafx.deploy.embedJNLP=true
javafx.deploy.includeDT=true
javafx.deploy.installpermanently=false
javafx.deploy.permissionselevated=false
# Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs)
javafx.disable.concurrent.runs=false
# Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project
javafx.enable.concurrent.external.runs=false
# This is a JavaFX project
javafx.enabled=true
javafx.fallback.class=com.javafx.main.NoJavaFXFallback
# Main class for JavaFX
javafx.main.class=anim.Tennis
javafx.preloader.class=
# This project does not use Preloader
javafx.preloader.enabled=false
javafx.preloader.jar.filename=
javafx.preloader.jar.path=
javafx.preloader.project.path=
javafx.preloader.type=none
# Set true for GlassFish only. Rebases manifest classpaths of JARs in lib dir. Not usable with signed JARs.
javafx.rebase.libs=false
javafx.run.height=600
javafx.run.width=800
javafx.signing.blob=false
javafx.signing.enabled=false
javafx.signing.type=notsigned
jlink.launcher=false
jlink.launcher.name=MP2FX_Stelly
# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects
jnlp.enabled=false
# Main class for Java launcher
main.class=com.javafx.main.Main
# For improved security specify narrower Codebase manifest attribute to prevent RIAs from being repurposed
manifest.custom.codebase=*
# Specify Permissions manifest attribute to override default (choices: sandbox, all-permissions)
manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
native.bundling.enabled=false
no.dependencies=true
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1">
<extension file="jfx-impl.xml" id="jfx3">
<dependency dependsOn="-jfx-copylibs" target="-post-jar"/>
<dependency dependsOn="-rebase-libs" target="-post-jar"/>
<dependency dependsOn="jfx-deployment" target="-post-jar"/>
<dependency dependsOn="jar" target="debug"/>
<dependency dependsOn="jar" target="profile"/>
<dependency dependsOn="jar" target="run"/>
</extension>
</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>MP2FX_Stelly</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<libraries xmlns="http://www.netbeans.org/ns/ant-project-libraries/1">
<definitions>C:\Users\ethan\Documents\NetBeansProjects\JavaLibraryASDV\nblibraries.properties</definitions>
</libraries>
</configuration>
</project>

@ -0,0 +1,160 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package anim;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
/**
*
* @author asdv
*/
public class BouncingBall extends Pane
{
public int pScore = 0;
public int cScore = 0;
GridPane textDisplay = new GridPane();
Rectangle racket = new Rectangle();
public final double radius = 10; // ball size 40
private double x = radius, y = radius; // coordinates of ball
private double dx = 1, dy = 1; // direction of the ball
private Circle circle = new Circle(x, y, radius); // her majesty, the ball
private Timeline animation; // animate the ball
private Label playerScore = new Label("Your Score: 0");
private Label compScore = new Label("Computer Score: 0");
public BouncingBall()
{
racket.setWidth(70);
racket.setHeight(20);
racket.relocate(0, 580);
textDisplay.add(playerScore, 0, 0);
textDisplay.add(compScore, 0, 1);
circle.setFill(Color.BROWN);
getChildren().addAll(circle, racket, textDisplay);
animation = new Timeline(
new KeyFrame(Duration.millis(50), (ActionEvent event)
->
{
moveBall();
if (y >= (getHeight() - 20))
{
boolean intersected = intersection();
if (intersected && circle.getCenterX() <= racket.getX() / 2)
{
System.out.println("Intersected.");
dx *= -1;
dy *= -1;
playerScored();
}
else
{
if (intersected && circle.getCenterX() >= racket.getX() / 2)
{
playerScored();
dy *= -1;
}
else
{
if (y >= (getHeight() - 40))
{
computerScored();
dy *= -1;
}
}
}
}
}));
animation.setCycleCount(Timeline.INDEFINITE);
animation.setRate(animation.getRate() * 20);
animation.play();
}
private void moveBall()
{
if (x < radius || x > getWidth() - radius)
{
dx *= -1;
}
if (y < radius || y > getHeight() - radius)
{
dy *= -1;
}
x += dx;
y += dy;
circle.setCenterX(x);
circle.setCenterY(y);
}
public void playerScored()
{
playerScore.setText("Your Score: " + (++this.pScore));
}
public void computerScored()
{
compScore.setText("Computer Score: " + (++this.cScore));
}
public boolean intersection()
{
boolean intersected = racket.getBoundsInParent().intersects(circle.getBoundsInParent());
if (intersected)
{
return true;
}
else
{
return false;
}
}
public void moveRacket(double x)
{
racket.relocate(x, 580);
}
public void play()
{
animation.play();
}
public void pause()
{
animation.pause();
}
public void increaseSpeed()
{
animation.setRate(animation.getRate() * 1.5);
}
public void decreaseSpeed()
{
animation.setRate(animation.getRate() * 1.5 > 0 ? animation.getRate() / 1.5 : 0);
}
public DoubleProperty rateProperty()
{
return animation.rateProperty();
}
}

@ -0,0 +1,65 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package anim;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseEvent;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
*
* @author asdv
*/
public class Tennis extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
BouncingBall bouncingBall = new BouncingBall();
Scene scene = new Scene(bouncingBall, 800, 600);
primaryStage.setTitle("Play Tennis");
primaryStage.setScene(scene);
primaryStage.show();
bouncingBall.requestFocus();
bouncingBall.setOnMousePressed((MouseEvent event) ->
{
bouncingBall.pause();
});
bouncingBall.setOnMouseReleased((MouseEvent event) ->
{
bouncingBall.play();
});
bouncingBall.setOnKeyPressed(e ->
{
if(e.getCode() == KeyCode.UP)
{
bouncingBall.increaseSpeed();
}
else if(e.getCode() == KeyCode.DOWN)
{
bouncingBall.decreaseSpeed();
}
});
bouncingBall.setOnMouseMoved((MouseEvent event) ->
{
bouncingBall.moveRacket(event.getSceneX() - bouncingBall.racket.getWidth() / 2);
});
}
public static void main(String[] args)
{
launch(args);
}
}