*internal screaming*
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -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,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,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;
|
||||
}
|
Reference in New Issue
Block a user