Question
JAVA HELP HELP HELP me fix it... Buttons do not work.... idk what are the problems import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import
JAVA HELP HELP HELP me fix it...
Buttons do not work.... idk what are the problems
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage;
public class Main extends Application { Button regroupButt = new Button("Regroup List"); Button clearButt = new Button("Clear List"); Button fileButt = new Button("File"); Button sizeButt = new Button("Size of List"); Button quitButt = new Button("Quit"); Button addButt = new Button("Add Node to List"); Button delButt = new Button("Delete a Node"); Button getButt = new Button("Get Node information"); GridPane gp = new GridPane(); HBox hb = new HBox(); VBox vb = new VBox(); // File file = new File();
@Override public void start(Stage primaryStage) { try { primaryStage.setTitle("LinkedList");
hb.getStyleClass().add("hBox"); gp.getStyleClass().add("gridPane");
regroupButt.getStyleClass().add("button"); clearButt.getStyleClass().add("button"); fileButt.getStyleClass().add("button"); sizeButt.getStyleClass().add("button"); quitButt.getStyleClass().add("button"); addButt.getStyleClass().add("button"); delButt.getStyleClass().add("button"); getButt.getStyleClass().add("button");
Scene sc = new Scene(vb, 1000, 1000); sc.getStylesheets().add("styles/style.css");
hb.getChildren().addAll(fileButt, addButt, delButt, clearButt, getButt, regroupButt, sizeButt, quitButt);
vb.getChildren().addAll(hb, gp);
primaryStage.setScene(sc); primaryStage.show(); } catch (Exception e) { e.printStackTrace(); } } public void createGrid(){ }
public static void main(String[] args) { launch(args); } }
-----------------------------------------------------------
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner;
public class LinkedList
public LinkedList() { this.head = null; }
public LinkedList(int currentCategory) { this.head = null; this.groupingCategory = currentCategory; }
/* * This class shall have one constructor which takes a File object parameter * and an integer parameter. This File is the input file from which a list * can be generated and populated. The integer parameter is the current * grouping property. . */ @SuppressWarnings("unchecked") public LinkedList(File file, int currentCategory) throws FileNotFoundException { this.groupingCategory = currentCategory; String lineOfData = ""; String[] field = { "" }; String values = ""; String[] singleValues = { "" };
Scanner fReader = new Scanner(file);
while (fReader.hasNextLine()) { lineOfData += fReader.nextLine(); lineOfData += " "; field = lineOfData.split(" "); } fReader.close();
this.category1Label = (T) field[0]; this.category2Label = (K) field[1]; this.category3Label = (O) field[2];
for (int HA = 4; HA < field.length; HA++) { values += field[HA]; values += ", "; singleValues = values.split(", "); }
for (int LOL = 0; LOL < singleValues.length; LOL += 3) { add((T) singleValues[LOL], (K) singleValues[LOL + 1], (O) singleValues[LOL + 2]); } }
/* * This method shall have three parameters. These parameters are the values * of the categories in a Node. Use the parameters to create a new Node and * add it to the list. The Node must be added in such a way that it * maintains the current grouping category of the list. */ public void add(T value1, K value2, O value3) { Node
if (currentNode.category3.equals(value3)) { if (currentNode.down == null) { currentNode.down = newNode; System.out.println("added to middle node downlist"); done = true; } else { Node
/* This method shall clear the list. */ public void clear() { this.head = null; this.size = 0; }
/* * This method shall delete the first Node in the main list. This method * shall NOT delete any nodes in the first Node's sublist. The remaining * Nodes in the sublist should be "reattached" to the beginning of the main * list. */ public void deleteFirst() { if (this.size == 0) { System.out.println("Empty List"); } else { if (this.head.down != null) { this.head.right.left = this.head.down; this.head.down.right = this.head.right; this.head = this.head.down; } else { this.head = this.head.right; } this.size--; } }
/* * This method shall delete the last Node in the main list. This method * shall NOT delete any nodes in the last Node's sublist. The remaining * Nodes in the sublist should be "reattached" to the end of the main list. */ public void deleteLast() { if (this.size == 0) { System.out.println("Empty List"); } else { Node
if (currentNode.down != null) { currentNode.down.left = previousNode; previousNode.right = currentNode.down; } else { previousNode.right = null; } size--; } }
/* * This method shall delete a specific node from anywhere in the list, given * the mainIndex and subIndex. This method should ONLY delete the requested * Node and should "reconnect" any Nodes that may be attached to the deleted * Node. */ public void delete(int mainIndex, int subIndex) { int countMain = 0, countSub = 0; if (mainIndex > size() - 1 || mainIndex < 0) { throw new IndexOutOfBoundsException("main index out of bounds"); } else if (subIndex > size(mainIndex) || subIndex < 0) { throw new IndexOutOfBoundsException("sub index out of bounds"); }
if (mainIndex == 0 && subIndex == 0) { deleteFirst(); } else if (mainIndex == size() - 1 && subIndex == 0) { deleteLast(); }
Node
while (currentNode.down != null && countSub < subIndex) { previousNode = currentNode; currentNode = currentNode.down; countSub++; }
Node
if (subIndex == 0) { if (currentNode.down != null) { rightReference.left = currentNode.down; leftReference.right = currentNode.down; currentNode.down.right = rightReference; currentNode.down.left = leftReference; } else { rightReference.left = leftReference; leftReference.right = rightReference; } size--; } else if (subIndex > 0) { if (currentNode.down != null) { previousNode.down = currentNode.down; } else { previousNode.down = null; }
} }
/* * This method shall have an integer parameter, mainIndex, which is an index * (starting from 0) which indicates the Node from the main branch you want * to retrieve. */ public String get(int mainIndex, int category) { if (mainIndex > size() - 1 || mainIndex < 0) { throw new IndexOutOfBoundsException("mainIndex out of bounds"); } else if (category < 0 || category > 3) { throw new IndexOutOfBoundsException("category index out of bounds"); }
int count = 0; Node
return null; }
public String get(int mainIndex, int subIndex, int category) { if (mainIndex > size() - 1 || mainIndex < 0) { throw new IndexOutOfBoundsException("main index out of bounds"); } else if (category < 0 || category > 3) { throw new IndexOutOfBoundsException("category index out of bounds"); } else if (subIndex < 0 | subIndex > size(mainIndex)) { throw new IndexOutOfBoundsException("sub index out of bounds"); } int countMain = 0, countSub = 0; Node
return null; }
/* * This method shall be responsible for regrouping your LinkedList based on * the given regrouping category number. Example: I could take the above * list from the diagram, which was initially grouped based on the Age * category (category 1), and I could regroup the list based on the * Profession category (category 3). If the groupingCategoryNumber is out of * bounds, display an IndexOutOfBoundsException with an appropriate error * message. */ public void regroup(int groupingCategoryNumber) { if (groupingCategoryNumber < 1 || groupingCategoryNumber > 3) { throw new IndexOutOfBoundsException("grouping category number out of bounds, bounds = [0,3]"); } else { this.groupingCategory = groupingCategoryNumber; ArrayList
Node
}
/* * This method shall return the size of the main list. The size is the * number of nodes in the main list. */ public int size() { Node
/* * This method shall return the size of the sub-list at the given index. If * the given index is out of bounds, this method should throw an * IndexOutOfBoundsException with an appropriate error message. */ public int size(int index) { int count = 0; int subListSize = 0; if (index > size() - 1 || index < 0) { throw new IndexOutOfBoundsException("Index out of bounds, index bounds: [0," + size() + "]"); } else { if (index == 0) { Node
public void print() { // System.out.println(this.head.right.getCategory1()); // System.out.println(this.head.down.getCategory1()); // System.out.println(this.head.down.down.getCategory1()); // // System.out.println(this.head.right.right.left.down.getCategory2());
System.out.println(this.head.right.right.getCategory3()); }
public void print2() { System.out.println(this.head.getCategory1()); System.out.println(this.head.down.getCategory1()); System.out.println(this.head.down.down.getCategory1()); } }
--------------------------------------------
public class Node
public Node(T category1, K category2, O category3) { this.category1 = category1; this.category2 = category2; this.category3 = category3; }
public T getCategory1() { return category1; }
public K getCategory2() { return category2; }
public O getCategory3() { return category3; } }
-----------------
style.css
.hBox{ -fx-background-color: #000000; } .gridPane{ -fx-pref-height: 1000.0; -fx-pref-width: 900.0; -fx-background-color: #000000; } .button{ -fx-background-color: #000000; -fx-border-color: #ffffff; -fx-text-fill: #ffffff; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started