*internal screaming*

master
Caleb Fontenot 2023-10-21 00:37:53 +07:00
parent 68440bd402
commit 01f7640bdd
62 changed files with 5125 additions and 84 deletions

5
.gitignore vendored

@ -183,3 +183,8 @@
/Semester 3/Assignments/JavaFXBallsWithComparator/target/
/Semester 3/Assignments/MP4_CalebFontenot/target/
/Semester 3/MP5-Binary-Files_CalebFontenot/target/
/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot2/target/
/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot2/MP5-Binary-Files_CalebFontenot/build/
/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot2/MP5-Binary-Files_CalebFontenot/nbproject/private/
/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/build/
/Semester 3/Assignments/MP5-Binary-Files_CalebFontenot/nbproject/private/

@ -22,8 +22,8 @@ public class Database
String databaseName = "suppliers_parts_23";
String userName = "admin";
String password = "RangerDog01!";
String URL2 = "com.mysql.jdbc.Driver";
//String URL2 = "com.mysql.cj.jdbc.Driver";
//String URL2 = "com.mysql.jdbc.Driver";
String URL2 = "com.mysql.cj.jdbc.Driver";
Connection con = null;
try
{// Load Sun's jdbc driver
@ -37,7 +37,8 @@ public class Database
return null;
}
String ip = "localhost"; //internet connection
String url = "jdbc:mysql://" + ip + ":3306/" + databaseName;
String url = "jdbc:mysql://" + ip + ":3306/" + databaseName +"&useSSL=false";
System.out.println(url);
try
{
con = DriverManager.getConnection(url, userName, password);

@ -0,0 +1,73 @@
<?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. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="MP5-Binary-Files_CalebFontenot" default="default" basedir=".">
<description>Builds, tests, and runs the project MP5-Binary-Files_CalebFontenot.</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. They 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-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="MP5-Binary-Files_CalebFontenot-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

@ -0,0 +1,2 @@
com.calebfontenot.mp5.files_calebfontenot.Exercise17_05
com.calebfontenot.mp5.files_calebfontenot.DataContainer

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

@ -0,0 +1,8 @@
build.xml.data.CRC32=a0844a83
build.xml.script.CRC32=dee8d968
build.xml.stylesheet.CRC32=f85dc8f2@1.108.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=a0844a83
nbproject/build-impl.xml.script.CRC32=025ed557
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48

@ -0,0 +1,8 @@
compile.on.save=true
do.depend=false
do.jar=true
do.jlink=false
javac.debug=true
javadoc.preview=true
jlink.strip=false
user.properties.file=/home/caleb/.netbeans/19/build.properties

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/caleb/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_CalebFontenot/src/module-info.java</file>
<file>file:/home/caleb/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/AddressBookFX.java</file>
<file>file:/home/caleb/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/Exercise17_05.java</file>
<file>file:/home/caleb/ASDV-WebDev/Semester%202/Assignments/MP5-Binary-Files_CalebFontenot/src/com/calebfontenot/mp5/files_calebfontenot/App.java</file>
</group>
</open-files>
</project-private>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>MP5-Binary-Files_CalebFontenot</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

@ -0,0 +1,204 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;
/**
*
* @author caleb
*/
public class AddressBookFX extends Application {
ArrayList<AddressBookEntry> addressArray = new ArrayList<>();
@Override
public void start(Stage stage) throws Exception
{
GridPane primaryGridPane = new GridPane();
GridPane textFieldGridPane = new GridPane();
GridPane addressFieldPane = new GridPane();
GridPane buttonFieldPane = new GridPane();
// Text fields / labels
textFieldGridPane.add(new Label("Name"), 0, 0);
textFieldGridPane.add(new Label("Street"), 0, 1);
textFieldGridPane.add(new Label("City"), 0, 2);
addressFieldPane.add(new Label("State"), 2, 0);
addressFieldPane.add(new Label("ZIP"), 4, 0);
TextField nameTextField = new TextField();
TextField streetTextField = new TextField();
TextField cityTextField = new TextField();
TextField stateTextField = new TextField();
TextField zipTextField = new TextField();
textFieldGridPane.add(nameTextField, 1, 0);
textFieldGridPane.add(streetTextField, 1, 1);
textFieldGridPane.add(addressFieldPane, 1, 2);
addressFieldPane.add(cityTextField, 1, 0);
addressFieldPane.add(stateTextField, 3, 0);
addressFieldPane.add(zipTextField, 5, 0);
textFieldGridPane.getColumnConstraints().add(new ColumnConstraints(50));
primaryGridPane.add(textFieldGridPane, 0, 0);
// Buttons
Button addButton = new Button("Add");
Button firstButton = new Button("First");
Button nextButton = new Button("Next");
Button previousButton = new Button("Previous");
Button lastButton = new Button("Last");
Button updateButton = new Button("Update");
buttonFieldPane.add(addButton, 0, 0);
buttonFieldPane.add(firstButton, 1, 0);
buttonFieldPane.add(nextButton, 2, 0);
buttonFieldPane.add(previousButton, 3, 0);
buttonFieldPane.add(lastButton, 4, 0);
buttonFieldPane.add(updateButton, 5, 0);
primaryGridPane.add(buttonFieldPane, 0, 1);
primaryGridPane.setAlignment(Pos.CENTER);
buttonFieldPane.setHgap(10);
addButton.setOnAction(e -> {
});
firstButton.setOnAction(e -> {
});
nextButton.setOnAction(e -> {
});
previousButton.setOnAction(e -> {
});
lastButton.setOnAction(e -> {
});
updateButton.setOnAction(e -> {
});
Scene scene = new Scene(primaryGridPane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args)
{
File addressBook = new File("AddressBookFX.dat");
if (!addressBook.exists()) {
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(addressBook))) {
fileStream.writeObject(new DataContainer());
} catch (IOException ex) {
System.out.println(ex);
}
} else {
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(addressBook))) {
addressBook = (ArrayList<AddressBookEntry>) fileStream.readObject();
} catch (IOException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
}
launch();
}
}
class AddressBookEntry implements Serializable {
private String name;
private String street;
private String city;
private String state;
private String zip;
public AddressBookEntry()
{
this.name = "Enter a name here.";
this.street = "Enter a street here.";
this.city = "Enter a city here.";
this.state = "Enter a state here.";
this.zip = "Enter a zip here.";
}
public AddressBookEntry(String name, String street, String city, String state, String zip)
{
this.name = name;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
public String getZip()
{
return zip;
}
public void setZip(String zip)
{
this.zip = zip;
}
public String getState()
{
return state;
}
public void setState(String state)
{
this.state = state;
}
public String getCity()
{
return city;
}
public void setCity(String city)
{
this.city = city;
}
public String getStreet()
{
return street;
}
public void setStreet(String street)
{
this.street = street;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}

@ -1,4 +1,4 @@
package com.calebfontenot.mp5.binary.files_calebfontenot;
package com.calebfontenot.mp5.files_calebfontenot;
import javafx.application.Application;
import javafx.scene.Scene;

@ -0,0 +1,52 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
/**
*
* @author caleb
*/
public class Exercise17_01 {
public static void main(String[] args)
{
try (RandomAccessFile fileIO = new RandomAccessFile("Exercise17_01.txt", "rw")) {
int random = 0;
System.out.println("Writing data to file...");
for (int i = 1; i < 100 + 1; ++i) {
random = (int) (Math.random() * 9) + 1;
System.out.print(random + " ");
if (i != 0 && i % 10 == 0) {
System.out.println();
}
fileIO.writeInt(random);
}
System.out.println("Wrote to the file successfully!");
System.out.println("File contents:");
fileIO.seek(0);
int readIterator = 1;
while (true) {
try {
System.out.print(fileIO.readInt() + " ");
if (readIterator != 0 && readIterator % 10 == 0) {
System.out.println();
}
++readIterator;
} catch (EOFException e) {
break;
}
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}

@ -0,0 +1,70 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
*
* @author caleb
*/
public class Exercise17_03 {
static int fileSize = Math.abs((int) (Math.random() * 1024));
public static void writeData()
{
try (FileOutputStream fileWrite = new FileOutputStream("Exercise17_03.dat")) {
// Write a unspecified number of integers into the file.
// Must be positive!
int randInt = 0;
for (int i = 0; i < fileSize; ++i) {
randInt = (int) (Math.random() * 10);
fileWrite.write(randInt);
}
} catch (IOException ex) {
System.out.println(ex);
}
System.out.println("Wrote data to the file!");
}
public static int[] readData()
{
int[] fileData = new int[fileSize];
try (FileInputStream fileRead = new FileInputStream("Exercise17_03.dat")) {
// Read the data back
int dataIterator = 0;
int dataStream = 0;
while (fileRead.available() > 0) {
dataStream = fileRead.read();
fileData[dataIterator++] = dataStream;
System.out.print(dataStream + " ");
if ((dataIterator + 1) % 10 == 0) {
System.out.println();
}
}
} catch (IOException ex) {
System.out.println(ex);
}
return fileData;
}
public static void main(String[] args)
{
System.out.println("Ints to write: " + fileSize);
writeData();
int[] fileData = readData();
// Sum the digits
int sum = 0;
for (int i: fileData) {
sum += i;
}
System.out.println("\nThe sum of the integers in the file is: " + sum);
}
}

@ -0,0 +1,79 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.util.Date;
/**
*
* @author caleb
*/
public class Exercise17_05 {
public static void main(String[] args) {
File dataFile = new File("Exercise17_05.dat");
if(!dataFile.exists()) {
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(dataFile))) {
fileStream.writeObject(new DataContainer());
} catch (IOException ex) {
System.out.println(ex);
}
}
DataContainer data = null;
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(dataFile))) {
data = (DataContainer) fileStream.readObject();
} catch (IOException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
// Now print out the data!
System.out.println("We got the data from the file!");
System.out.println(data.toString());
}
}
class DataContainer implements Serializable {
int[] intArray = {1, 2, 3, 4};
Date currentDate = new Date();
double doubleMoment = 5.5;
public int[] getIntArray()
{
return intArray;
}
public Date getCurrentDate()
{
return currentDate;
}
public double getDoubleMoment()
{
return doubleMoment;
}
@Override
public String toString()
{
String intString = "[";
for (int i = 0; i < intArray.length - 1; ++i) {
intString += intArray[i];
if (i == (intArray.length - 2)) {
intString += "]";
} else {
intString += ", ";
}
}
return "DataContainer{" + "intArray=" + intString + ", currentDate=" + currentDate + ", doubleMoment=" + doubleMoment + '}';
}
}

@ -0,0 +1,4 @@
module com.calebfontenot.mp5.files_calebfontenot{
requires javafx.controls;
exports com.calebfontenot.mp5.files_calebfontenot;
}

@ -0,0 +1 @@
,caleb,caleb-gaming-laptop-archlinux,20.10.2023 21:26,file:///home/caleb/.config/libreoffice/4;

@ -0,0 +1,73 @@
<?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. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="MP5-Binary-Files_CalebFontenot" default="default" basedir=".">
<description>Builds, tests, and runs the project MP5-Binary-Files_CalebFontenot.</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. They 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-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="MP5-Binary-Files_CalebFontenot-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

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

@ -0,0 +1,8 @@
build.xml.data.CRC32=a0844a83
build.xml.script.CRC32=dee8d968
build.xml.stylesheet.CRC32=f85dc8f2@1.108.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=a0844a83
nbproject/build-impl.xml.script.CRC32=025ed557
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.108.0.48

File diff suppressed because one or more lines are too long

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>MP5-Binary-Files_CalebFontenot</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

@ -0,0 +1,256 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.RowConstraints;
import javafx.stage.Stage;
/**
*
* @author caleb
*/
public class AddressBookFX extends Application {
static File addressBook = new File("AddressBookFX.dat");
static int addressArrayPointer = 0;
static ArrayList<AddressBookEntry> addressArray = new ArrayList<>();
static TextField nameTextField = new TextField();
static TextField streetTextField = new TextField();
static TextField cityTextField = new TextField();
static TextField stateTextField = new TextField();
static TextField zipTextField = new TextField();
static Label addressBookCounter = new Label("Items in address book:");
static Label indexLabel = new Label();
@Override
public void start(Stage stage) throws Exception
{
getData();
BorderPane primaryBorderPane = new BorderPane();
GridPane textFieldGridPane = new GridPane();
GridPane addressFieldPane = new GridPane();
GridPane buttonFieldPane = new GridPane();
// Text fields / labels
textFieldGridPane.add(new Label("Name"), 0, 0);
textFieldGridPane.add(new Label("Street"), 0, 1);
textFieldGridPane.add(new Label("City"), 0, 2);
addressFieldPane.add(new Label("State"), 2, 0);
addressFieldPane.add(new Label("ZIP"), 4, 0);
textFieldGridPane.add(nameTextField, 1, 0);
textFieldGridPane.add(streetTextField, 1, 1);
textFieldGridPane.add(addressFieldPane, 1, 2);
addressFieldPane.add(cityTextField, 1, 0);
addressFieldPane.add(stateTextField, 3, 0);
addressFieldPane.add(zipTextField, 5, 0);
textFieldGridPane.getColumnConstraints().add(new ColumnConstraints(50));
primaryBorderPane.setTop(textFieldGridPane);
// Buttons
Button addButton = new Button("Add");
Button firstButton = new Button("First");
Button nextButton = new Button("Next");
Button previousButton = new Button("Previous");
Button lastButton = new Button("Last");
Button updateButton = new Button("Update");
buttonFieldPane.add(indexLabel, 0, 0);
buttonFieldPane.add(addButton, 1, 0);
buttonFieldPane.add(firstButton, 2, 0);
buttonFieldPane.add(nextButton, 3, 0);
buttonFieldPane.add(previousButton, 4, 0);
buttonFieldPane.add(lastButton, 5, 0);
buttonFieldPane.add(updateButton, 6, 0);
buttonFieldPane.add(addressBookCounter, 7, 0);
primaryBorderPane.setBottom(buttonFieldPane);
buttonFieldPane.setAlignment(Pos.CENTER);
buttonFieldPane.setHgap(10);
addButton.setOnAction(e -> {
addressArray.add(new AddressBookEntry());
updateData();
});
firstButton.setOnAction(e -> {
addressArrayPointer = 0;
getEntry(addressArrayPointer);
});
nextButton.setOnAction(e -> {
if (addressArrayPointer >= addressArray.size() - 1) {
addressArrayPointer = 0;
} else {
addressArrayPointer++;
}
getEntry(addressArrayPointer);
});
previousButton.setOnAction(e -> {
if (addressArrayPointer > 0) {
addressArrayPointer--;
} else {
addressArrayPointer = addressArray.size() - 1;
}
getEntry(addressArrayPointer);
});
lastButton.setOnAction(e -> {
addressArrayPointer = addressArray.size() - 1;
getEntry(addressArrayPointer);
});
updateButton.setOnAction(e -> {
AddressBookEntry entry = addressArray.get(addressArrayPointer);
entry.setName(nameTextField.getText());
entry.setCity(nameTextField.getText());
entry.setStreet(streetTextField.getText());
entry.setCity(cityTextField.getText());
entry.setState(stateTextField.getText());
entry.setZip(zipTextField.getText());
updateData();
});
// init fields with data from first entry
getEntry(0);
Scene scene = new Scene(primaryBorderPane);
stage.setScene(scene);
stage.show();
}
public static AddressBookEntry getEntry(int index)
{
AddressBookEntry entry = addressArray.get(index);
indexLabel.setText("Current index: " + index);
addressBookCounter.setText("Items in address book: " + addressArray.size());
nameTextField.setText(entry.getName());
streetTextField.setText(entry.getStreet());
cityTextField.setText(entry.getCity());
stateTextField.setText(entry.getState());
zipTextField.setText(entry.getZip());
return entry;
}
public static void updateData()
{
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(addressBook))) {
fileStream.writeObject(addressArray);
} catch (IOException ex) {
System.out.println(ex);
}
}
public static void getData()
{
if (!addressBook.exists()) {
addressArray.add(new AddressBookEntry());
updateData();
} else {
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(addressBook))) {
addressArray = (ArrayList<AddressBookEntry>) fileStream.readObject();
} catch (IOException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
}
}
public static void main(String[] args)
{
launch();
}
}
class AddressBookEntry implements Serializable {
private String name;
private String street;
private String city;
private String state;
private String zip;
public AddressBookEntry()
{
this.name = "Enter a name here.";
this.street = "Enter a street here.";
this.city = "Enter a city here.";
this.state = "Enter a state here.";
this.zip = "Enter a zip here.";
}
public AddressBookEntry(String name, String street, String city, String state, String zip)
{
this.name = name;
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
public String getZip()
{
return zip;
}
public void setZip(String zip)
{
this.zip = zip;
}
public String getState()
{
return state;
}
public void setState(String state)
{
this.state = state;
}
public String getCity()
{
return city;
}
public void setCity(String city)
{
this.city = city;
}
public String getStreet()
{
return street;
}
public void setStreet(String street)
{
this.street = street;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}

@ -0,0 +1,30 @@
package com.calebfontenot.mp5.files_calebfontenot;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* JavaFX App
*/
public class App extends Application {
@Override
public void start(Stage stage) {
var javaVersion = SystemInfo.javaVersion();
var javafxVersion = SystemInfo.javafxVersion();
var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
var scene = new Scene(new StackPane(label), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}

@ -0,0 +1,98 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.DataInput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
*
* @author caleb
*/
public class CombineFilesFX extends Application {
static List<File> files = null;
final FileChooser fileChooser = new FileChooser();
@Override
public void start(final Stage stage) throws Exception
{
fileChooser.setTitle("Open File to Split...");
BorderPane primaryBorderPane = new BorderPane();
GridPane textFieldGridPane = new GridPane();
Label infoLabel = new Label("Point me at the files that were output by SplitFilesFX.java.");
Label chooseFile = new Label("Choose files to combine: ");
Button openFilePicker = new Button("Choose...");
Button run = new Button("Start");
textFieldGridPane.add(chooseFile, 0, 0);
textFieldGridPane.add(openFilePicker, 1, 0);
primaryBorderPane.setAlignment(run, Pos.CENTER);
primaryBorderPane.setTop(infoLabel);
primaryBorderPane.setCenter(textFieldGridPane);
primaryBorderPane.setBottom(run);
openFilePicker.setOnAction(e -> {
files = fileChooser.showOpenMultipleDialog(openFilePicker.getScene().getWindow());
});
run.setOnAction(e -> {
if (files == null) {
e.consume();
}
combineFiles(files);
});
Scene scene = new Scene(primaryBorderPane);
stage.setScene(scene);
stage.show();
}
public static void combineFiles(List<File> filesToCombine)
{
String outputPath = filesToCombine.get(0).getParent();
try (FileOutputStream dataOut = new FileOutputStream(outputPath + "/" + "reconstructed_" +filesToCombine.get(0).getName().substring( 0, (filesToCombine.get(0).getName().length() - 2)))) {
System.out.println("Writing to " + outputPath + "/" + "reconstructed_" +filesToCombine.get(0).getName().substring( 0, ( filesToCombine.get(0).getName().length() - 2)));
for (File file : filesToCombine) {
try (FileInputStream dataIn = new FileInputStream(file)) {
System.out.println("Opening the source file!");
byte[] buffer = new byte[4096]; // You can adjust the buffer size as needed
int bytesRead;
while ((bytesRead = dataIn.read(buffer)) != -1) {
dataOut.write(buffer, 0, bytesRead);
}
}
}
} catch (IOException ex) {
System.out.println(ex);
}
}
public static void main(String[] args)
{
launch();
}
}
/*
*/

@ -0,0 +1,52 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
/**
*
* @author caleb
*/
public class Exercise17_01 {
public static void main(String[] args)
{
try (RandomAccessFile fileIO = new RandomAccessFile("Exercise17_01.txt", "rw")) {
int random = 0;
System.out.println("Writing data to file...");
for (int i = 1; i < 100 + 1; ++i) {
random = (int) (Math.random() * 9) + 1;
System.out.print(random + " ");
if (i != 0 && i % 10 == 0) {
System.out.println();
}
fileIO.writeInt(random);
}
System.out.println("Wrote to the file successfully!");
System.out.println("File contents:");
fileIO.seek(0);
int readIterator = 1;
while (true) {
try {
System.out.print(fileIO.readInt() + " ");
if (readIterator != 0 && readIterator % 10 == 0) {
System.out.println();
}
++readIterator;
} catch (EOFException e) {
break;
}
}
} catch (Exception ex) {
System.out.println(ex);
}
}
}

@ -0,0 +1,70 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
*
* @author caleb
*/
public class Exercise17_03 {
static int fileSize = Math.abs((int) (Math.random() * 1024));
public static void writeData()
{
try (FileOutputStream fileWrite = new FileOutputStream("Exercise17_03.dat")) {
// Write a unspecified number of integers into the file.
// Must be positive!
int randInt = 0;
for (int i = 0; i < fileSize; ++i) {
randInt = (int) (Math.random() * 10);
fileWrite.write(randInt);
}
} catch (IOException ex) {
System.out.println(ex);
}
System.out.println("Wrote data to the file!");
}
public static int[] readData()
{
int[] fileData = new int[fileSize];
try (FileInputStream fileRead = new FileInputStream("Exercise17_03.dat")) {
// Read the data back
int dataIterator = 0;
int dataStream = 0;
while (fileRead.available() > 0) {
dataStream = fileRead.read();
fileData[dataIterator++] = dataStream;
System.out.print(dataStream + " ");
if ((dataIterator + 1) % 10 == 0) {
System.out.println();
}
}
} catch (IOException ex) {
System.out.println(ex);
}
return fileData;
}
public static void main(String[] args)
{
System.out.println("Ints to write: " + fileSize);
writeData();
int[] fileData = readData();
// Sum the digits
int sum = 0;
for (int i: fileData) {
sum += i;
}
System.out.println("\nThe sum of the integers in the file is: " + sum);
}
}

@ -0,0 +1,79 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.util.Date;
/**
*
* @author caleb
*/
public class Exercise17_05 {
public static void main(String[] args) {
File dataFile = new File("Exercise17_05.dat");
if(!dataFile.exists()) {
try (ObjectOutputStream fileStream = new ObjectOutputStream(new FileOutputStream(dataFile))) {
fileStream.writeObject(new DataContainer());
} catch (IOException ex) {
System.out.println(ex);
}
}
DataContainer data = null;
try (ObjectInputStream fileStream = new ObjectInputStream(new FileInputStream(dataFile))) {
data = (DataContainer) fileStream.readObject();
} catch (IOException ex) {
System.out.println(ex);
} catch (ClassNotFoundException ex) {
System.out.println(ex);
}
// Now print out the data!
System.out.println("We got the data from the file!");
System.out.println(data.toString());
}
}
class DataContainer implements Serializable {
int[] intArray = {1, 2, 3, 4};
Date currentDate = new Date();
double doubleMoment = 5.5;
public int[] getIntArray()
{
return intArray;
}
public Date getCurrentDate()
{
return currentDate;
}
public double getDoubleMoment()
{
return doubleMoment;
}
@Override
public String toString()
{
String intString = "[";
for (int i = 0; i < intArray.length - 1; ++i) {
intString += intArray[i];
if (i == (intArray.length - 2)) {
intString += "]";
} else {
intString += ", ";
}
}
return "DataContainer{" + "intArray=" + intString + ", currentDate=" + currentDate + ", doubleMoment=" + doubleMoment + '}';
}
}

@ -0,0 +1,97 @@
/*
* 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 com.calebfontenot.mp5.files_calebfontenot;
import java.io.DataInput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
/**
*
* @author caleb
*/
public class SplitFilesFX extends Application {
static File file = null;
final FileChooser fileChooser = new FileChooser();
@Override
public void start(final Stage stage) throws Exception
{
fileChooser.setTitle("Open File to Split...");
BorderPane primaryBorderPane = new BorderPane();
GridPane textFieldGridPane = new GridPane();
Label infoLabel = new Label("If you split a file named tmp into 3 smaller files,\n the three smaller files are temp.txt.1, temp.txt.2, and temp.txt.3. ");
Label chooseFile = new Label("Choose a file to split: ");
Button openFilePicker = new Button("Choose...");
Label splitCountLabel = new Label("Enter the amount of files to split into: ");
TextField splitCount = new TextField();
Button run = new Button("Start");
textFieldGridPane.add(chooseFile, 0, 0);
textFieldGridPane.add(openFilePicker, 1, 0);
textFieldGridPane.add(splitCountLabel, 0, 1);
textFieldGridPane.add(splitCount, 1, 1);
primaryBorderPane.setAlignment(run, Pos.CENTER);
primaryBorderPane.setTop(infoLabel);
primaryBorderPane.setCenter(textFieldGridPane);
primaryBorderPane.setBottom(run);
openFilePicker.setOnAction(e -> {
file = fileChooser.showOpenDialog(openFilePicker.getScene().getWindow());
});
run.setOnAction(e -> {
if (file == null) {
e.consume();
}
splitFile(file, Integer.parseInt(splitCount.getText()));
});
Scene scene = new Scene(primaryBorderPane);
stage.setScene(scene);
stage.show();
}
public static void splitFile(File fileToSplit, int splitCount) {
int outputFileSize = (int) fileToSplit.length() / splitCount;
String outputPath = fileToSplit.getParent();
// Open the original file
try (FileInputStream dataIn = new FileInputStream(fileToSplit)) {
System.out.println("Opening the source file!");
for (int i = 0; i < splitCount; ++i) {
//dataIn.mark(outputFileSize * (i + 1));
try (FileOutputStream dataOut = new FileOutputStream(outputPath + "/" + fileToSplit.getName() + "." + (i + 1))) {
dataOut.write(dataIn.readNBytes(outputFileSize), 0, outputFileSize);
System.out.println("Writing to " + outputPath + "/" + fileToSplit.getName() + "." + (i + 1));
}
}
} catch (IOException ex) {
System.out.println(ex);
}
}
public static void main(String[] args)
{
launch();
}
}
/*
*/

@ -0,0 +1,13 @@
package com.calebfontenot.mp5.files_calebfontenot;
public class SystemInfo {
public static String javaVersion() {
return System.getProperty("java.version");
}
public static String javafxVersion() {
return System.getProperty("javafx.version");
}
}

@ -0,0 +1,4 @@
module com.calebfontenot.mp5.files_calebfontenot{
requires javafx.controls;
exports com.calebfontenot.mp5.files_calebfontenot;
}

@ -0,0 +1 @@
-XX:+UnlockExperimentalVMOptions -XX:+EagerJVMCI -XX:+EnableJVMCI -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.compile.on.save>all</netbeans.compile.on.save>
<netbeans.hint.jdkPlatform>Graal_JDK_20</netbeans.hint.jdkPlatform>
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
</properties>
</project-shared-configuration>

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>clean</goal>
<goal>javafx:run</goal>
</goals>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>clean</goal>
<goal>javafx:run@ide-debug</goal>
</goals>
<properties>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<goals>
<goal>clean</goal>
<goal>javafx:run@ide-profile</goal>
</goals>
</action>
<action>
<actionName>CUSTOM-jlink</actionName>
<displayName>jlink</displayName>
<goals>
<goal>clean</goal>
<!-- compile not needed with javafx-maven-plugin v0.0.5 -->
<goal>compile</goal>
<goal>javafx:jlink</goal>
</goals>
</action>
</actions>

@ -1,15 +0,0 @@
/*
* 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 com.calebfontenot.mp5.binary.files_calebfontenot;
/**
*
* @author caleb
*/
public class Exercise17_01 {
public static void main(String[] args) {
}
}

@ -1,4 +0,0 @@
module com.calebfontenot.mp5.binary.files_calebfontenot {
requires javafx.controls;
exports com.calebfontenot.mp5.binary.files_calebfontenot;
}