Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Polygon extends Figure2D {
- // fields
- private ArrayList<Point> auxiliaryPoints;
- private int[] x, y;
- private int size;
- // constructors
- public Polygon(
- Point refPoint,
- Point defPoint,
- ArrayList<Point> auxiliaryPoints,
- Color borderColor,
- Color figureColor) {
- super(refPoint, defPoint, borderColor, figureColor);
- setAuxiliaryPoints(auxiliaryPoints);
- }
- public Polygon(Polygon polygon) {
- super(polygon);
- }
- // methods
- @Override
- protected void paintComponent(Graphics g) {
- super.paintComponent(g);
- g.setColor(getFigureColor());
- g.fillPolygon(x, y, size);
- g.setColor(getBorderColor());
- g.drawRect(
- 0,
- 0,
- Math.abs(getDefPoint().x - getRefPoint().x),
- Math.abs(getDefPoint().y - getRefPoint().y));
- }
- // getters and setters
- public ArrayList<Point> getAuxiliaryPoints() {
- return auxiliaryPoints;
- }
- public void setAuxiliaryPoints(ArrayList<Point> auxiliaryPoints) {
- this.auxiliaryPoints = auxiliaryPoints;
- if(auxiliaryPoints!=null){
- setXY();
- }
- }
- private void setXY(){
- size = this.auxiliaryPoints.size();
- x = new int[size];
- y = new int[size];
- for (int i = 0; i < size; i++) {
- x[i] = this.auxiliaryPoints.get(i).x - getRefPoint().x;
- y[i] = this.auxiliaryPoints.get(i).y - getDefPoint().y;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment