Domanda

I am trying to draw a bunch of random shapes and lines in a JFrame. Is there any way to see where the locations of x and y are without randomly inserting a number and guessing then adjusting accordingly after running the program? It gets really tedious trying to position everything perfectly...especially with the amount that I am drawing. If anyone has any suggestions please let me know. The only thing I've thought of is using a mouse pointer location but if there is anything easier please let me know. Thank you!!

È stato utile?

Soluzione

If you know the point of the pixel ahead of time, you could draw the point (in this case, an X marks the spot) in the paint method, in a class that extends JFrame.

@Override
public void paint(Graphics g) {

    int x = 50;
    int y = 50;

    super.paint(g);
    g.drawLine(x-2, y-2, x+2, y+2); 
    g.drawLine(x-2, y+2, x+2, y-2);
}

Modify the 2 to change the length/size of the X.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top