88 lines
5.3 KiB
HTML
88 lines
5.3 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Checkerboard.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}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
|
.ST2 {color: #ffc66d}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
|
|
.ST4 {color: #ffc66d; font-family: monospace; font-style: italic}
|
|
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
|
|
.ST0 {color: #287bde}
|
|
.literal {color: #cc7832}
|
|
.ST5 {font-family: monospace; font-style: italic}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/JavaFX_CalebFontenot/src/javafx_calebfontenot/Checkerboard.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"> */</span>
|
|
<span class="literal">package</span> javafx_calebfontenot;
|
|
|
|
<span class="literal">import</span> javafx.application.Application;
|
|
<span class="literal">import</span> <span class="literal">static</span> javafx.application.Application.launch;
|
|
<span class="literal">import</span> javafx.scene.Scene;
|
|
<span class="literal">import</span> javafx.scene.layout.Pane;
|
|
<span class="literal">import</span> javafx.scene.paint.Color;
|
|
<span class="literal">import</span> javafx.scene.shape.Rectangle;
|
|
<span class="literal">import</span> javafx.stage.Stage;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> Checkerboard <span class="literal">extends</span> Application {
|
|
|
|
@Override
|
|
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">start</span>(Stage primaryStage) <span class="literal">throws</span> Exception
|
|
{
|
|
Pane pane = <span class="literal">new</span> Pane(); <span class="comment">// Create a pane object</span>
|
|
Scene scene = <span class="literal">new</span> Scene(pane, <span class="number">8</span><span class="number">00</span>, <span class="number">8</span><span class="number">00</span>); <span class="comment">// Create a scene object</span>
|
|
primaryStage.setScene(scene); <span class="comment">// Set the stage scene to the scene object</span>
|
|
primaryStage.show(); <span class="comment">// Make the window display on the screen</span>
|
|
Rectangle[][] r = <span class="literal">new</span> Rectangle[<span class="number">8</span>][<span class="number">8</span>];
|
|
<span class="comment">//Fill array with rectangle objects.</span>
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; ++i) {
|
|
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < <span class="number">8</span>; ++j) {
|
|
r[i][j] = <span class="literal">new</span> Rectangle();
|
|
}
|
|
}
|
|
<span class="literal">int</span> j = <span class="number">0</span>;
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="number">8</span>; ++i) {
|
|
<span class="literal">for</span> (j = <span class="number">0</span>; j < <span class="number">8</span>; ++j) {
|
|
r[i][j].setWidth(<span class="number">8</span><span class="number">0</span>);
|
|
r[i][j].setHeight(<span class="number">8</span><span class="number">0</span>);
|
|
<span class="literal">if</span> (j > <span class="number">0</span>) {
|
|
r[i][j].setX(r[i][j - <span class="number">1</span>].getX() + <span class="number">75</span>);
|
|
}
|
|
<span class="literal">if</span> ((i + j) % <span class="number">2</span> == <span class="number">0</span>) {
|
|
r[i][j].setFill(Color.<span class="ST3">RED</span>);
|
|
} <span class="literal">else</span> {
|
|
r[i][j].setFill(Color.<span class="ST3">BLACK</span>);
|
|
}
|
|
r[i][j].setY((i + <span class="number">1</span>) * <span class="number">75</span>);
|
|
pane.getChildren().add(r[i][j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
<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);
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|