2023-09-01 00:14:38 -05:00

76 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ThreeRandomCards.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}
.string {color: #6a8759}
.number {color: #6897bb}
.comment {color: #808080}
.whitespace {color: #505050}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/MP1_FX_CalebFontenot/src/mp1_fx_calebfontenot/ThreeRandomCards.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> mp1_fx_calebfontenot;
<span class="literal">import</span> javafx.application.Application;
<span class="literal">import</span> javafx.geometry.Pos;
<span class="literal">import</span> javafx.scene.Scene;
<span class="literal">import</span> javafx.scene.image.Image;
<span class="literal">import</span> javafx.scene.image.ImageView;
<span class="literal">import</span> javafx.scene.layout.GridPane;
<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> ThreeRandomCards <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 {
GridPane pane = <span class="literal">new</span> GridPane();
pane.setOnMouseClicked(e -&gt; {
addCards(pane);
});
System.out.println(<span class="string">&quot;</span><span class="string">Created GridPane. Executing addCards() to add cards to GridPane.</span><span class="string">&quot;</span>);
addCards(pane);
Scene scene = <span class="literal">new</span> Scene(pane);
primaryStage.setTitle(<span class="string">&quot;</span><span class="string">Three Random Cards</span><span class="string">&quot;</span>);
primaryStage.setScene(scene);
primaryStage.show();
}
<span class="literal">public</span> <span class="literal">void</span> addCards(GridPane imagePane) {
System.out.println(<span class="string">&quot;</span><span class="string">addCards() executed!</span><span class="string">&quot;</span>);
imagePane.setAlignment(Pos.CENTER);
imagePane.setHgap(<span class="number">5</span>);
imagePane.setVgap(<span class="number">5</span>);
<span class="comment">// Define Image objects</span>
<span class="literal">int</span> rand = <span class="number">0</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; <span class="number">3</span>; i++) {
rand = (<span class="literal">int</span>) ((Math.random() * <span class="number">54</span>) + <span class="number">1</span>);
imagePane.add(<span class="literal">new</span> ImageView(<span class="literal">new</span> Image(<span class="string">&quot;</span><span class="string">https://files.calebfontenot.com/image/card/</span><span class="string">&quot;</span> + rand + <span class="string">&quot;</span><span class="string">.png</span><span class="string">&quot;</span>)), i, <span class="number">0</span>);
System.out.println(<span class="string">&quot;</span><span class="string">added image </span><span class="string">&quot;</span> + rand + <span class="string">&quot;</span><span class="string"> to the imagePane.</span><span class="string">&quot;</span>);
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
launch(args);
}
}
</pre></body>
</html>