Java FX Application
Java FX Application
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.control.*;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import java.util.Optional;
import java.util.List;
import java.util.Arrays;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.event.EventHandler;
class LinkedList{
private Node head;
private int size;
LinkedList(){
head=null;
size=0;
}
void AddFirst(int data) {
Node n = new Node(data, null);
n.setNext(head);
head=n;
size++;
}
void AddLast(int data) {
Node ptr = head;
while(ptr.getNext() != null) {
ptr = ptr.getNext();
}
Node n = new Node(data, null);
ptr.setNext(n);
size++;
}
void Display(){
Node ptr = head;
while(ptr.getNext() != null){
System.out.println(ptr.data);
}
}
Node i = head;
while(i.getNext() != null){
i = i.getNext();
list.add(i);
}
return list;
}
pushbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
int pushval = Integer.parseInt(val.getText());
mystack.push(pushval);
msgpushed.setText("Value pushed: " + pushval);
}
});
popbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
lblpop.setText("Value popped: " + mystack.pop());
}
});
stackbox.getChildren().addAll(val,pushbtn, popbtn,msgpushed,lblpop);
stage.setScene(new Scene(stackbox, 500, 300));
stage.show();
addbtn.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
int a = Integer.parseInt(addfield.getText());
l.AddFirst(a);
table.setItems(l.getNodesList());
}
});
data.setCellValueFactory(new PropertyValueFactory<>("data"));
next.setCellValueFactory(new PropertyValueFactory<>("next"));
table.getColumns().addAll(data, next);
@Override
public void start(Stage primaryStage) {
List<String> dialogData;
dialogData = Arrays.asList(arrayData);
ChoiceDialog dialog = new ChoiceDialog(dialogData.get(0), dialogData);
dialog.setTitle("Data Structures");
dialog.setHeaderText("Select your choice");
Optional<String> result = dialog.showAndWait();
String selected = "";
if (result.isPresent()) {
selected = result.get();
switch(selected){
case "LinkedList":
System.out.println("LinkedList");
Stage stage = new Stage();
linkListDS(stage);
break;
case "Stack":
System.out.println("Stack");
Stage stagestack = new Stage();
stack(stagestack);
break;
default:
break;
}
}
//actionStatus.setText("Selection: " + selected);
// int m=Integer.parseInt("a");
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);