Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lab03.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
114.69 Кб
Скачать

Import java.Awt.Color;

/**

* Класс, описывающий треугольник

*/

public class Triangle {

protected int xA, xB, xC, yA, yB, yC;

protected Color bgColor = new Color (255, 255, 255);

protected Color color = new Color (0, 0, 0);

public int getXA() {

return xA;

}

public int getXB() {

return xB;

}

public int getXC() {

return xC;

}

public int getYA() {

return yA;

}

public int getYB() {

return yB;

}

public int getYC() {

return yC;

}

public Color getBgColor() {

return bgColor;

}

public Color getColor() {

return color;

}

/**

* Построение треугольника по трем точкам

* @param xA

* @param yA

* @param xB

* @param yB

* @param xC

* @param yC

* @param bgColor

* @param borderColor

*/

public Triangle(int xA, int yA, int xB, int yB, int xC, int yC, Color bgColor, Color borderColor) {

super();

this.xA = xA;

this.xB = xB;

this.xC = xC;

this.yA = yA;

this.yB = yB;

this.yC = yC;

if (borderColor != null) this.color = borderColor;

if (bgColor != null) this.bgColor = bgColor;

System.out.println("Рисуем треугольник с координатами точек:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + ").");

}

/**

* Move Figure to new position with NO change others parameters

* @param dX - Horizontal delta

* @param dY - Vertical delta

*/

public void transfer (int dX, int dY) {

this.xA += dX;

this.xB += dX;

this.xC += dX;

this.yA += dY;

this.yB += dY;

this.yC += dY;

System.out.println("Новые координаты треугольника:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + ").");

}

public void reDraw (int xA, int yA, int xB, int yB, int xC, int yC, Color bgColor, Color borderColor) {

this.xA = xA;

this.xB = xB;

this.xC = xC;

this.yA = yA;

this.yB = yB;

this.yC = yC;

if (borderColor != null) this.color = borderColor;

if (bgColor != null) this.bgColor = bgColor;

System.out.println("Рисуем треугольник с координатами точек:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + ").");

}

}

  • И, наконец, четырехугольник. Четырехугольник также лучше строить по его четырем точкам. Реализация класса «Quadrangle.java» следующая:

Import java.Awt.Color;

/**

* Класс, описывающий четырехугольник

*/

public class Quadrangle {

protected int xA, xB, xC, xD, yA, yB, yC, yD;

protected Color bgColor = new Color (255, 255, 255);

protected Color color = new Color (0, 0, 0);

public int getXA() {

return xA;

}

public int getXB() {

return xB;

}

public int getXC() {

return xC;

}

public int getXD() {

return xD;

}

public int getYA() { return yA; }

public int getYB() { return yB; }

public int getYC() { return yC; }

public int getYD() {

return yD;

}

public Color getBgColor() {

return bgColor;

}

public Color getColor() {

return color;

}

/**

* Построение четырехугольника по 4-м точкам

* @param xA

* @param yA

* @param xB

* @param yB

* @param xC

* @param yC

* @param xD

* @param yD

* @param bgColor

* @param borderColor

*/

public Quadrangle(int xA, int yA, int xB, int yB, int xC, int yC, int xD, int yD, Color bgColor, Color borderColor) {

super();

this.xA = xA;

this.xB = xB;

this.xC = xC;

this.xD = xD;

this.yA = yA;

this.yB = yB;

this.yC = yC;

this.yD = yD;

if (borderColor != null) this.color = borderColor;

if (bgColor != null) this.bgColor = bgColor;

System.out.println("Рисуем четырехугольник с координатами точек:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + "),");

System.out.println(" D(" + xD + ", " + yD + ").");

}

/**

* Move Figure to new position with NO change others parameters

* @param dX - Horizontal delta

* @param dY - Vertical delta

*/

public void transfer (int dX, int dY) {

this.xA += dX;

this.xB += dX;

this.xC += dX;

this.xD += dX;

this.yA += dY;

this.yB += dY;

this.yC += dY;

this.yD += dY;

System.out.println("Новые координаты треугольника:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + "),");

System.out.println(" D(" + xD + ", " + yD + ").");

}

public void reDraw (int xA, int yA, int xB, int yB, int xC, int yC, int xD, int yD, Color bgColor, Color borderColor) {

this.xA = xA;

this.xB = xB;

this.xC = xC;

this.yA = yA;

this.yB = yB;

this.yC = yC;

if (borderColor != null) this.color = borderColor;

if (bgColor != null) this.bgColor = bgColor;

System.out.println("Рисуем четырехугольник с координатами точек:");

System.out.println(" A(" + xA + ", " + yA + "),");

System.out.println(" B(" + xB + ", " + yB + "),");

System.out.println(" C(" + xC + ", " + yC + "),");

System.out.println(" D(" + xD + ", " + yD + ").");

}

}

18

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]