Java Swing custom shapes (2D Graphics)

前端 未结 3 1625
清歌不尽
清歌不尽 2021-01-15 15:23

I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon.

public void mouseClicked(MouseEvent e)          


        
3条回答
  •  情深已故
    2021-01-15 15:55

    Have you looked at the Graphics class in java (there is also a Polygon class)? There are draw and fill polygon methods, and each can take in an array of x-coordinates and y-coordinates. By using these arrays, you should be able to change the positions of the points fairly easily. Like you could change all of them equally for a re-size, or copy and paste by just moving all points equally. Changing the color is as easy as filling it with a new color and repainting.

提交回复
热议问题