JAVA HELP HELP HELP me fix it... Buttons do not work.... idk what are the proble
ID: 3822081 • Letter: J
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 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<T, K, O> {
private Node<T, K, O> head;
private int size = 0;
private T category1Label;
private K category2Label;
private O category3Label;
private int groupingCategory;
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<T, K, O> newNode = new Node<T, K, O>(value1, value2, value3);
Node<T, K, O> currentNode = this.head;
boolean done = false;
if (groupingCategory == 1) {
if (this.head == null) {
this.head = newNode;
System.out.println("made first head");
} else {
if (currentNode.category1.equals(value1)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to first node downlist");
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to first node down list p2");
}
} else {
while (currentNode.right != null) {
currentNode = currentNode.right;
if (currentNode.category1.equals(value1)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to middle node downlist");
done = true;
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to middle node down list p2");
done = true;
}
}
}
if (!done) {
currentNode.right = newNode;
newNode.left = currentNode;
System.out.println("created a new node in main list");
}
}
}
} else if (groupingCategory == 2) {
if (this.head == null) {
this.head = newNode;
System.out.println("made first head");
} else {
if (currentNode.category2.equals(value2)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to first node downlist");
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to first node down list p2");
}
} else {
while (currentNode.right != null) {
currentNode = currentNode.right;
if (currentNode.category2.equals(value2)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to middle node downlist");
done = true;
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to middle node down list p2");
done = true;
}
}
}
if (!done) {
currentNode.right = newNode;
newNode.left = currentNode;
System.out.println("created a new node in main list");
}
}
}
} else if (groupingCategory == 3) {
if (this.head == null) {
this.head = newNode;
System.out.println("made first head");
} else {
if (currentNode.category3.equals(value3)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to first node downlist");
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to first node down list p2");
}
} else {
while (currentNode.right != null) {
currentNode = currentNode.right;
if (currentNode.category3.equals(value3)) {
if (currentNode.down == null) {
currentNode.down = newNode;
System.out.println("added to middle node downlist");
done = true;
} else {
Node<T, K, O> tempCur = currentNode;
while (tempCur.down != null) {
tempCur = tempCur.down;
}
tempCur.down = newNode;
System.out.println("added to middle node down list p2");
done = true;
}
}
}
if (!done) {
currentNode.right = newNode;
newNode.left = currentNode;
System.out.println("created a new node in main list");
}
}
}
}
size++;
System.out.println(size);
}
/* 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<T, K, O> currentNode = this.head;
Node<T, K, O> previousNode = this.head;
while (currentNode.right != null) {
previousNode = currentNode;
currentNode = currentNode.right;
}
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<T, K, O> currentNode = this.head;
Node<T, K, O> previousNode = this.head;
while (currentNode.right != null && countMain < mainIndex) {
previousNode = currentNode;
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
previousNode = currentNode;
currentNode = currentNode.down;
countSub++;
}
Node<T, K, O> rightReference = currentNode.right;
Node<T, K, O> leftReference = currentNode.left;
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<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && count < mainIndex) {
currentNode = currentNode.right;
count++;
}
return (String) currentNode.getCategory3();
}
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<T, K, O> currentNode = this.head;
if (category == 1) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory1();
} else if (category == 2) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory2();
} else if (category == 3) {
while (currentNode.right != null && countMain < mainIndex) {
currentNode = currentNode.right;
countMain++;
}
while (currentNode.down != null && countSub < subIndex) {
currentNode = currentNode.down;
countSub++;
}
return (String) currentNode.getCategory3();
}
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<T, K, O>> listOfNodes = new ArrayList<>();
Node<T, K, O> mainNode = this.head;
Node<T, K, O> subNode = this.head;
while (mainNode != null) {
listOfNodes.add(mainNode);
while(subNode.down != null){
subNode = subNode.down;
listOfNodes.add(subNode);
}
mainNode = mainNode.right;
subNode = mainNode;
}
clear();
for (int i = 0; i < listOfNodes.size(); i++) {
add(listOfNodes.get(i).getCategory1(),listOfNodes.get(i).getCategory2(),listOfNodes.get(i).getCategory3());
}
}
}
/*
* 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<T, K, O> currentNode = this.head;
int mainListSize = 1;
while (currentNode.right != null) {
currentNode = currentNode.right;
mainListSize++;
}
return mainListSize;
}
/*
* 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<T, K, O> thisNode = this.head;
while (thisNode.down != null) {
thisNode = thisNode.down;
subListSize++;
}
} else {
Node<T, K, O> currentNode = this.head;
while (currentNode.right != null && count < index) {
currentNode = currentNode.right;
count++;
}
while (currentNode.down != null) {
currentNode = currentNode.down;
subListSize++;
}
}
}
return subListSize;
}
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<T, K, O> {
protected T category1;
protected K category2;
protected O category3;
protected Node<T, K, O> right = null;
protected Node<T, K, O> left = null;
protected Node<T, K, O> down = null;
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;
}
Explanation / Answer
Test the common or general way (using anonymous class) to make the button bounded
nameOFButton.setOnAction(new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e) {
System.out.println("Action Of the Button ");
}
});
// If it does not works try this method
Alternative to the above solution:
1.Make Use Of the Logger
2.Attempt to Debug the Code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.