ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/PrintedHTMLs/BallControl.html
2023-09-01 00:14:38 -05:00

85 lines
3.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>BallControl.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
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}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab3_CalebFontenot/src/lab3_calebfontenot/BallControl.java</td></tr></table>
<pre>
<span class="comment">/*</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> lab3_calebfontenot;
<span class="literal">import</span> javafx.application.Application;
<span class="literal">import</span> javafx.event.EventHandler;
<span class="literal">import</span> javafx.scene.Scene;
<span class="literal">import</span> javafx.scene.input.KeyCode;
<span class="literal">import</span> javafx.scene.input.MouseEvent;
<span class="literal">import</span> javafx.stage.Stage;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> BallControl <span class="literal">extends</span> Application {
@Override
<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">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.setOnMousePressed(<span class="literal">new</span> EventHandler&lt;MouseEvent&gt;() {
@Override
<span class="literal">public</span> <span class="literal">void</span> handle(MouseEvent event) {
bouncingBall.pause();
}
});
bouncingBall.setOnMouseReleased(e
-&gt; {
bouncingBall.play();
});
<span class="comment">// Increase and decrease animation</span>
bouncingBall.setOnKeyPressed (e
-&gt; {
<span class="literal">if</span> (e.getCode() == KeyCode.UP) {
bouncingBall.increaseSpeed();
} <span class="literal">else</span> <span class="literal">if</span> (e.getCode() == KeyCode.DOWN) {
bouncingBall.decreaseSpeed();
}
}
);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
launch(args);
}
}
</pre></body>
</html>