问:
How to render edit view and post flash message in rails3
In my account controller I'd like to display (render, redirect_to ?) the edit view after changes get saved and display flash notice. </p>

```<code> def update
    @account = Account.find(params[:id])

    respond_to do |format|
      if @account.update_attributes(params[:account])
        format.html { redirect_to(@account, :notice => 'Account was successfully updated.') }

      else
        format.html { render :action => "edit" }
      end
    end
  end
</code>```

答:
You can still use notices like in Rails 2:

```<code>flash[:notice] = "message"
</code>```

Just add the following line to the top of your view to display it:

<%= flash[:notice] %>

And you should use render method if you don't want to make your users to fill edit forms once again.

Body:
In my account controller I'd like to display (render, redirect_to ?) the edit view after changes get saved and display flash notice.

 def update
    @account = Account.find(params[:id])

    respond_to do |format|
      if @account.update_attributes(params[:account])
        format.html { redirect_to(@account, :notice => 'Account was successfully updated.') }

      else
        format.html { render :action => "edit" }
      end
    end
  end

Body:
You can still use notices like in Rails 2:

flash[:notice] = "message"

Just add the following line to the top of your view to display it:

<p id="notice"><%= flash[:notice] %></p>

And you should use render method if you don't want to make your users to fill edit forms once again.


来源: stackexchange

问:
Animation in UIView follow UILabel
I have work with animation same image

I have make a UILabel on UIView. And I make animation for UILabel move from right to left.

I want same here:

This is my code:

```<code>[UIView animateKeyframesWithDuration:6 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseOut animations:^{
             _lbAnimation.frame=CGRectMake(0-(rect.size.width), _lbAnimation.frame.origin.y, rect.size.width, _lbAnimation.frame.size.height);

         } completion:^(BOOL finished)
          {
              _viewAnimation.hidden = YES;
          }];
</code>```

And now, I want while frame of UILabel move to end is width of UIView: _viewAnimation follow UILabel.

Please help me.

This is my code

https://github.com/nhhthuanck/Alert-Animation

Please check again help me.

答:
You shouldn't put lbAnimation inside viewAnimation. And need some calculate duration of animation time.

```<code>- (IBAction)startAction:(id)sender {

    NSString * htmlString = @"<html>"
    "  <head>"
    "    <style type='text/css'>"
    "      body { font: 16pt 'Gill Sans'; color: #1a004b; }"
    "      i { color: #822; }"
    "    </style>"
    "  </head>"
    "  <body>Here is some <i>formatting!</i> <a href='#'><font color='green'>Google</font></a><font color='red'> example text</font><a href='#'>YouTube</a><b> bold</b> and <i>italic</i></body>"
    "</html>";
    NSError *err = nil;
    NSAttributedString * attrStr = [[NSAttributedString alloc]
                                    initWithData: [htmlString dataUsingEncoding:NSUTF8StringEncoding]
                                    options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                    documentAttributes: nil
                                    error: &err];

    _viewAnimation.frame = CGRectMake(self.view.frame.size.width, _viewAnimation.frame.origin.y, _viewAnimation.frame.size.width, _viewAnimation.frame.size.height);
    _viewAnimation.hidden = NO;
    _lbAnimation.hidden = YES;
    CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(FLT_MAX, _lbAnimation.frame.size.height)
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                               context:nil];

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveLinear  animations:^{
        _viewAnimation.frame=CGRectMake(0, _viewAnimation.frame.origin.y, _viewAnimation.frame.size.width, _viewAnimation.frame.size.height);
    } completion:^(BOOL finished)
     {
         _lbAnimation.hidden = NO;
         _lbAnimation.attributedText = attrStr;
         _lbAnimation.frame = CGRectMake(self.view.frame.size.width, _lbAnimation.frame.origin.y, rect.size.width, _viewAnimation.frame.size.height);

       CGFloat duration = 6;
       CGFloat ratio = _viewAnimation.frame.size.width / (rect.size.width + _viewAnimation.frame.size.width);

       [UIView animateWithDuration:duration * ratio delay:duration * (1-ratio) + 0.1f options:UIViewAnimationOptionCurveLinear animations:^{
         _viewAnimation.frame = CGRectMake(_viewAnimation.frame.origin.x, _viewAnimation.frame.origin.y, 0, _viewAnimation.frame.size.height);
       } completion:^(BOOL finished) {
         _viewAnimation.hidden = YES;
       }];

       [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
         _lbAnimation.frame=CGRectMake(-rect.size.width, _lbAnimation.frame.origin.y, rect.size.width, _lbAnimation.frame.size.height);

       } completion:^(BOOL finished)
        {

        }];

     }];
}
</code>```

You can check my demo.

ContentLicense: CC BY-SA 3.0

Title: Animation in UIView follow UILabel

Body:
I have work with animation same image

I have make a UILabel on UIView. And I make animation for UILabel move from right to left.

I want same here:

This is my code:

[UIView animateKeyframesWithDuration:6 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseOut animations:^{
             _lbAnimation.frame=CGRectMake(0-(rect.size.width), _lbAnimation.frame.origin.y, rect.size.width, _lbAnimation.frame.size.height);

         } completion:^(BOOL finished)
          {
              _viewAnimation.hidden = YES;
          }];

And now, I want while frame of UILabel move to end is width of UIView: _viewAnimation follow UILabel.

Please help me.

This is my code

https://github.com/nhhthuanck/Alert-Animation

Please check again help me.

Body:
You shouldn't put lbAnimation inside viewAnimation. And need some calculate duration of animation time.

- (IBAction)startAction:(id)sender {

    NSString * htmlString = @"<html>"
    "  <head>"
    "    <style type='text/css'>"
    "      body { font: 16pt 'Gill Sans'; color: #1a004b; }"
    "      i { color: #822; }"
    "    </style>"
    "  </head>"
    "  <body>Here is some <i>formatting!</i> <a href='#'><font color='green'>Google</font></a><font color='red'> example text</font><a href='#'>YouTube</a><b> bold</b> and <i>italic</i></body>"
    "</html>";
    NSError *err = nil;
    NSAttributedString * attrStr = [[NSAttributedString alloc]
                                    initWithData: [htmlString dataUsingEncoding:NSUTF8StringEncoding]
                                    options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
                                    documentAttributes: nil
                                    error: &err];

    _viewAnimation.frame = CGRectMake(self.view.frame.size.width, _viewAnimation.frame.origin.y, _viewAnimation.frame.size.width, _viewAnimation.frame.size.height);
    _viewAnimation.hidden = NO;
    _lbAnimation.hidden = YES;
    CGRect rect = [attrStr boundingRectWithSize:CGSizeMake(FLT_MAX, _lbAnimation.frame.size.height)
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                               context:nil];

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveLinear  animations:^{
        _viewAnimation.frame=CGRectMake(0, _viewAnimation.frame.origin.y, _viewAnimation.frame.size.width, _viewAnimation.frame.size.height);
    } completion:^(BOOL finished)
     {
         _lbAnimation.hidden = NO;
         _lbAnimation.attributedText = attrStr;
         _lbAnimation.frame = CGRectMake(self.view.frame.size.width, _lbAnimation.frame.origin.y, rect.size.width, _viewAnimation.frame.size.height);

       CGFloat duration = 6;
       CGFloat ratio = _viewAnimation.frame.size.width / (rect.size.width + _viewAnimation.frame.size.width);

       [UIView animateWithDuration:duration * ratio delay:duration * (1-ratio) + 0.1f options:UIViewAnimationOptionCurveLinear animations:^{
         _viewAnimation.frame = CGRectMake(_viewAnimation.frame.origin.x, _viewAnimation.frame.origin.y, 0, _viewAnimation.frame.size.height);
       } completion:^(BOOL finished) {
         _viewAnimation.hidden = YES;
       }];

       [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
         _lbAnimation.frame=CGRectMake(-rect.size.width, _lbAnimation.frame.origin.y, rect.size.width, _lbAnimation.frame.size.height);

       } completion:^(BOOL finished)
        {

        }];

     }];
}

You can check my demo.

ContentLicense: CC BY-SA 4.0


问:
how to see if value entered is a number and not chars?

I want to know if someone entered a number and if they did the program continues but if they didn't the program terminates.
</p>

```<code>int main(void) {
    int i;

    printf("Enter a number: ");
    scanf("%d",&i);
    /*If input is not a number than terminate*/

    /*Otherwise continue*/
    else {
        if (test_prime(i))
            printf("Prime.\n");
        else
            printf("Not prime.\n");
    }
    return 0;
}
</code>```

<p>
If the user enters "hello" than I want program to terminate.
</p>

答:
Well the right way to do it will be something like this

```<code>int main(void) {
    int i;

    printf("Enter a number: ");
    if( scanf("%d",&i) != 1){
        fprintf(stderr,"%s\n","Error in input, input is not number");
        exit(1);
    }
    /*input is a number */

    if (test_prime(i))
       printf("%s\n","Prime.");
    else
       printf("%s\n","Not prime.");

    return 0;
}
</code>```

Checking the return value of scanf will help us know whether the scanf call was successful or not.

Alternatively you can use fgets() to get a line input and then parse it and check with functions like strtol etc.
Checking whether the input is a correct number with only applying isdigit() on it is not a solution.(As provided in other answer). You can check by giving an input 1234 and you will see the isdigit() solution fails here though it shouldn't.

To give you an idea why the isdigit solution won't work, from 7.4.1.5 standard we can see the quote

The isdigit function tests for any decimal-digit character.

And the decimal digit characters are 0,1...9.

Explanation of the solution provided:

If you look into the return value of the function it says

the function returns the number of input items assigned, which can be
fewer than provided for, or even zero, in the event of an early
matching failure.

This is what is being checked. And this works for multiple digit number also.

Body:
I want to know if someone entered a number and if they did the program continues but if they didn't the program terminates.

int main(void) {
    int i;

    printf("Enter a number: ");
    scanf("%d",&i);
    /*If input is not a number than terminate*/

    /*Otherwise continue*/
    else {
        if (test_prime(i))
            printf("Prime.\n");
        else
            printf("Not prime.\n");
    }
    return 0;
}

If the user enters "hello" than I want program to terminate.

Body:
Well the right way to do it will be something like this

int main(void) {
    int i;

    printf("Enter a number: ");
    if( scanf("%d",&i) != 1){
        fprintf(stderr,"%s\n","Error in input, input is not number");
        exit(1);
    }
    /*input is a number */

    if (test_prime(i))
       printf("%s\n","Prime.");
    else
       printf("%s\n","Not prime.");

    return 0;
}

Checking the return value of scanf will help us know whether the scanf call was successful or not.

Alternatively you can use fgets() to get a line input and then parse it and check with functions like strtol etc.
Checking whether the input is a correct number with only applying isdigit() on it is not a solution.(As provided in other answer). You can check by giving an input 1234 and you will see the isdigit() solution fails here though it shouldn't.

To give you an idea why the isdigit solution won't work, from 7.4.1.5 standard we can see the quote

The isdigit function tests for any decimal-digit character.

And the decimal digit characters are 0,1...9.

Explanation of the solution provided:

If you look into the return value of the function it says

the function returns the number of input items assigned, which can be
fewer than provided for, or even zero, in the event of an early
matching failure.

This is what is being checked. And this works for multiple digit number also.


问:
React-native-fbsdk building error
I am using to react-native-fbsdk. But last time when i tried to build my project on Android I have this error.

```<code>  Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.
     > Could not find com.android.support:appcompat-v7:27.0.1.
       Searched in the following locations:
           file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
           file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           file:/home/deema/Desktop/work/projects/dacebookTest/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
       Required by:
           dacebookTest:react-native-fbsdk:unspecified
     > Could not find com.android.support:appcompat-v7:27.0.1.
</code>```

There are more same errors with com.android.support v 27.
I tried to create new empty project and I have same errors.

答:
The key is in the error message shown in your case:

Searched in the following locations:
  file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/

I have had the same. Then I went to the location:

file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/

And found that there is no directory named 27.0.1 because in my case the latest buildTool was not downloaded. In my case I have had 27.0.0-alpha1.

So in both of my app build.gradle and in

node_modules/react-native-fbsdk/android/build.gradle

And replaced 27.0.1 with 27.0.0-alpha1 and build was successful.

Title: React-native-fbsdk building error

Body:
I am using to react-native-fbsdk. But last time when i tried to build my project on Android I have this error.

  Could not resolve all dependencies for configuration ':react-native-fbsdk:_debugPublishCopy'.
     > Could not find com.android.support:appcompat-v7:27.0.1.
       Searched in the following locations:
           file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.pom
           file:/home/deema/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
           file:/home/deema/Desktop/work/projects/dacebookTest/android/sdk-manager/com/android/support/appcompat-v7/27.0.1/appcompat-v7-27.0.1.jar
       Required by:
           dacebookTest:react-native-fbsdk:unspecified
     > Could not find com.android.support:appcompat-v7:27.0.1.

There are more same errors with com.android.support v 27.
I tried to create new empty project and I have same errors.


问:
Can I Push Data Native To React To Native in React Native?
I have crate one apps in react native for Android. I Want to call .java file at middle also transfer data. After again .java file to .js file. its possible. please help me.

答:
Yes you can do it. Here i am sharing few useful links for that.

Communication between Android and React Native

Communication between iOS and React Native

And in case of receiving data from java to react native you need to use callback

```<code>@ReactMethod
public void generate(final Callback successCallback)
{
    successCallback.invoke(<parameter you need to pass back>);
}
</code>```

and from React Native you need to call

```<code>AndroidModule.generate((<parameter passed from native module>) => {

})
</code>```

Body:
Yes you can do it. Here i am sharing few useful links for that.

Communication between Android and React Native

Communication between iOS and React Native

And in case of receiving data from java to react native you need to use callback

@ReactMethod
public void generate(final Callback successCallback)
{
    successCallback.invoke(<parameter you need to pass back>);
}

and from React Native you need to call

AndroidModule.generate((<parameter passed from native module>) => {

})


问:
How to hide all items in a private void method you've created?
so I created my own private void that can create buttons

```<code>        private void addButtonsToForm()
        {

           for (int i = 0; i < 26; i++)
         {
               Button currentNewButton = new Button();
               currentNewButton.Size = new Size(20, 30);
               currentNewButton.Location = new Point(20 + 25 * i, 420);
               currentNewButton.Text = ((char)(65 + i)).ToString();
               currentNewButton.Click += LetterClicked;
               letters[i] = currentNewButton;
               this.Controls.Add(letters[i]);
          }

        }
</code>```

The buttons are alphabets and will be accessed when the user wants to choose a letter ... but the problem is I'm trying to figure out how to go back when the user clicked or selected a button..

Originally I wanted to do was i could just hide all the buttons created and just make the previous button visible but for some reason it only hides the only button that is clicked

```<code>     //this is under private void LetterClicked(object sender, EventArgs e)
      Button selectedLetter = (Button)sender;
      selectedLetter.Enabled = false;
</code>```

i thought of stupid codes like
addbuttonstoform().visible = false; but of course that won't work.. but you might get an idea to where i want to go.... it's a bit confusing to explain... I'm new in c# and i'm creating a guess the word game so help could be great..

答:
Here is a working solution for your problem. See below:</p>

```<code>using System;
using System.Drawing;
using System.Windows.Forms;

namespace Alphabets
{
    public partial class Form1 : Form
    {
        private Button[] _letters;

        public Form1()
        {
            InitializeComponent();
            AddButtonsToForm();
        }

        private void AddButtonsToForm()
        {
            _letters = new Button[26];
            for (int i = 0; i < 26; i++)
            {
                Button currentNewButton = new Button
                {
                    Name = "BtnLetter"+ ((char)(65 + i)),
                    Size = new Size(20, 30),
                    Location = new Point(20 + 25 * i, 420),
                    Text = ((char) (65 + i)).ToString()
                };
                currentNewButton.Click += LetterClicked;
                _letters[i] = currentNewButton;
                this.Controls.Add(_letters[i]);
            }
        }

        private void LetterClicked(object sender, EventArgs e)
        {
            var selectedLetter = (Button) sender;
            //hide all other buttons
            foreach (var letter in _letters)
            {
                if (letter.Text != selectedLetter.Text)
                {
                    var buttons = this.Controls.Find("BtnLetter" + letter.Text, true);
                    buttons[0].Enabled = false;
                }
            }
        }
    }
}
</code>```

Body:
so I created my own private void that can create buttons

        private void addButtonsToForm()
        {

           for (int i = 0; i < 26; i++)
         {
               Button currentNewButton = new Button();
               currentNewButton.Size = new Size(20, 30);
               currentNewButton.Location = new Point(20 + 25 * i, 420);
               currentNewButton.Text = ((char)(65 + i)).ToString();
               currentNewButton.Click += LetterClicked;
               letters[i] = currentNewButton;
               this.Controls.Add(letters[i]);
          }

        }

The buttons are alphabets and will be accessed when the user wants to choose a letter ... but the problem is I'm trying to figure out how to go back when the user clicked or selected a button..

Originally I wanted to do was i could just hide all the buttons created and just make the previous button visible but for some reason it only hides the only button that is clicked

     //this is under private void LetterClicked(object sender, EventArgs e)
      Button selectedLetter = (Button)sender;
      selectedLetter.Enabled = false;

i thought of stupid codes like
addbuttonstoform().visible = false; but of course that won't work.. but you might get an idea to where i want to go.... it's a bit confusing to explain... I'm new in c# and i'm creating a guess the word game so help could be great..

Body:
Here is a working solution for your problem. See below:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Alphabets
{
    public partial class Form1 : Form
    {
        private Button[] _letters;

        public Form1()
        {
            InitializeComponent();
            AddButtonsToForm();
        }

        private void AddButtonsToForm()
        {
            _letters = new Button[26];
            for (int i = 0; i < 26; i++)
            {
                Button currentNewButton = new Button
                {
                    Name = "BtnLetter"+ ((char)(65 + i)),
                    Size = new Size(20, 30),
                    Location = new Point(20 + 25 * i, 420),
                    Text = ((char) (65 + i)).ToString()
                };
                currentNewButton.Click += LetterClicked;
                _letters[i] = currentNewButton;
                this.Controls.Add(_letters[i]);
            }
        }

        private void LetterClicked(object sender, EventArgs e)
        {
            var selectedLetter = (Button) sender;
            //hide all other buttons
            foreach (var letter in _letters)
            {
                if (letter.Text != selectedLetter.Text)
                {
                    var buttons = this.Controls.Find("BtnLetter" + letter.Text, true);
                    buttons[0].Enabled = false;
                }
            }
        }
    }
}


问:
How to get ip address of a server on Centos 7 in bash
Previously I used the following command in bash to find the main ip of my server

```<code>ipaddr=$(/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}' | grep -v '127.0.0.1')
</code>```

But in centos7 it no longer works since ifconfig isn't available and the command no longer works even if I install ifconfig using yum install net-tools

What is the equivalent command for centos 7

Thanks a lot

答:
Something like this - a riff on @maarten-vanlinthout's answer</p>

```<code>ip  -f inet a show eth0| grep inet| awk '{ print $2}' | cut -d/ -f1
</code>```

Body:
Previously I used the following command in bash to find the main ip of my server

ipaddr=$(/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}' | grep -v '127.0.0.1')

But in centos7 it no longer works since ifconfig isn't available and the command no longer works even if I install ifconfig using yum install net-tools

What is the equivalent command for centos 7

Thanks a lot

Body:
Something like this - a riff on @maarten-vanlinthout's answer

ip  -f inet a show eth0| grep inet| awk '{ print $2}' | cut -d/ -f1


答:
Use isdigit() from  ctype header file

This function will return 0 if the entered value is non numeric character.

In Your Case,

```<code>#include<ctype.h>
if(isdigit(i)==0)
{  // Terminate
}
else
{  if (test_prime(i))
          printf("Prime.\n");
   else
        printf("Not prime.\n");
}
</code>```

For More reference Visit
https://www.programiz.com/c-programming/library-function/ctype.h/isdigit

Title: how to see if value entered is a number and not chars?

Body:
Use isdigit() from  ctype header file

This function will return 0 if the entered value is non numeric character.

In Your Case,

#include<ctype.h>
if(isdigit(i)==0)
{  // Terminate
}
else
{  if (test_prime(i))
          printf("Prime.\n");
   else
        printf("Not prime.\n");
}

For More reference Visit
https://www.programiz.com/c-programming/library-function/ctype.h/isdigit


问:
GUI edge to node recursive path not finding first index of path
I wrote a program that allows a user to add nodes and connect them with edges with a GUI interface.  The first node is always labeled "0".  When I call the findPath method however it shows the entire path appropriately just lacking the 0.  For example if I want to find the path from 0-4, and they're all connected numerically it will show [1,2,3,4].  To get a proper reading of the path after connecting the nodes you need to hit the print adjacency button.  Everything else is running as expected but I can't seem to figure out why this won't add the first node.

Thanks Guys!

```<code>    import javax.swing.JFrame;//imports JFrame package

    public class Graph//class header
    {
       public static void main (String[] args)//main method
       {
          JFrame frame = new JFrame ("Directed Graph");//sets variable frame to a JFrame object and titles it
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);//exits application when it is closed
          frame.getContentPane().add (new GraphPanel());//adding GraphPanel() to the frame
          frame.setLocationRelativeTo(null);//sets location to the center
          frame.pack();//packs the frame, fits everything inside
          frame.setVisible(true);//makes frame visible
       }
    }

import java.util.ArrayList;//all of these are the required to get classes from other packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

public class GraphPanel extends JPanel
{
    private final int SIZE = 10;  // radius of each node
    private double alpha; // double variable to define later
    private JButton print, create, delete, path1; //allpath;//button variables
    private JTextField label, label1;
    boolean mode = true;//sets boolean for entire class to true, until later when I define it as false for certain methods to be complete

    String x1, y1;
    String str1 = new String("Mode Chosen Is : create" );//when you choose create it will print this instead
    String str2 = new String("Mode Chosen Is : delete" );//when you choose delete it will print this

    int x, y;
    int mode1 = 1; // int mode1 variable, will comment why i need this when it is later defined/changed

    private Point point1 = null, point2 = null, point3 = null;//makes pointers null, i added a third pointer to put the distance from the first drawn string at the top right, but no longer needed it
    //keeping it incase I wanted to add it again

    private ArrayList<Point> nodeList;   // Graph nodes
    private ArrayList<Edge> edgeList;    // Graph edges

    static private int[][] a = new int[100][100];  // Graph adjacency matrix
    static ArrayList<Integer> path = new ArrayList<Integer>();

    public GraphPanel()
    {

        nodeList = new ArrayList<Point>();//declares ArrayList<Point>
        edgeList = new ArrayList<Edge>();//declares ArrayList<Edge>

        GraphListener listener = new GraphListener();//assigns 'listener' to a Graphlistener object
        addMouseListener (listener);//accepts and reads mouseListener methods to the GraphListener object
        addMouseMotionListener (listener);//accepts and reads MouseMotionListener methods to the GraphListener object

        label = new JTextField (1);
        label1 = new JTextField (1);

        //allpath = new JButton ("Find All Paths");
        path1 = new JButton ("Find Path");//path button
        create = new JButton("Create");//declares 'create' as a JButton object with text on it that says 'create'
        delete = new JButton("Delete");//declares 'delete' as a JButton object with text that says 'delete'
        JButton print = new JButton("Print adjacency matrix");//declares 'print' as a JButton object with text that reads 'print adjacency matrix'

        print.addActionListener (new ButtonListener());//adds an action listener to the print button from the buttonlistener object
        create.addActionListener (new ButtonListener1());//adds an actionListener to the create button from the buttonlistener1 object
        delete.addActionListener (new ButtonListener2());//adds an actionliseneer to the delete button from the buttonlistener2 object
        path1.addActionListener (new ButtonListener3());//adds button that will find path of nodes
        //allpath.addActionListener (new ButtonListener4());

        setBackground (Color.black);//sets backround as black
        setPreferredSize (new Dimension(400, 300));//this is preferred size of graphpanel
        add(print);//these next six add()'s add each button to GraphPanel
        add(delete);//
        add(create);//
        //add(allpath);
        add(path1);
        add(label);
        add(label1);
    }

    public static boolean findPath(int x, int y) //boolean method findpath that takes two ints as parameters
    {
        boolean found = false;

        if (a[x][y]==1) //base case
        {
            //System.out.println(x + " -> " + y);//prints node -> node
            found = true;//path is found
            path.add(0,y);
        }
        else
        {
            int z;
            for (z=0; !found& z<a.length; z++)
            {
                if (a[x][z]==1)
                {
                    a[x][z]=2;
                    found = findPath(z,y);

                }
                if (found)
                {
                    //System.out.println(x + " -> " + z);
                    path.add(0,z);
                }

            }
        }

        if (!found){
            System.out.println("Path Does Not Exist");
        }
        return found;
    }

    // public static ArrayList findPath1(int x, int y, ArrayList path)
    // {
    // System.out.println("CALL FIND: " + path);
    // ArrayList path2 = null;
    // if (a[x][y]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(y);
    // System.out.println("EXIT BASE: " + path3);
    // path2 = path3;
    // }
    // else
    // {
    // int z;
    // for (z=0; z<a.length; z++)
    // if (a[x][z]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(z);
    // path3 = findPath1(z,y,path3);
    // System.out.println("EXIT RECU: " + path);
    // path2 = path3;
    // }
    // }
    // return path2;
    // }
    //  Draws the graph
    public void paintComponent (Graphics page)
    {
        super.paintComponent(page);//using parent methods

        // Draws the edge that is being dragged
        page.setColor (Color.green);//setting color of what will be drawn to green
        if (mode1 == 1)//if mode1 is set to 1, which is when the create button is selected
        {
            page.drawString(str1, 125, 75);//then this is printed
        }
        if (mode1 == 2)//if mode1 is set to 2, which is when the delete button is selected
        {
            page.drawString(str2, 125, 75);//then this is printed
        }
        if (point1 != null && point2 != null)//if and only if both points are not null
        {
            page.drawLine (point1.x, point1.y, point2.x, point2.y);//then it draws the line from between point1(x, y cords), and point2(x, y cords)
            page.fillOval (point2.x-3, point2.y-3, 6, 6);//fills this oval by the rectangle it is specified from
        }
        // Draws the nodes
        for (int i=0; i<nodeList.size(); i++) //for loop going through the nodeList ArrayList
        {
            page.setColor (Color.green);//color is set to green
            page.fillOval (nodeList.get(i).x-SIZE, nodeList.get(i).y-SIZE, SIZE*2, SIZE*2);//fills oval by subtracting the SIZE from the x, y and setting the height and width as two times the SIZE
            page.setColor (Color.black);//sets next line to black
            page.drawString (String.valueOf(i), nodeList.get(i).x-SIZE/2, nodeList.get(i).y+SIZE/2);//writes inside the node what number index it is from the ArrayList with black text
        }
        // Draws the edges
        for (int i=0; i<edgeList.size(); i++) // for loop going through the edgeList ArrayList
        {
            page.setColor (Color.green);//sets the next line to green
            page.drawLine (edgeList.get(i).a.x, edgeList.get(i).a.y,edgeList.get(i).b.x, edgeList.get(i).b.y);//draws the line from x and y cords of where it starts to end
            //page.fillOval (edgeList.get(i).b.x-3, edgeList.get(i).b.y-3, 6, 6);

            //page.drawString (String.valueOf(point1.x*(point2.y-point3.y)+point2.x*(point3.y-point1.y)+point3.x*(point1.y-point2.y)), 5, 15);

            alpha = Math.atan((double)(edgeList.get(i).b.y-edgeList.get(i).a.y)/(edgeList.get(i).b.x-edgeList.get(i).a.x));//alpha = b.y-a.y cords/b.x-a.x chords as a double variable
            if (edgeList.get(i).a.x > edgeList.get(i).b.x)//if the x chord of a is greater than the x cordinate of b
            {
                alpha = alpha + Math.PI;//then alpha = previously defined alpha multiplied by PI
            }
            if (edgeList.get(i).a.x < edgeList.get(i).b.x && edgeList.get(i).a.y > edgeList.get(i).b.y)//if a.x is less than b.x and a.y is less than b.y
            {
                alpha = alpha + 2*Math.PI;//then alpha becomes the previously defined alpha multiplied by 2 PI
            }
            arrow(page,edgeList.get(i).b.x,edgeList.get(i).b.y,0,1.57-alpha);//arrow method, taking a x(edgeList.get(i).b.x, y(edgeList.get(i).b.y, length = 0 so arrow is at the
            // very end of the drawn line subtracted by a double aplha
        }
    }

    // arrow method to call when making an arrow
    private void arrow(Graphics page, int x, int y, int len, double alpha)//arrow method, taking a x, y, length and double parameter
    {
        page.setColor (Color.green);//sets arrow to green
        int x1 = x+(int)(len*Math.sin(alpha));//x1 is set to x plus length *sin of alpha
        int y1 = y+(int)(len*Math.cos(alpha));//y1 is set to y plus the length * cosin of alpha
        page.drawLine (x, y, x1, y1);//drawa the x and y, and then previously defined x1, and y1
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+2.5)), y1+(int)(20*Math.cos(alpha+2.5)));//arithmatic to draw one side of the line for the arrow
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+3.7)), y1+(int)(20*Math.cos(alpha+3.7)));//arithmatic to draw the corresponding line for the arrow to complete the arrow
    }

    //  The listener for mouse events.
    private class GraphListener implements MouseListener, MouseMotionListener//GraphListener which implements MouseListener and MouseMotionListener, meaning it takes methods from both of those classes
    {
        public void mouseClicked (MouseEvent event)//when mouse is clicked and released
        {
            if (mode == true)//if the mode is true
            {
                nodeList.add(event.getPoint());//the current point to the nodeList
                repaint();//whenever you change the look of a componenet you call this method
            }
            if (mode == false)//if boolean mode is false
            {
                for (int i=0; i<nodeList.size(); i++)//for loop to go through the nodeList ArrayList
                {
                    if (distance(nodeList.get(i), event.getPoint()) < SIZE)//if the distance between a specific node and the pointer is less than the radius of the node (SIZE)
                        nodeList.remove(i);//then remove that node
                }
                for (int i=0; i<edgeList.size(); i++)
                {
                    if (distance(edgeList.get(i).a, event.getPoint())+distance(event.getPoint(), edgeList.get(i).b)-distance(edgeList.get(i).a, edgeList.get(i).b) < SIZE)
                    //if the (distance between starting point of that edgelist index and the current point) plus (the distance between the current point and ending point of that edgeList index)
                    //subtracted by the (distance of the starting and ending point of that edgeList index)(AB+BC-AC) is all less than the size
                        edgeList.remove(i);//then remove that index
                }
            }
        }

        public void mousePressed (MouseEvent event)//when the mouse is pressed down
        {
            if (mode == true)//if the mode is true
            {
                point1 = event.getPoint();//you start that point
            }
        }

        public void mouseDragged (MouseEvent event)//when the mouse is dragged while pressed down
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you get the second point
                repaint();//must use this method because you are making a change to the component
            }
        }

        public void mouseReleased (MouseEvent event)//when the mouse is released after being pressed (not to be confused with a click)
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you set point2 to where that point landed
                if (point1.x != point2.x && point1.y != point2.y)//if the points are not in the same spots
                {
                    edgeList.add(new Edge(point1,point2));//then you add a new edgeList element to the ArrayList, by definition of Edge() object
                    repaint();//must use this method because changes to component have been made
                }
            }

        }

        public void mouseMoved (MouseEvent event)// if the mouse is moved, without it being clicked (not to be confused by mouseDragged)
        {
            point3 = event.getPoint();//point three is set to be where the mouse is at the current time(used this to find the distance of original edge drawn, keeping here incase I want to add)
            repaint();//must use this method because changes were made to component

        }

        //  Empty definitions for unused event methods.
        public void mouseEntered (MouseEvent event){}//when the mouse enters a component

        public void mouseExited (MouseEvent event) {}//when the mouse exits a component

        private int distance(Point p1, Point p2) //private distance formula but inside of this class so i was able to use it for determining how to erase nodes and edges
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));//square root of x cordinants of first point minus second point times its self plus the y coordinates
            //of first point minus second point times itself
        }
    }
    // Represents the graph edges
    private class Edge //defines how edges are made
    {
        Point a, b;

        public Edge(Point a, Point b)
        {
            this.a = a;
            this.b = b;
        }
    }

    private class ButtonListener implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {

            if (event.getSource()== create)
            {
                mode = true;
                mode1 = 1;
            }
            if (event.getSource()==delete)
            {
                mode = !true;
                mode1 = 2;

            }

            // Initializes graph adjacency matrix
            for (int i=0; i<nodeList.size(); i++)
                for (int j=0; j<nodeList.size(); j++) a[i][j]=0;

            // Includes the edges in the graph adjacency matrix
            for (int i=0; i<edgeList.size(); i++)
            {
                for (int j=0; j<nodeList.size(); j++)
                    if (distance(nodeList.get(j),edgeList.get(i).a)<=SIZE+3)
                        for (int k=0; k<nodeList.size(); k++)
                            if (distance(nodeList.get(k),edgeList.get(i).b)<=SIZE+3)
                            {
                                System.out.println(j+"->"+k);
                                a[j][k]=1;
                            }
            }

            if (event.getSource()==print)
            {

                // Prints the graph adjacency matrix
                for (int i=0; i<nodeList.size(); i++)
                {
                    for (int j=0; j<nodeList.size(); j++)
                        System.out.print(a[i][j]+"\t");
                    System.out.println();
                }
            }
        }
        // Euclidean distance function
        private int distance(Point p1, Point p2)
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
        }
    }

    private class ButtonListener1 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== create)//if create button is selected
            {
                mode = true;//then the mode is set to true
                mode1 = 1;//and mode1 is set to 1
            }
        }
    }

    private class ButtonListener2 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== delete)//if create button is selected
            {
                mode = !true;//then the mode is set to true
                mode1 = 2;//and mode1 is set to 2, which would change the string that is output
            }
        }
    }

    private class ButtonListener3 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            x1 = label.getText();
            y1 = label1.getText();
            x = Integer.parseInt(x1);
            y = Integer.parseInt(y1);

            System.out.println("Path from " +x+" to " +y);
            System.out.println(findPath(x,y));
            System.out.println(path);

        }
    }
</code>```

答:
I was able to find it, and of course it was the smallest mistake I missed, adding this because in case anyone else has the same problem I hope this helps.  The main differences are in my buttonlistener3 class but I'll add the whole thing again just incase this helps anyone out.</p>

```<code>import java.util.ArrayList;//all of these are the required to get classes from other packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

public class GraphPanel extends JPanel
{
    private final int SIZE = 10;  // radius of each node
    private double alpha; // double variable to define later
    private JButton print, create, delete, path1; //allpath;//button variables
    private JTextField label, label1;
    boolean mode = true;//sets boolean for entire class to true, until later when I define it as false for certain methods to be complete

    String x1, y1;
    String str1 = new String("Mode Chosen Is : create" );//when you choose create it will print this instead
    String str2 = new String("Mode Chosen Is : delete" );//when you choose delete it will print this

    int x, y;
    int mode1 = 1; // int mode1 variable, will comment why i need this when it is later defined/changed

    private Point point1 = null, point2 = null, point3 = null;//makes pointers null, i added a third pointer to put the distance from the first drawn string at the top right, but no longer needed it
    //keeping it incase I wanted to add it again

    private ArrayList<Point> nodeList;   // Graph nodes
    private ArrayList<Edge> edgeList;    // Graph edges

    static private int[][] a = new int[100][100];  // Graph adjacency matrix
    static ArrayList<Integer> path = new ArrayList<Integer>();

    public GraphPanel()
    {

        nodeList = new ArrayList<Point>();//declares ArrayList<Point>
        edgeList = new ArrayList<Edge>();//declares ArrayList<Edge>

        GraphListener listener = new GraphListener();//assigns 'listener' to a Graphlistener object
        addMouseListener (listener);//accepts and reads mouseListener methods to the GraphListener object
        addMouseMotionListener (listener);//accepts and reads MouseMotionListener methods to the GraphListener object

        label = new JTextField (1);
        label1 = new JTextField (1);

        //allpath = new JButton ("Find All Paths");
        path1 = new JButton ("Find Path");//path button
        create = new JButton("Create");//declares 'create' as a JButton object with text on it that says 'create'
        delete = new JButton("Delete");//declares 'delete' as a JButton object with text that says 'delete'
        JButton print = new JButton("Print adjacency matrix");//declares 'print' as a JButton object with text that reads 'print adjacency matrix'

        print.addActionListener (new ButtonListener());//adds an action listener to the print button from the buttonlistener object
        create.addActionListener (new ButtonListener1());//adds an actionListener to the create button from the buttonlistener1 object
        delete.addActionListener (new ButtonListener2());//adds an actionliseneer to the delete button from the buttonlistener2 object
        path1.addActionListener (new ButtonListener3());//adds button that will find path of nodes
        //allpath.addActionListener (new ButtonListener4());

        setBackground (Color.black);//sets backround as black
        setPreferredSize (new Dimension(400, 300));//this is preferred size of graphpanel
        add(print);//these next six add()'s add each button to GraphPanel
        add(delete);//
        add(create);//
        //add(allpath);
        add(path1);
        add(label);
        add(label1);
    }

    public static boolean findPath(int x, int y) //boolean method findpath that takes two ints as parameters
    {
        boolean found = false;

        if (a[x][y]==1) //base case
        {
            //System.out.println(x + " -> " + y);//prints node -> node
            found = true;//path is found
            path.add(0,y);
        }
        else
        {
            int z;
            for (z=0; !found& z<a.length; z++)
            {
                if (a[x][z]==1)
                {
                    a[x][z]=2;
                    found = findPath(z,y);

                }
                if (found)
                {
                    //System.out.println(x + " -> " + z);
                    path.add(0,z);
                }

            }
        }
        return found;
    }

    // public static ArrayList findPath1(int x, int y, ArrayList path)
    // {
    // System.out.println("CALL FIND: " + path);
    // ArrayList path2 = null;
    // if (a[x][y]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(y);
    // System.out.println("EXIT BASE: " + path3);
    // path2 = path3;
    // }
    // else
    // {
    // int z;
    // for (z=0; z<a.length; z++)
    // if (a[x][z]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(z);
    // path3 = findPath1(z,y,path3);
    // System.out.println("EXIT RECU: " + path);
    // path2 = path3;
    // }
    // }
    // return path2;
    // }
    //  Draws the graph
    public void paintComponent (Graphics page)
    {
        super.paintComponent(page);//using parent methods

        // Draws the edge that is being dragged
        page.setColor (Color.green);//setting color of what will be drawn to green
        if (mode1 == 1)//if mode1 is set to 1, which is when the create button is selected
        {
            page.drawString(str1, 125, 75);//then this is printed
        }
        if (mode1 == 2)//if mode1 is set to 2, which is when the delete button is selected
        {
            page.drawString(str2, 125, 75);//then this is printed
        }
        if (point1 != null && point2 != null)//if and only if both points are not null
        {
            page.drawLine (point1.x, point1.y, point2.x, point2.y);//then it draws the line from between point1(x, y cords), and point2(x, y cords)
            page.fillOval (point2.x-3, point2.y-3, 6, 6);//fills this oval by the rectangle it is specified from
        }
        // Draws the nodes
        for (int i=0; i<nodeList.size(); i++) //for loop going through the nodeList ArrayList
        {
            page.setColor (Color.green);//color is set to green
            page.fillOval (nodeList.get(i).x-SIZE, nodeList.get(i).y-SIZE, SIZE*2, SIZE*2);//fills oval by subtracting the SIZE from the x, y and setting the height and width as two times the SIZE
            page.setColor (Color.black);//sets next line to black
            page.drawString (String.valueOf(i), nodeList.get(i).x-SIZE/2, nodeList.get(i).y+SIZE/2);//writes inside the node what number index it is from the ArrayList with black text
        }
        // Draws the edges
        for (int i=0; i<edgeList.size(); i++) // for loop going through the edgeList ArrayList
        {
            page.setColor (Color.green);//sets the next line to green
            page.drawLine (edgeList.get(i).a.x, edgeList.get(i).a.y,edgeList.get(i).b.x, edgeList.get(i).b.y);//draws the line from x and y cords of where it starts to end
            //page.fillOval (edgeList.get(i).b.x-3, edgeList.get(i).b.y-3, 6, 6);

            //page.drawString (String.valueOf(point1.x*(point2.y-point3.y)+point2.x*(point3.y-point1.y)+point3.x*(point1.y-point2.y)), 5, 15);

            alpha = Math.atan((double)(edgeList.get(i).b.y-edgeList.get(i).a.y)/(edgeList.get(i).b.x-edgeList.get(i).a.x));//alpha = b.y-a.y cords/b.x-a.x chords as a double variable
            if (edgeList.get(i).a.x > edgeList.get(i).b.x)//if the x chord of a is greater than the x cordinate of b
            {
                alpha = alpha + Math.PI;//then alpha = previously defined alpha multiplied by PI
            }
            if (edgeList.get(i).a.x < edgeList.get(i).b.x && edgeList.get(i).a.y > edgeList.get(i).b.y)//if a.x is less than b.x and a.y is less than b.y
            {
                alpha = alpha + 2*Math.PI;//then alpha becomes the previously defined alpha multiplied by 2 PI
            }
            arrow(page,edgeList.get(i).b.x,edgeList.get(i).b.y,0,1.57-alpha);//arrow method, taking a x(edgeList.get(i).b.x, y(edgeList.get(i).b.y, length = 0 so arrow is at the
            // very end of the drawn line subtracted by a double aplha
        }
    }

    // arrow method to call when making an arrow
    private void arrow(Graphics page, int x, int y, int len, double alpha)//arrow method, taking a x, y, length and double parameter
    {
        page.setColor (Color.green);//sets arrow to green
        int x1 = x+(int)(len*Math.sin(alpha));//x1 is set to x plus length *sin of alpha
        int y1 = y+(int)(len*Math.cos(alpha));//y1 is set to y plus the length * cosin of alpha
        page.drawLine (x, y, x1, y1);//drawa the x and y, and then previously defined x1, and y1
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+2.5)), y1+(int)(20*Math.cos(alpha+2.5)));//arithmatic to draw one side of the line for the arrow
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+3.7)), y1+(int)(20*Math.cos(alpha+3.7)));//arithmatic to draw the corresponding line for the arrow to complete the arrow
    }

    //  The listener for mouse events.
    private class GraphListener implements MouseListener, MouseMotionListener//GraphListener which implements MouseListener and MouseMotionListener, meaning it takes methods from both of those classes
    {
        public void mouseClicked (MouseEvent event)//when mouse is clicked and released
        {
            if (mode == true)//if the mode is true
            {
                nodeList.add(event.getPoint());//the current point to the nodeList
                repaint();//whenever you change the look of a componenet you call this method
            }
            if (mode == false)//if boolean mode is false
            {
                for (int i=0; i<nodeList.size(); i++)//for loop to go through the nodeList ArrayList
                {
                    if (distance(nodeList.get(i), event.getPoint()) < SIZE)//if the distance between a specific node and the pointer is less than the radius of the node (SIZE)
                        nodeList.remove(i);//then remove that node
                }
                for (int i=0; i<edgeList.size(); i++)
                {
                    if (distance(edgeList.get(i).a, event.getPoint())+distance(event.getPoint(), edgeList.get(i).b)-distance(edgeList.get(i).a, edgeList.get(i).b) < SIZE)
                    //if the (distance between starting point of that edgelist index and the current point) plus (the distance between the current point and ending point of that edgeList index)
                    //subtracted by the (distance of the starting and ending point of that edgeList index)(AB+BC-AC) is all less than the size
                        edgeList.remove(i);//then remove that index
                }
            }
        }

        public void mousePressed (MouseEvent event)//when the mouse is pressed down
        {
            if (mode == true)//if the mode is true
            {
                point1 = event.getPoint();//you start that point
            }
        }

        public void mouseDragged (MouseEvent event)//when the mouse is dragged while pressed down
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you get the second point
                repaint();//must use this method because you are making a change to the component
            }
        }

        public void mouseReleased (MouseEvent event)//when the mouse is released after being pressed (not to be confused with a click)
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you set point2 to where that point landed
                if (point1.x != point2.x && point1.y != point2.y)//if the points are not in the same spots
                {
                    edgeList.add(new Edge(point1,point2));//then you add a new edgeList element to the ArrayList, by definition of Edge() object
                    repaint();//must use this method because changes to component have been made
                }
            }

        }

        public void mouseMoved (MouseEvent event)// if the mouse is moved, without it being clicked (not to be confused by mouseDragged)
        {
            point3 = event.getPoint();//point three is set to be where the mouse is at the current time(used this to find the distance of original edge drawn, keeping here incase I want to add)
            repaint();//must use this method because changes were made to component

        }

        //  Empty definitions for unused event methods.
        public void mouseEntered (MouseEvent event){}//when the mouse enters a component

        public void mouseExited (MouseEvent event) {}//when the mouse exits a component

        private int distance(Point p1, Point p2) //private distance formula but inside of this class so i was able to use it for determining how to erase nodes and edges
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));//square root of x cordinants of first point minus second point times its self plus the y coordinates
            //of first point minus second point times itself
        }
    }
    // Represents the graph edges
    private class Edge //defines how edges are made
    {
        Point a, b;

        public Edge(Point a, Point b)
        {
            this.a = a;
            this.b = b;
        }
    }

    private class ButtonListener implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {

            if (event.getSource()== create)
            {
                mode = true;
                mode1 = 1;
            }
            if (event.getSource()==delete)
            {
                mode = !true;
                mode1 = 2;

            }

            // Initializes graph adjacency matrix
            for (int i=0; i<nodeList.size(); i++)
                for (int j=0; j<nodeList.size(); j++) a[i][j]=0;

            // Includes the edges in the graph adjacency matrix
            for (int i=0; i<edgeList.size(); i++)
            {
                for (int j=0; j<nodeList.size(); j++)
                    if (distance(nodeList.get(j),edgeList.get(i).a)<=SIZE+3)
                        for (int k=0; k<nodeList.size(); k++)
                            if (distance(nodeList.get(k),edgeList.get(i).b)<=SIZE+3)
                            {
                                System.out.println(j+"->"+k);

                                a[j][k]=1;
                            }
            }

            if (event.getSource()==print)
            {

                // Prints the graph adjacency matrix
                for (int i=0; i<nodeList.size(); i++)
                {
                    for (int j=0; j<nodeList.size(); j++)
                        System.out.print(a[i][j]+"\t");
                    System.out.println();
                }
            }
        }
        // Euclidean distance function
        private int distance(Point p1, Point p2)
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
        }
    }

    private class ButtonListener1 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== create)//if create button is selected
            {
                mode = true;//then the mode is set to true
                mode1 = 1;//and mode1 is set to 1
            }
        }
    }

    private class ButtonListener2 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== delete)//if create button is selected
            {
                mode = !true;//then the mode is set to true
                mode1 = 2;//and mode1 is set to 2, which would change the string that is output
            }
        }
    }

    private class ButtonListener3 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            x1 = label.getText();
            y1 = label1.getText();
            x = Integer.parseInt(x1);
            y = Integer.parseInt(y1);
            System.out.println("Path from " +x+" to " +y);
            System.out.println(findPath(x,y));
            path.add(0,x);
            System.out.println(path);
            path.clear();
        }
    }

    // private class ButtonListener4 implements ActionListener
    // {
    // public void actionPerformed (ActionEvent event)
    // {
    // x1 = label.getText();
    // y1 = label1.getText();
    // x = Integer.parseInt(x1);
    // y = Integer.parseInt(y1);
    // System.out.println("Path from " +x+" to " +y);
    // System.out.println(findPath1(x,y,path));
    // System.out.println(path);
    // }
    // }
}
</code>```

Body:
I wrote a program that allows a user to add nodes and connect them with edges with a GUI interface.  The first node is always labeled "0".  When I call the findPath method however it shows the entire path appropriately just lacking the 0.  For example if I want to find the path from 0-4, and they're all connected numerically it will show [1,2,3,4].  To get a proper reading of the path after connecting the nodes you need to hit the print adjacency button.  Everything else is running as expected but I can't seem to figure out why this won't add the first node.

Thanks Guys!

    import javax.swing.JFrame;//imports JFrame package

    public class Graph//class header
    {
       public static void main (String[] args)//main method
       {
          JFrame frame = new JFrame ("Directed Graph");//sets variable frame to a JFrame object and titles it
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);//exits application when it is closed
          frame.getContentPane().add (new GraphPanel());//adding GraphPanel() to the frame
          frame.setLocationRelativeTo(null);//sets location to the center
          frame.pack();//packs the frame, fits everything inside
          frame.setVisible(true);//makes frame visible
       }
    }

import java.util.ArrayList;//all of these are the required to get classes from other packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

public class GraphPanel extends JPanel
{
    private final int SIZE = 10;  // radius of each node
    private double alpha; // double variable to define later
    private JButton print, create, delete, path1; //allpath;//button variables
    private JTextField label, label1;
    boolean mode = true;//sets boolean for entire class to true, until later when I define it as false for certain methods to be complete

    String x1, y1;
    String str1 = new String("Mode Chosen Is : create" );//when you choose create it will print this instead
    String str2 = new String("Mode Chosen Is : delete" );//when you choose delete it will print this

    int x, y;
    int mode1 = 1; // int mode1 variable, will comment why i need this when it is later defined/changed

    private Point point1 = null, point2 = null, point3 = null;//makes pointers null, i added a third pointer to put the distance from the first drawn string at the top right, but no longer needed it
    //keeping it incase I wanted to add it again

    private ArrayList<Point> nodeList;   // Graph nodes
    private ArrayList<Edge> edgeList;    // Graph edges

    static private int[][] a = new int[100][100];  // Graph adjacency matrix
    static ArrayList<Integer> path = new ArrayList<Integer>();

    public GraphPanel()
    {

        nodeList = new ArrayList<Point>();//declares ArrayList<Point>
        edgeList = new ArrayList<Edge>();//declares ArrayList<Edge>

        GraphListener listener = new GraphListener();//assigns 'listener' to a Graphlistener object
        addMouseListener (listener);//accepts and reads mouseListener methods to the GraphListener object
        addMouseMotionListener (listener);//accepts and reads MouseMotionListener methods to the GraphListener object

        label = new JTextField (1);
        label1 = new JTextField (1);

        //allpath = new JButton ("Find All Paths");
        path1 = new JButton ("Find Path");//path button
        create = new JButton("Create");//declares 'create' as a JButton object with text on it that says 'create'
        delete = new JButton("Delete");//declares 'delete' as a JButton object with text that says 'delete'
        JButton print = new JButton("Print adjacency matrix");//declares 'print' as a JButton object with text that reads 'print adjacency matrix'

        print.addActionListener (new ButtonListener());//adds an action listener to the print button from the buttonlistener object
        create.addActionListener (new ButtonListener1());//adds an actionListener to the create button from the buttonlistener1 object
        delete.addActionListener (new ButtonListener2());//adds an actionliseneer to the delete button from the buttonlistener2 object
        path1.addActionListener (new ButtonListener3());//adds button that will find path of nodes
        //allpath.addActionListener (new ButtonListener4());

        setBackground (Color.black);//sets backround as black
        setPreferredSize (new Dimension(400, 300));//this is preferred size of graphpanel
        add(print);//these next six add()'s add each button to GraphPanel
        add(delete);//
        add(create);//
        //add(allpath);
        add(path1);
        add(label);
        add(label1);
    }

    public static boolean findPath(int x, int y) //boolean method findpath that takes two ints as parameters
    {
        boolean found = false;

        if (a[x][y]==1) //base case
        {
            //System.out.println(x + " -> " + y);//prints node -> node
            found = true;//path is found
            path.add(0,y);
        }
        else
        {
            int z;
            for (z=0; !found& z " + z);
                    path.add(0,z);
                }

            }
        }

        if (!found){
            System.out.println("Path Does Not Exist");
        }
        return found;
    }

    // public static ArrayList findPath1(int x, int y, ArrayList path)
    // {
    // System.out.println("CALL FIND: " + path);
    // ArrayList path2 = null;
    // if (a[x][y]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(y);
    // System.out.println("EXIT BASE: " + path3);
    // path2 = path3;
    // }
    // else
    // {
    // int z;
    // for (z=0; z<a.length; z++)
    // if (a[x][z]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(z);
    // path3 = findPath1(z,y,path3);
    // System.out.println("EXIT RECU: " + path);
    // path2 = path3;
    // }
    // }
    // return path2;
    // }
    //  Draws the graph
    public void paintComponent (Graphics page)
    {
        super.paintComponent(page);//using parent methods

        // Draws the edge that is being dragged
        page.setColor (Color.green);//setting color of what will be drawn to green
        if (mode1 == 1)//if mode1 is set to 1, which is when the create button is selected
        {
            page.drawString(str1, 125, 75);//then this is printed
        }
        if (mode1 == 2)//if mode1 is set to 2, which is when the delete button is selected
        {
            page.drawString(str2, 125, 75);//then this is printed
        }
        if (point1 != null && point2 != null)//if and only if both points are not null
        {
            page.drawLine (point1.x, point1.y, point2.x, point2.y);//then it draws the line from between point1(x, y cords), and point2(x, y cords)
            page.fillOval (point2.x-3, point2.y-3, 6, 6);//fills this oval by the rectangle it is specified from
        }
        // Draws the nodes
        for (int i=0; i<nodeList.size(); i++) //for loop going through the nodeList ArrayList
        {
            page.setColor (Color.green);//color is set to green
            page.fillOval (nodeList.get(i).x-SIZE, nodeList.get(i).y-SIZE, SIZE*2, SIZE*2);//fills oval by subtracting the SIZE from the x, y and setting the height and width as two times the SIZE
            page.setColor (Color.black);//sets next line to black
            page.drawString (String.valueOf(i), nodeList.get(i).x-SIZE/2, nodeList.get(i).y+SIZE/2);//writes inside the node what number index it is from the ArrayList with black text
        }
        // Draws the edges
        for (int i=0; i<edgeList.size(); i++) // for loop going through the edgeList ArrayList
        {
            page.setColor (Color.green);//sets the next line to green
            page.drawLine (edgeList.get(i).a.x, edgeList.get(i).a.y,edgeList.get(i).b.x, edgeList.get(i).b.y);//draws the line from x and y cords of where it starts to end
            //page.fillOval (edgeList.get(i).b.x-3, edgeList.get(i).b.y-3, 6, 6);

            //page.drawString (String.valueOf(point1.x*(point2.y-point3.y)+point2.x*(point3.y-point1.y)+point3.x*(point1.y-point2.y)), 5, 15);

            alpha = Math.atan((double)(edgeList.get(i).b.y-edgeList.get(i).a.y)/(edgeList.get(i).b.x-edgeList.get(i).a.x));//alpha = b.y-a.y cords/b.x-a.x chords as a double variable
            if (edgeList.get(i).a.x > edgeList.get(i).b.x)//if the x chord of a is greater than the x cordinate of b
            {
                alpha = alpha + Math.PI;//then alpha = previously defined alpha multiplied by PI
            }
            if (edgeList.get(i).a.x < edgeList.get(i).b.x && edgeList.get(i).a.y > edgeList.get(i).b.y)//if a.x is less than b.x and a.y is less than b.y
            {
                alpha = alpha + 2*Math.PI;//then alpha becomes the previously defined alpha multiplied by 2 PI
            }
            arrow(page,edgeList.get(i).b.x,edgeList.get(i).b.y,0,1.57-alpha);//arrow method, taking a x(edgeList.get(i).b.x, y(edgeList.get(i).b.y, length = 0 so arrow is at the
            // very end of the drawn line subtracted by a double aplha
        }
    }

    // arrow method to call when making an arrow
    private void arrow(Graphics page, int x, int y, int len, double alpha)//arrow method, taking a x, y, length and double parameter
    {
        page.setColor (Color.green);//sets arrow to green
        int x1 = x+(int)(len*Math.sin(alpha));//x1 is set to x plus length *sin of alpha
        int y1 = y+(int)(len*Math.cos(alpha));//y1 is set to y plus the length * cosin of alpha
        page.drawLine (x, y, x1, y1);//drawa the x and y, and then previously defined x1, and y1
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+2.5)), y1+(int)(20*Math.cos(alpha+2.5)));//arithmatic to draw one side of the line for the arrow
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+3.7)), y1+(int)(20*Math.cos(alpha+3.7)));//arithmatic to draw the corresponding line for the arrow to complete the arrow
    }

    //  The listener for mouse events.
    private class GraphListener implements MouseListener, MouseMotionListener//GraphListener which implements MouseListener and MouseMotionListener, meaning it takes methods from both of those classes
    {
        public void mouseClicked (MouseEvent event)//when mouse is clicked and released
        {
            if (mode == true)//if the mode is true
            {
                nodeList.add(event.getPoint());//the current point to the nodeList
                repaint();//whenever you change the look of a componenet you call this method
            }
            if (mode == false)//if boolean mode is false
            {
                for (int i=0; i<nodeList.size(); i++)//for loop to go through the nodeList ArrayList
                {
                    if (distance(nodeList.get(i), event.getPoint()) < SIZE)//if the distance between a specific node and the pointer is less than the radius of the node (SIZE)
                        nodeList.remove(i);//then remove that node
                }
                for (int i=0; i<edgeList.size(); i++)
                {
                    if (distance(edgeList.get(i).a, event.getPoint())+distance(event.getPoint(), edgeList.get(i).b)-distance(edgeList.get(i).a, edgeList.get(i).b) < SIZE)
                    //if the (distance between starting point of that edgelist index and the current point) plus (the distance between the current point and ending point of that edgeList index)
                    //subtracted by the (distance of the starting and ending point of that edgeList index)(AB+BC-AC) is all less than the size
                        edgeList.remove(i);//then remove that index
                }
            }
        }

        public void mousePressed (MouseEvent event)//when the mouse is pressed down
        {
            if (mode == true)//if the mode is true
            {
                point1 = event.getPoint();//you start that point
            }
        }

        public void mouseDragged (MouseEvent event)//when the mouse is dragged while pressed down
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you get the second point
                repaint();//must use this method because you are making a change to the component
            }
        }

        public void mouseReleased (MouseEvent event)//when the mouse is released after being pressed (not to be confused with a click)
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you set point2 to where that point landed
                if (point1.x != point2.x && point1.y != point2.y)//if the points are not in the same spots
                {
                    edgeList.add(new Edge(point1,point2));//then you add a new edgeList element to the ArrayList, by definition of Edge() object
                    repaint();//must use this method because changes to component have been made
                }
            }

        }

        public void mouseMoved (MouseEvent event)// if the mouse is moved, without it being clicked (not to be confused by mouseDragged)
        {
            point3 = event.getPoint();//point three is set to be where the mouse is at the current time(used this to find the distance of original edge drawn, keeping here incase I want to add)
            repaint();//must use this method because changes were made to component

        }

        //  Empty definitions for unused event methods.
        public void mouseEntered (MouseEvent event){}//when the mouse enters a component

        public void mouseExited (MouseEvent event) {}//when the mouse exits a component

        private int distance(Point p1, Point p2) //private distance formula but inside of this class so i was able to use it for determining how to erase nodes and edges
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));//square root of x cordinants of first point minus second point times its self plus the y coordinates
            //of first point minus second point times itself
        }
    }
    // Represents the graph edges
    private class Edge //defines how edges are made
    {
        Point a, b;

        public Edge(Point a, Point b)
        {
            this.a = a;
            this.b = b;
        }
    }

    private class ButtonListener implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {

            if (event.getSource()== create)
            {
                mode = true;
                mode1 = 1;
            }
            if (event.getSource()==delete)
            {
                mode = !true;
                mode1 = 2;

            }

            // Initializes graph adjacency matrix
            for (int i=0; i<nodeList.size(); i++)
                for (int j=0; j<nodeList.size(); j++) a[i][j]=0;

            // Includes the edges in the graph adjacency matrix
            for (int i=0; i<edgeList.size(); i++)
            {
                for (int j=0; j<nodeList.size(); j++)
                    if (distance(nodeList.get(j),edgeList.get(i).a)<=SIZE+3)
                        for (int k=0; k<nodeList.size(); k++)
                            if (distance(nodeList.get(k),edgeList.get(i).b)<=SIZE+3)
                            {
                                System.out.println(j+"->"+k);
                                a[j][k]=1;
                            }
            }

            if (event.getSource()==print)
            {

                // Prints the graph adjacency matrix
                for (int i=0; i<nodeList.size(); i++)
                {
                    for (int j=0; j<nodeList.size(); j++)
                        System.out.print(a[i][j]+"\t");
                    System.out.println();
                }
            }
        }
        // Euclidean distance function
        private int distance(Point p1, Point p2)
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
        }
    }

    private class ButtonListener1 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== create)//if create button is selected
            {
                mode = true;//then the mode is set to true
                mode1 = 1;//and mode1 is set to 1
            }
        }
    }

    private class ButtonListener2 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== delete)//if create button is selected
            {
                mode = !true;//then the mode is set to true
                mode1 = 2;//and mode1 is set to 2, which would change the string that is output
            }
        }
    }

    private class ButtonListener3 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            x1 = label.getText();
            y1 = label1.getText();
            x = Integer.parseInt(x1);
            y = Integer.parseInt(y1);

            System.out.println("Path from " +x+" to " +y);
            System.out.println(findPath(x,y));
            System.out.println(path);

        }
    }

Body:
I was able to find it, and of course it was the smallest mistake I missed, adding this because in case anyone else has the same problem I hope this helps.  The main differences are in my buttonlistener3 class but I'll add the whole thing again just incase this helps anyone out.

import java.util.ArrayList;//all of these are the required to get classes from other packages
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;

public class GraphPanel extends JPanel
{
    private final int SIZE = 10;  // radius of each node
    private double alpha; // double variable to define later
    private JButton print, create, delete, path1; //allpath;//button variables
    private JTextField label, label1;
    boolean mode = true;//sets boolean for entire class to true, until later when I define it as false for certain methods to be complete

    String x1, y1;
    String str1 = new String("Mode Chosen Is : create" );//when you choose create it will print this instead
    String str2 = new String("Mode Chosen Is : delete" );//when you choose delete it will print this

    int x, y;
    int mode1 = 1; // int mode1 variable, will comment why i need this when it is later defined/changed

    private Point point1 = null, point2 = null, point3 = null;//makes pointers null, i added a third pointer to put the distance from the first drawn string at the top right, but no longer needed it
    //keeping it incase I wanted to add it again

    private ArrayList<Point> nodeList;   // Graph nodes
    private ArrayList<Edge> edgeList;    // Graph edges

    static private int[][] a = new int[100][100];  // Graph adjacency matrix
    static ArrayList<Integer> path = new ArrayList<Integer>();

    public GraphPanel()
    {

        nodeList = new ArrayList<Point>();//declares ArrayList<Point>
        edgeList = new ArrayList<Edge>();//declares ArrayList<Edge>

        GraphListener listener = new GraphListener();//assigns 'listener' to a Graphlistener object
        addMouseListener (listener);//accepts and reads mouseListener methods to the GraphListener object
        addMouseMotionListener (listener);//accepts and reads MouseMotionListener methods to the GraphListener object

        label = new JTextField (1);
        label1 = new JTextField (1);

        //allpath = new JButton ("Find All Paths");
        path1 = new JButton ("Find Path");//path button
        create = new JButton("Create");//declares 'create' as a JButton object with text on it that says 'create'
        delete = new JButton("Delete");//declares 'delete' as a JButton object with text that says 'delete'
        JButton print = new JButton("Print adjacency matrix");//declares 'print' as a JButton object with text that reads 'print adjacency matrix'

        print.addActionListener (new ButtonListener());//adds an action listener to the print button from the buttonlistener object
        create.addActionListener (new ButtonListener1());//adds an actionListener to the create button from the buttonlistener1 object
        delete.addActionListener (new ButtonListener2());//adds an actionliseneer to the delete button from the buttonlistener2 object
        path1.addActionListener (new ButtonListener3());//adds button that will find path of nodes
        //allpath.addActionListener (new ButtonListener4());

        setBackground (Color.black);//sets backround as black
        setPreferredSize (new Dimension(400, 300));//this is preferred size of graphpanel
        add(print);//these next six add()'s add each button to GraphPanel
        add(delete);//
        add(create);//
        //add(allpath);
        add(path1);
        add(label);
        add(label1);
    }

    public static boolean findPath(int x, int y) //boolean method findpath that takes two ints as parameters
    {
        boolean found = false;

        if (a[x][y]==1) //base case
        {
            //System.out.println(x + " -> " + y);//prints node -> node
            found = true;//path is found
            path.add(0,y);
        }
        else
        {
            int z;
            for (z=0; !found& z<a.length; z++)
            {
                if (a[x][z]==1)
                {
                    a[x][z]=2;
                    found = findPath(z,y);

                }
                if (found)
                {
                    //System.out.println(x + " -> " + z);
                    path.add(0,z);
                }

            }
        }
        return found;
    }

    // public static ArrayList findPath1(int x, int y, ArrayList path)
    // {
    // System.out.println("CALL FIND: " + path);
    // ArrayList path2 = null;
    // if (a[x][y]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(y);
    // System.out.println("EXIT BASE: " + path3);
    // path2 = path3;
    // }
    // else
    // {
    // int z;
    // for (z=0; z<a.length; z++)
    // if (a[x][z]==1)
    // {
    // ArrayList path3 = (ArrayList)path.clone();
    // path3.add(z);
    // path3 = findPath1(z,y,path3);
    // System.out.println("EXIT RECU: " + path);
    // path2 = path3;
    // }
    // }
    // return path2;
    // }
    //  Draws the graph
    public void paintComponent (Graphics page)
    {
        super.paintComponent(page);//using parent methods

        // Draws the edge that is being dragged
        page.setColor (Color.green);//setting color of what will be drawn to green
        if (mode1 == 1)//if mode1 is set to 1, which is when the create button is selected
        {
            page.drawString(str1, 125, 75);//then this is printed
        }
        if (mode1 == 2)//if mode1 is set to 2, which is when the delete button is selected
        {
            page.drawString(str2, 125, 75);//then this is printed
        }
        if (point1 != null && point2 != null)//if and only if both points are not null
        {
            page.drawLine (point1.x, point1.y, point2.x, point2.y);//then it draws the line from between point1(x, y cords), and point2(x, y cords)
            page.fillOval (point2.x-3, point2.y-3, 6, 6);//fills this oval by the rectangle it is specified from
        }
        // Draws the nodes
        for (int i=0; i<nodeList.size(); i++) //for loop going through the nodeList ArrayList
        {
            page.setColor (Color.green);//color is set to green
            page.fillOval (nodeList.get(i).x-SIZE, nodeList.get(i).y-SIZE, SIZE*2, SIZE*2);//fills oval by subtracting the SIZE from the x, y and setting the height and width as two times the SIZE
            page.setColor (Color.black);//sets next line to black
            page.drawString (String.valueOf(i), nodeList.get(i).x-SIZE/2, nodeList.get(i).y+SIZE/2);//writes inside the node what number index it is from the ArrayList with black text
        }
        // Draws the edges
        for (int i=0; i<edgeList.size(); i++) // for loop going through the edgeList ArrayList
        {
            page.setColor (Color.green);//sets the next line to green
            page.drawLine (edgeList.get(i).a.x, edgeList.get(i).a.y,edgeList.get(i).b.x, edgeList.get(i).b.y);//draws the line from x and y cords of where it starts to end
            //page.fillOval (edgeList.get(i).b.x-3, edgeList.get(i).b.y-3, 6, 6);

            //page.drawString (String.valueOf(point1.x*(point2.y-point3.y)+point2.x*(point3.y-point1.y)+point3.x*(point1.y-point2.y)), 5, 15);

            alpha = Math.atan((double)(edgeList.get(i).b.y-edgeList.get(i).a.y)/(edgeList.get(i).b.x-edgeList.get(i).a.x));//alpha = b.y-a.y cords/b.x-a.x chords as a double variable
            if (edgeList.get(i).a.x > edgeList.get(i).b.x)//if the x chord of a is greater than the x cordinate of b
            {
                alpha = alpha + Math.PI;//then alpha = previously defined alpha multiplied by PI
            }
            if (edgeList.get(i).a.x < edgeList.get(i).b.x && edgeList.get(i).a.y > edgeList.get(i).b.y)//if a.x is less than b.x and a.y is less than b.y
            {
                alpha = alpha + 2*Math.PI;//then alpha becomes the previously defined alpha multiplied by 2 PI
            }
            arrow(page,edgeList.get(i).b.x,edgeList.get(i).b.y,0,1.57-alpha);//arrow method, taking a x(edgeList.get(i).b.x, y(edgeList.get(i).b.y, length = 0 so arrow is at the
            // very end of the drawn line subtracted by a double aplha
        }
    }

    // arrow method to call when making an arrow
    private void arrow(Graphics page, int x, int y, int len, double alpha)//arrow method, taking a x, y, length and double parameter
    {
        page.setColor (Color.green);//sets arrow to green
        int x1 = x+(int)(len*Math.sin(alpha));//x1 is set to x plus length *sin of alpha
        int y1 = y+(int)(len*Math.cos(alpha));//y1 is set to y plus the length * cosin of alpha
        page.drawLine (x, y, x1, y1);//drawa the x and y, and then previously defined x1, and y1
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+2.5)), y1+(int)(20*Math.cos(alpha+2.5)));//arithmatic to draw one side of the line for the arrow
        page.drawLine (x1, y1, x1+(int)(20*Math.sin(alpha+3.7)), y1+(int)(20*Math.cos(alpha+3.7)));//arithmatic to draw the corresponding line for the arrow to complete the arrow
    }

    //  The listener for mouse events.
    private class GraphListener implements MouseListener, MouseMotionListener//GraphListener which implements MouseListener and MouseMotionListener, meaning it takes methods from both of those classes
    {
        public void mouseClicked (MouseEvent event)//when mouse is clicked and released
        {
            if (mode == true)//if the mode is true
            {
                nodeList.add(event.getPoint());//the current point to the nodeList
                repaint();//whenever you change the look of a componenet you call this method
            }
            if (mode == false)//if boolean mode is false
            {
                for (int i=0; i<nodeList.size(); i++)//for loop to go through the nodeList ArrayList
                {
                    if (distance(nodeList.get(i), event.getPoint()) < SIZE)//if the distance between a specific node and the pointer is less than the radius of the node (SIZE)
                        nodeList.remove(i);//then remove that node
                }
                for (int i=0; i<edgeList.size(); i++)
                {
                    if (distance(edgeList.get(i).a, event.getPoint())+distance(event.getPoint(), edgeList.get(i).b)-distance(edgeList.get(i).a, edgeList.get(i).b) < SIZE)
                    //if the (distance between starting point of that edgelist index and the current point) plus (the distance between the current point and ending point of that edgeList index)
                    //subtracted by the (distance of the starting and ending point of that edgeList index)(AB+BC-AC) is all less than the size
                        edgeList.remove(i);//then remove that index
                }
            }
        }

        public void mousePressed (MouseEvent event)//when the mouse is pressed down
        {
            if (mode == true)//if the mode is true
            {
                point1 = event.getPoint();//you start that point
            }
        }

        public void mouseDragged (MouseEvent event)//when the mouse is dragged while pressed down
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you get the second point
                repaint();//must use this method because you are making a change to the component
            }
        }

        public void mouseReleased (MouseEvent event)//when the mouse is released after being pressed (not to be confused with a click)
        {
            if (mode == true)//if the mode is true
            {
                point2 = event.getPoint();//then you set point2 to where that point landed
                if (point1.x != point2.x && point1.y != point2.y)//if the points are not in the same spots
                {
                    edgeList.add(new Edge(point1,point2));//then you add a new edgeList element to the ArrayList, by definition of Edge() object
                    repaint();//must use this method because changes to component have been made
                }
            }

        }

        public void mouseMoved (MouseEvent event)// if the mouse is moved, without it being clicked (not to be confused by mouseDragged)
        {
            point3 = event.getPoint();//point three is set to be where the mouse is at the current time(used this to find the distance of original edge drawn, keeping here incase I want to add)
            repaint();//must use this method because changes were made to component

        }

        //  Empty definitions for unused event methods.
        public void mouseEntered (MouseEvent event){}//when the mouse enters a component

        public void mouseExited (MouseEvent event) {}//when the mouse exits a component

        private int distance(Point p1, Point p2) //private distance formula but inside of this class so i was able to use it for determining how to erase nodes and edges
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));//square root of x cordinants of first point minus second point times its self plus the y coordinates
            //of first point minus second point times itself
        }
    }
    // Represents the graph edges
    private class Edge //defines how edges are made
    {
        Point a, b;

        public Edge(Point a, Point b)
        {
            this.a = a;
            this.b = b;
        }
    }

    private class ButtonListener implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {

            if (event.getSource()== create)
            {
                mode = true;
                mode1 = 1;
            }
            if (event.getSource()==delete)
            {
                mode = !true;
                mode1 = 2;

            }

            // Initializes graph adjacency matrix
            for (int i=0; i<nodeList.size(); i++)
                for (int j=0; j<nodeList.size(); j++) a[i][j]=0;

            // Includes the edges in the graph adjacency matrix
            for (int i=0; i<edgeList.size(); i++)
            {
                for (int j=0; j<nodeList.size(); j++)
                    if (distance(nodeList.get(j),edgeList.get(i).a)<=SIZE+3)
                        for (int k=0; k<nodeList.size(); k++)
                            if (distance(nodeList.get(k),edgeList.get(i).b)<=SIZE+3)
                            {
                                System.out.println(j+"->"+k);

                                a[j][k]=1;
                            }
            }

            if (event.getSource()==print)
            {

                // Prints the graph adjacency matrix
                for (int i=0; i<nodeList.size(); i++)
                {
                    for (int j=0; j<nodeList.size(); j++)
                        System.out.print(a[i][j]+"\t");
                    System.out.println();
                }
            }
        }
        // Euclidean distance function
        private int distance(Point p1, Point p2)
        {
            return (int)Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
        }
    }

    private class ButtonListener1 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== create)//if create button is selected
            {
                mode = true;//then the mode is set to true
                mode1 = 1;//and mode1 is set to 1
            }
        }
    }

    private class ButtonListener2 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            if (event.getSource()== delete)//if create button is selected
            {
                mode = !true;//then the mode is set to true
                mode1 = 2;//and mode1 is set to 2, which would change the string that is output
            }
        }
    }

    private class ButtonListener3 implements ActionListener
    {
        public void actionPerformed (ActionEvent event)
        {
            x1 = label.getText();
            y1 = label1.getText();
            x = Integer.parseInt(x1);
            y = Integer.parseInt(y1);
            System.out.println("Path from " +x+" to " +y);
            System.out.println(findPath(x,y));
            path.add(0,x);
            System.out.println(path);
            path.clear();
        }
    }

    // private class ButtonListener4 implements ActionListener
    // {
    // public void actionPerformed (ActionEvent event)
    // {
    // x1 = label.getText();
    // y1 = label1.getText();
    // x = Integer.parseInt(x1);
    // y = Integer.parseInt(y1);
    // System.out.println("Path from " +x+" to " +y);
    // System.out.println(findPath1(x,y,path));
    // System.out.println(path);
    // }
    // }
}


问:
Passing PHP Array to Javascript with Json_encode
I am trying to pass a php array to a javascript variable as an object to use in google maps on the same page/file. I am not able to send out an alert when testing the array in javascript.

PHP

```<code>while( $row = $query->fetch_assoc() ){
$street_address = $row['street_address'];
$zip = $row['zip'];
$state = $row['state'];
$lat = $row['lat'];
$lng = $row['lng'];
$test = $row['sellerDB_test'];

$firstName = $row['first_name'];
$lastName = $row['last_name'];
$email = $row['email'];
$phone = $row['phone'];

/* Each row is added as a new array */
$locations = array( 'streetAddress'=>$street_address, 'state'=>$state, 'zip'=>$zip, 'lat'=>$lat, 'lng'=>$lng, 'test'=>$test, 'first name'=>$firstName, 'last name'=>$lastName, 'email'=>$email, 'phone'=>$phone);
</code>```

JS

```<code>var map;
        var Markers = {};
        var infowindow;
        var locations = '<?php echo json_encode($locations); ?>';
        var location = JSON.parse(loactions);
        alert(locations[0]);
</code>```

I am getting this error

Uncaught ReferenceError: loactions is not defined
      at account:299

答:
@Ghost is right. I did not notice that the $locations is inside while loop. So You should define $locations = []; before while loop.
And then keep adding multiple records from while loop. So the updated code should be like:

```<code>$locations = [];
while( $row = $query->fetch_assoc() ){
    $street_address = $row['street_address'];
    $zip = $row['zip'];
    $state = $row['state'];
    $lat = $row['lat'];
    $lng = $row['lng'];
    $test = $row['sellerDB_test'];

    $firstName = $row['first_name'];
    $lastName = $row['last_name'];
    $email = $row['email'];
    $phone = $row['phone'];

    /* Each row is added as a new array [] */
    $locations[] = array( 'streetAddress'=>$street_address, 'state'=>$state, 'zip'=>$zip, 'lat'=>$lat, 'lng'=>$lng, 'test'=>$test, 'first name'=>$firstName, 'last name'=>$lastName, 'email'=>$email, 'phone'=>$phone);
}
</code>```

And after this, you should put the JS code snippet.

And use it like this:

JS cpde:

```<code>var map;
var Markers = {};
var infowindow;
var locations = <?php echo json_encode($locations); ?>;
var location = JSON.parse(loactions);
alert(location.streetAddress);
</code>```

Body:
I am trying to pass a php array to a javascript variable as an object to use in google maps on the same page/file. I am not able to send out an alert when testing the array in javascript.

PHP

while( $row = $query->fetch_assoc() ){
$street_address = $row['street_address'];
$zip = $row['zip'];
$state = $row['state'];
$lat = $row['lat'];
$lng = $row['lng'];
$test = $row['sellerDB_test'];

$firstName = $row['first_name'];
$lastName = $row['last_name'];
$email = $row['email'];
$phone = $row['phone'];

/* Each row is added as a new array */
$locations = array( 'streetAddress'=>$street_address, 'state'=>$state, 'zip'=>$zip, 'lat'=>$lat, 'lng'=>$lng, 'test'=>$test, 'first name'=>$firstName, 'last name'=>$lastName, 'email'=>$email, 'phone'=>$phone);

JS

var map;
        var Markers = {};
        var infowindow;
        var locations = '<?php echo json_encode($locations); ?>';
        var location = JSON.parse(loactions);
        alert(locations[0]);

I am getting this error

Uncaught ReferenceError: loactions is not defined
      at account:299

Body:
@Ghost is right. I did not notice that the $locations is inside while loop. So You should define $locations = []; before while loop.
And then keep adding multiple records from while loop. So the updated code should be like:

$locations = [];
while( $row = $query->fetch_assoc() ){
    $street_address = $row['street_address'];
    $zip = $row['zip'];
    $state = $row['state'];
    $lat = $row['lat'];
    $lng = $row['lng'];
    $test = $row['sellerDB_test'];

    $firstName = $row['first_name'];
    $lastName = $row['last_name'];
    $email = $row['email'];
    $phone = $row['phone'];

    /* Each row is added as a new array [] */
    $locations[] = array( 'streetAddress'=>$street_address, 'state'=>$state, 'zip'=>$zip, 'lat'=>$lat, 'lng'=>$lng, 'test'=>$test, 'first name'=>$firstName, 'last name'=>$lastName, 'email'=>$email, 'phone'=>$phone);
}

And after this, you should put the JS code snippet.

And use it like this:

JS cpde:

var map;
var Markers = {};
var infowindow;
var locations = <?php echo json_encode($locations); ?>;
var location = JSON.parse(loactions);
alert(location.streetAddress);