Skip to main content

Posts

Showing posts with the label rectangle

Extending an abstract class [closed]

The following code for RectangleNode extends an abstract class called GraphElement, this is needed for my program to draw rectangles where necessary. My question is regarding the abstract method in GraphElement. Rectangle Node: import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.awt.Color; public class RectangleNode extends GraphElement { private double width = 20; private double length = 40; private Rectangle2D.Double rect; public RectangleNode(int x, int y) { super(x,y); rect = new Rectangle2D.Double(getXPos(), getYPos(), length, width); } public RectangleNode() { super(); rect = null; } public boolean isSelected(double x, double y) { return super(x,y); } public void draw(Graphics2D g2) { if (rect != null) g2.draw(rect); } } Graph Element: import java.awt.Graphics2D; abstract public class GraphElement { private double xPos; private double yPos; protected String label; public GraphElement() {