How to analyze the code to fix its work

I am writing code for the “Time Tracker” application and one of the functions does not work, namely the display of the image. What’s wrong?
And yet, I want to analyze the entire code, maybe there are still errors that I don’t see. Is there some kind of automatic code analysis?
private void initPanel()
panel = new JPanel();{


Hi there and welcome to our forums!

It looks you only pasted a few lines of code. Certainly not enough to go by for giving you a proper answer.

Could you please post all relevant code? And when you do please enclose it in three backticks on a line before and after the code so it gets properly formatted.

Yes, it`s my code

package com.TSP;
import java.util.ArrayList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.geometry.Point2D;
import javafx.stage.Stage;
public class Controller {
    public static AnchorPane canvasPane;
    private static ArrayList<Point2D> pointsArray;
    private int newCitiesCount; //в дальнейшем буду передавать его как bound для ProblemSolver
    public static Point2D canvasPanePointCoords;
    public static Point2D prevPointClicked;
    public static int getCity(Point2D point) {
            int i;
            for (i = 0; i < pointsArray.size(); ++i) {
                if (pointsArray.get(i).distance(point) < 24)
            return i + 1;
    private int repPointClicksCounter;
    private static Stage stage;
    private static void showDistanceInputWindow() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource("dialog.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 400, 250);
        stage.setTitle("Distance input");
    public static void closeDistanceInputWindow() {
    void onMouseClicked(MouseEvent event) {
        double pointX = event.getSceneX();
        double pointY = event.getSceneY();
        canvasPanePointCoords = canvasPane.sceneToLocal(pointX, pointY);
        int counter = 0; int counter2 = 0;
        int flag = 0;
        if (pointsArray.size() == 0)
            flag = 1;
        else {
            for (int i = 0; i < pointsArray.size(); ++i) {
                if (pointsArray.get(i).distance(canvasPanePointCoords) > 24)
            if (counter == pointsArray.size())
                flag = 1;
        if (flag == 1 && newCitiesCount < CitiesCollection.size) { //если в месте клика нет точки
            Circle point = new Circle(canvasPanePointCoords.getX(), canvasPanePointCoords.getY(), 8, Color.CADETBLUE);
            Label label = new Label(Integer.toString(newCitiesCount));
            System.out.println("Added new city: (" + canvasPanePointCoords.getX() + " ; " + canvasPanePointCoords.getY() + ")");
        } else if (flag == 0) { //если в месте клика уже есть точка
            if (pointsArray.size() > 1) { //если пред. клик был не в эту же точку и имеется больше 1 точки
                if (repPointClicksCounter == 2) {
                    for (int i = 0; i < pointsArray.size(); ++i) {
                        if (pointsArray.get(i).distance(canvasPanePointCoords) < 24 || pointsArray.get(i).distance(prevPointClicked) < 24)
                    repPointClicksCounter = 0;
                if (counter2 == 2 && prevPointClicked.distance(canvasPanePointCoords) > 24) { //если пред. клик и текущий клик - города
                    try {
                    catch (IOException e) {
                        System.out.println("Wrong input!");
        prevPointClicked = canvasPanePointCoords;
    void onStartButtonClicked(MouseEvent event) {
        ProblemSolver.findShortestRoute(CitiesCollection.matrix, newCitiesCount).printRoute();
    void initialize() {
        pointsArray = new ArrayList<>();
        canvasPane = new AnchorPane();
        prevPointClicked = new Point2D(0,0);
        canvasPanePointCoords = new Point2D(0,0);
        newCitiesCount = 1;
        repPointClicksCounter = 0;
        stage = new Stage();
type or paste code here

eslint does a pretty good job of helping to scan your code for any issues.

That looks like Java, not JavaScript. I’ll move this thread to a more suitable forum.

I also found the AppRefactoring service on the Internet, have you tried it?

No, I haven’t used that one but there are some warning signs:

  • The owner of the website is using a service to hide their identity on WHOIS
  • According to Tranco this site has a low Alexa rank
  • This website is (very) young.

It’s best to avoid that one.


Okay, thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.