Question: / / Main.java import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Circle;
Main.java
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
public class Main extends Application
private Graph graph;
@Override
public void startStage primaryStage
graph new Graph;
BorderPane root new BorderPane;
Scene scene new Sceneroot;
GraphPane graphPane new GraphPane;
root.setCentergraphPane;
HBox controls new HBox;
controls.setStylefxpadding: px;;
root.setBottomcontrols;
TextField vertexField new TextField;
TextField vertexField new TextField;
Button addEdgeButton new ButtonAdd Edge";
addEdgeButton.setOnActione addEdgevertexField.getText vertexField.getText;
controls.getChildrenaddAlladdEdgeButton new LabelVertex : vertexField,
new LabelVertex : vertexField;
Button isConnectedButton new ButtonIs Connected?";
isConnectedButton.setOnActione checkConnected;
Button hasCyclesButton new ButtonHas Cycles?";
hasCyclesButton.setOnActione checkCycles;
Button depthFirstButton new ButtonDepth First Search";
depthFirstButton.setOnActione performDepthFirstSearch;
Button breadthFirstButton new ButtonBreadth First Search";
breadthFirstButton.setOnActione performBreadthFirstSearch;
controls.getChildrenaddAllisConnectedButton hasCyclesButton, depthFirstButton, breadthFirstButton;
primaryStage.setScenescene;
primaryStage.setTitleGraph Component";
primaryStage.show;
private void addEdgeString vertex String vertex
Assume vertex coordinates are predefined for simplicity
double x y;
double x y;
if vertexisEmpty && vertexisEmpty
graph.addEdgevertex vertex;
drawEdgex y x y;
private void drawEdgedouble x double y double x double y
Line line new Linex y x y;
line.setStrokeWidth;
line.setStrokeColorBLACK;
GraphPane graphPane GraphPaneBorderPane graphPane.getScenegetRootgetCenter;
graphPane.getChildrenaddline;
private void checkConnected
boolean isConnected graph.isConnected;
displayMessageisConnected "The graph is connected." : "The graph is not connected.";
private void checkCycles
boolean hasCycles graph.hasCycles;
displayMessagehasCycles "The graph has cycles." : "The graph does not have cycles.";
private void performDepthFirstSearch
List dfs graph.depthFirstSearch;
displayMessageDepth First Search: dfstoString;
private void performBreadthFirstSearch
List bfs graph.breadthFirstSearch;
displayMessageBreadth First Search: bfstoString;
private void displayMessageString message
TextField messageField TextFieldBorderPane graphPane.getScenegetRootgetBottom;
Platform.runLaternull;
messageField.setTextmessage;
public static void mainString args
launchargs;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Text;
import java.util.HashMap;
import java.util.Map;
public class GraphPane extends Pane
private final Map vertexCircles new HashMap;
private char nextVertexLabel A;
public GraphPane
setOnMouseClickedevent
double x event.getX;
double y event.getY;
addVertexx y;
;
public void addVertexdouble x double y
if nextVertexLabel Z
return; Limit to vertices
String vertexName String.valueOfnextVertexLabel;
Circle circle new Circlex y Color.LIGHTBLUE;
Text label new Textx y vertexName;
vertexCircles.putvertexName circle;
getChildrenaddAllcircle label;
public void drawEdgeString vertex String vertex
Circle circle vertexCircles.getvertex;
Circle circle vertexCircles.getvertex;
if circle null && circle null
Line line new LinecirclegetCenterX circlegetCenterY
circlegetCenterX circlegetCenterY;
line.setStrokeColorBLACK;
getChildrenaddline;
Need help implemening message textfield, making sure the buttons work, and adding edges to the vertices.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
