【发布时间】:2019-09-16 02:29:14
【问题描述】:
我正在为学校创建一个像应用程序这样的绘画项目,在我当前的代码中,我有几个子类和一个超级类。超级应该保存要绘制的形状数组,每个形状对象都应该是它自己的子类,我以后必须放入一个数组并从应用程序调用。我必须使用 JDesktopPane 和 JInternalFrame,我不能使用 Arraylists,而且我目前坚持尝试将我的 RectDraw 子类的 Float 转换为我的 super。所有这一切都是在最终将工具嵌套在一个名为 MyShapes 的超名称中之前。欢迎任何帮助。我不经常使用 jdesktopPane,而且我不擅长投射。
public class myShapes {
public void paint(Graphics g) {
graphSettings = (Graphics2D)g;
graphSettings.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
graphSettings.setStroke(new BasicStroke(4));
Iterator<Color> strokeCounter = shapeStroke.iterator();
Iterator<Color> fillCounter = shapeFill.iterator();
Iterator<Float> transCounter = transPercent.iterator();
for (Shape s : shapes){
graphSettings.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transCounter.next()));
graphSettings.setPaint(strokeCounter.next());
graphSettings.draw(s);
graphSettings.setPaint(fillCounter.next());
graphSettings.fill(s);
}
if (drawStart != null && drawEnd != null){
graphSettings.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.40f));
graphSettings.setPaint(Color.LIGHT_GRAY);
Shape aShape = null;
if (currentAction == 2){
RectDraw drawRectangle = new RectDraw();
aShape = drawRectangle(x1, y1, x2, y2);
}
else if (currentAction == 3){
CircleDraw drawEllipse = new CircleDraw();
aShape = drawEllipse(x1, y1, x2, y2);
}
else if (currentAction == 4) {
LineDraw drawLine = new LineDraw();
aShape = drawLine(x1, y1, x2, y2);
}
graphSettings.draw(aShape);
}
}
}
这些是我的子类
package mainPackage;
import java.awt.geom.Rectangle2D;
public class RectDraw extends myShapes {
public Rectangle2D.Float drawRectangle(int x1, int y1, int x2, int y2) {
int RDx, RDy, RDwidth, RDheight;
RDx = Math.min(x1, x2);
RDy = Math.min(y1, y2);
RDwidth = Math.abs(x1 - x2);
RDheight = Math.abs(y1 - y2);
return new Rectangle2D.Float(RDx, RDy, RDwidth, RDheight);
}
}
除了名字之外,其他的完全一样
public class CircleDraw extends myShapes {
public Ellipse2D.Float drawEllipse(int x1, int y1, int x2, int y2){
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
return new Ellipse2D.Float(x, y, width, height);
}
}
public class LineDraw extends myShapes {
public Line2D.Float drawLine(int x1, int y1, int x2, int y2) {
return new Line2D.Float(x1, y1, x2, y2);
}
}
我不断得到无法解析为变量
【问题讨论】:
标签: java casting awt multiple-inheritance superclass