0% found this document useful (0 votes)
34 views4 pages

JavaFX Data Structures Example

This document defines a JavaFX application that allows a user to select between visualizing either a linked list or stack data structure. It implements classes for a LinkedList and Node, and methods for adding/displaying nodes. When the user selects their choice, it launches a new stage to display either the linked list or stack implementation using a table or HBox layout with buttons/labels.

Uploaded by

zeeshan tech
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

JavaFX Data Structures Example

This document defines a JavaFX application that allows a user to select between visualizing either a linked list or stack data structure. It implements classes for a LinkedList and Node, and methods for adding/displaying nodes. When the user selects their choice, it launches a new stage to display either the linked list or stack implementation using a table or HBox layout with buttons/labels.

Uploaded by

zeeshan tech
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication1;

import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

class LinkedList{
private Node head;
private int size;
LinkedList(){
head=null;
size=0;
}
void AddFirst(int data) {
Node n = new Node(data, null);
[Link](head);
head=n;
size++;
}
void AddLast(int data) {
Node ptr = head;
while([Link]() != null) {
ptr = [Link]();
}
Node n = new Node(data, null);
[Link](n);
size++;
}
void Display(){
Node ptr = head;
while([Link]() != null){
[Link]([Link]);
}
}

public ObservableList<Node> getNodesList(){


ObservableList<Node> list = [Link]();

Node i = head;
while([Link]() != null){
i = [Link]();
[Link](i);
}

return list;
}

public class JavaFXApplication1 extends Application {

void stack(Stage stage){


stack mystack = new stack();

HBox stackbox = new HBox();


Button pushbtn = new Button("Push");
Button popbtn = new Button("Pop");
Label msgpushed = new Label("");
Label lblpop = new Label("");
TextField val = new TextField("Enter value");

[Link](new Insets(15, 12, 15, 12));


[Link](10);

[Link](new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
int pushval = [Link]([Link]());
[Link](pushval);
[Link]("Value pushed: " + pushval);
}
});

[Link](new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
[Link]("Value popped: " + [Link]());

}
});

[Link]().addAll(val,pushbtn, popbtn,msgpushed,lblpop);
[Link](new Scene(stackbox, 500, 300));
[Link]();

public void linkListDS(Stage stage){

Button addbtn = new Button("Add");


TextField addfield = new TextField();
LinkedList l = new LinkedList();

TableView<Node> table = new TableView();


TableColumn<Node, Integer> data = new TableColumn("Data");
TableColumn<Node, Node> next = new TableColumn("Next Node");

[Link](new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
int a = [Link]([Link]());
[Link](a);
[Link]([Link]());
}
});

[Link](new PropertyValueFactory<>("data"));
[Link](new PropertyValueFactory<>("next"));
[Link]().addAll(data, next);

HBox box = new HBox();


[Link]().addAll(addfield,addbtn,table);
[Link](new Scene(box, 600, 300));
[Link]();

@Override
public void start(Stage primaryStage) {

final String [] arrayData = {"LinkedList", "Stack"};

List<String> dialogData;
dialogData = [Link](arrayData);
ChoiceDialog dialog = new ChoiceDialog([Link](0), dialogData);
[Link]("Data Structures");
[Link]("Select your choice");
Optional<String> result = [Link]();
String selected = "";

if ([Link]()) {

selected = [Link]();
switch(selected){
case "LinkedList":
[Link]("LinkedList");
Stage stage = new Stage();
linkListDS(stage);
break;
case "Stack":
[Link]("Stack");
Stage stagestack = new Stage();
stack(stagestack);
break;
default:
break;
}

}
//[Link]("Selection: " + selected);

// int m=[Link]("a");

// Button btn = new Button();


// [Link]("Say 'Hello World'");
// [Link](new EventHandler<ActionEvent>() {
//
// @Override
// public void handle(ActionEvent event) {
// [Link]("Hello World!");
// }
// });
//

// Scene scene = new Scene(root, 300, 250);


//
// [Link]("Hello World!");
// [Link](scene);
// [Link]();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

launch(args);

You might also like