Java Is it possible to create an actionPerformed() like method but takes a different parameter?

48 Views Asked by At

I have to create a very basic GPS for a project. In my interface, I have an animation of a car that moves from point A to point B. The code that makes the car move is implemented in the actionPerformed(ActionEvent e) method and is working fine. But I can't feed this method a different parameter.

The parameters I want to give it are the coordinates of some points (nodes) in the interface ( I am using Dijkstra's algoritm for shortest path). So is there a way to create a method that takes the desired parameters while keeping the same functionalities as the actionPerformed() method? I am new to java GUI interface.

**By actionPerformed() like method I mean a method that loops the code inside of it. This is what the actionPerformed() is doing in my code. **For example, if I print something inside of the actionPerformed() methode, it keeps printing it until I stop the code :

//This is going to print "Example for as long as the code is running
actionPerformed(ActionEvent e){
System.out.print("Example");
}

My actual code :

    @Override
    public void actionPerformed(ActionEvent e) {

        autoRegulTimer++;

        auto_1.setX(auto_1.getX() + 1);  // moves the car on the x axis  

        // basic code that directs the path of the car
        if (auto_1.getX() > DijkstraMain.X1) {      
            
            if(auto_1.getY()>=DijkstraMain.Y2) {    
                auto_1.setY(DijkstraMain.Y2);       
                auto_1.setX(auto_1.getX() + 1);     
            }
            else {                                          
            auto_1.setX(DijkstraMain.X1);            
            auto_1.setY(auto_1.getY() + 1);         
            }
        }
        if (autoRegulTimer % 125 == 0) {
            if (auto_G.size() > 0) {
                auto_G.add(auto_1);
            }
        }
        repaint(); 
    }

This is what I want to do :

    public void actionPerformed(ActionEvent e, Node node) {
        //code 
    }

Any help is appreciated. Thanks.

0

There are 0 best solutions below