I tried to make a simple program, draw a 4 sided polygon with 4 mouse clicks. This is the code:
import acm.graphics.*;
import acm.program.*;
import java.awt.event.*;
public class Pravougaonik extends GraphicsProgram {
public void run() {
addMouseListeners();
}
public void mouseClicked(MouseEvent e) {
GPolygon cetvorougao = new GPolygon();
cetvorougao.addVertex(e.getX(),e.getY());
cetvorougao.addVertex(e.getX(),e.getY());
cetvorougao.addVertex(e.getX(),e.getY());
cetvorougao.addVertex(e.getX(),e.getY());
add(cetvorougao);
}
}
I understand that the problem is when I click once all 4 vertices have the same coordinates, but I don't know how to correct the code. Can anyone help??