如何创建 Ellipse2D 数组?
我有一个我一直在工作的程序:它从用户那里获取数据,用它做一些数学运算,然后在屏幕上显示一个椭圆,当输入新数据时,旧的椭圆消失,新的椭圆取代它。但是,我需要该程序将旧椭圆和新椭圆保留在屏幕上,以便我可以比较大小。我对此的解决方案是拥有它,以便在创建椭圆时将其存储在数组中,然后将椭圆数组绘制到屏幕上,我还需要它以便用户可以清除数组并重新开始。但是我无法让代码工作。你愿意帮忙吗?
下面是我用来创建和绘制椭圆的代码,所有使用的变量都只是数字。
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.white);
g2.draw(new Ellipse2D.Double(((Background.getWidth()) / 2) - (gblSemiMajaxis / 2), ((Background.getHeight()) / 2) - (gblsemiMinoraxis / 2), gblSemiMajaxis, gblsemiMinoraxis));
}
I have a program that I've been working: it takes data from the user does some maths with it and then displays an ellipse to the screen, when new data is entered the old ellipses disappears and the new one replaces it. However I need the program to keep the old ellipse on the screen as well as the new ones so I can compare sizes. My solution to this is to have it so that when an ellipse is created it is stored in an array, and then the array of ellipse is drawn onto the screen, I also need it so that the user can clear the array and start over. However I cannot get the code to work. Will you please help?
Below is the code that I used to create and draw the ellipse all of the variables used are just numbers.
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.white);
g2.draw(new Ellipse2D.Double(((Background.getWidth()) / 2) - (gblSemiMajaxis / 2), ((Background.getHeight()) / 2) - (gblsemiMinoraxis / 2), gblSemiMajaxis, gblsemiMinoraxis));
}
只是为了扩展伊恩·麦克拉里德的答案:
Just to expand on Ian McLarid's answer: