在另一个线程中,我说过我喜欢通过做这样的事情来集中我的GUI:
JFrame frame = new JFrame("Foo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new HexagonGrid());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
Run Code Online (Sandbox Code Playgroud)
但安德鲁汤普森有不同的意见,而是打电话
frame.pack();
frame.setLocationByPlatform(true);
Run Code Online (Sandbox Code Playgroud)
和询问的头脑想知道为什么?
我有一个有趣的问题.使用Java图形,我想画一个圆圈中的平行线,这些圆线间隔有一些预定义的间隙常数.圆具有已知的x和y位置以及半径.线应该从圆的中心开始并且应该向外移动.例如,

我想成像,最简单的方法是首先绘制线条以填满整个方块,如下所示:

然后可能绘制4个多边形并用白色填充它们.4个多边形标记如下:

如您所见,在这种情况下,多边形由左顶点(x,y)定义,宽度和高度的边由圆的半径定义,然后是(x +半径,y +半径)的弧.
需要反馈:
重要提示:请注意,虽然此解决方案具有垂直线,但应根据某个角度θ来定义线条.也就是说,它们可以成角度(但彼此平行).
如果有人能提供实际绘制的代码,我将永远感激不尽!:)
public void draw(Graphics g, int x, int y, int radius, int lineGap, int lineThickness, int theta) {
//g = the graphics object
//x,y = the top left coordinate of the square
//radius = the radius of the circle, the width of the rectangle, the height of the rectangle
//lineGap = the gap in between each of the lines
//lineThickness = the thickness of the lines in …Run Code Online (Sandbox Code Playgroud)