ASDV-Java/Semester 3/Assignments/lab2_FX2_F22_part1/Printed HTMLs/ShowGridPane2.html

104 lines
7.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ShowGridPane2.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}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.number {color: #6897bb}
.string {color: #6a8759}
.ST1 {color: #ffc66d}
.comment {color: #808080}
.whitespace {color: #505050}
.ST2 {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>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/lab2_FX2_F22_part1/src/lab2_fx2_f22_part1/ShowGridPane2.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> lab2_fx2_f22_part1;
<span class="literal">import</span> javafx.application.Application;
<span class="literal">import</span> javafx.event.ActionEvent;
<span class="literal">import</span> javafx.event.EventHandler;
<span class="literal">import</span> javafx.geometry.HPos;
<span class="literal">import</span> javafx.geometry.Insets;
<span class="literal">import</span> javafx.geometry.Pos;
<span class="literal">import</span> javafx.scene.Scene;
<span class="literal">import</span> javafx.scene.control.Button;
<span class="literal">import</span> javafx.scene.control.Label;
<span class="literal">import</span> javafx.scene.control.TextField;
<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> ShowGridPane2 <span class="literal">extends</span> Application {
@Override <span class="comment">// Override the start method in the Application class</span>
<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="comment">// Create a pane and set its properties</span>
GridPane pane = <span class="literal">new</span> GridPane();
pane.setAlignment(Pos.<span class="ST2">CENTER</span>);
pane.setPadding(<span class="literal">new</span> Insets(<span class="number">1</span><span class="number">1.5</span>, <span class="number">1</span><span class="number">2.5</span>, <span class="number">1</span><span class="number">3.5</span>, <span class="number">1</span><span class="number">4.5</span>));
pane.setHgap(<span class="number">5</span><span class="number">.5</span>);
pane.setVgap(<span class="number">5</span><span class="number">.5</span>);
<span class="comment">// Place nodes in the pane</span>
pane.add(<span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">First Name:</span><span class="string">&quot;</span>), <span class="number">0</span>, <span class="number">0</span>);
TextField fName = <span class="literal">new</span> TextField();
pane.add(fName, <span class="number">1</span>, <span class="number">0</span>);
pane.add(<span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">MI:</span><span class="string">&quot;</span>), <span class="number">0</span>, <span class="number">1</span>);
TextField mInit = <span class="literal">new</span> TextField();
pane.add(mInit, <span class="number">1</span>, <span class="number">1</span>);
pane.add(<span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">Last Name:</span><span class="string">&quot;</span>), <span class="number">0</span>, <span class="number">2</span>);
TextField lName = <span class="literal">new</span> TextField();
pane.add(lName, <span class="number">1</span>, <span class="number">2</span>);
pane.add(<span class="literal">new</span> Label(<span class="string">&quot;</span><span class="string">Gender, M/F/nb:</span><span class="string">&quot;</span>), <span class="number">0</span>, <span class="number">3</span>);
TextField gender = <span class="literal">new</span> TextField();
gender.setMaxSize(<span class="number">4</span><span class="number">0</span>, <span class="number">2</span><span class="number">0</span>);
pane.add(gender, <span class="number">1</span>, <span class="number">3</span>);
Button button = <span class="literal">new</span> Button(<span class="string">&quot;</span><span class="string">Add Person</span><span class="string">&quot;</span>);
EventHandler eventHnadler = <span class="literal">new</span> EventHandler&lt;ActionEvent&gt;(){
@Override
<span class="literal">public</span> <span class="literal">void</span> <span class="ST1">handle</span>(ActionEvent t)
{
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Added person:</span><span class="string">&quot;</span>);
System.<span class="ST2">out</span>.println(fName.getText() + <span class="string">&quot;</span> <span class="string">&quot;</span> + mInit.getText() + <span class="string">&quot;</span> <span class="string">&quot;</span> + lName.getText());
System.<span class="ST2">out</span>.println(<span class="string">&quot;</span><span class="string">Gender: </span><span class="string">&quot;</span> + gender.getText());
}
};
button.setOnAction(eventHnadler);
pane.add(button, <span class="number">0</span>, <span class="number">4</span>);
GridPane.<span class="ST3">setHalignment</span>(button, HPos.<span class="ST2">LEFT</span>);
<span class="comment">// Create a scene and place it in the stage</span>
Scene scene = <span class="literal">new</span> Scene(pane);
primaryStage.setTitle(<span class="string">&quot;</span><span class="string">ShowGridPane</span><span class="string">&quot;</span>);
primaryStage.setScene(scene);
primaryStage.show();
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST4">main</span>(String[] args) {
<span class="ST3">launch</span>(args);
}
}
</pre></body>
</html>