Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
2.0 kB
1
Indexable
Never
import java.awt.*;
import java.awt.event.*;

class Circle extends Shape {
    public Circle(Color color, int xPosition, int yPosition, int size) {
        super(color, xPosition, yPosition, size);
    }

    public void draw(Graphics g) {
        g.setColor(color);
        g.fillOval(position.x, position.y, size * 2, size * 2);
    }

    public void handleKeyPress(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (keyCode == KeyEvent.VK_PLUS || keyCode == KeyEvent.VK_ADD) {
            resizeShape(1);
        } else if (keyCode == KeyEvent.VK_MINUS || keyCode == KeyEvent.VK_SUBTRACT) {
            resizeShape(-1);
        }
    }
}

class Square extends Shape {
    public Square(Color color, int xPosition, int yPosition, int size) {
        super(color, xPosition, yPosition, size);
    }

    public void draw(Graphics g) {
        g.setColor(color);
        g.fillRect(position.x, position.y, size * 2, size * 2);
    }

    public void handleKeyPress(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (keyCode == KeyEvent.VK_PLUS || keyCode == KeyEvent.VK_ADD) {
            resizeShape(1);
        } else if (keyCode == KeyEvent.VK_MINUS || keyCode == KeyEvent.VK_SUBTRACT) {
            resizeShape(-1);
        }
    }
}

class Triangle extends Shape {
    public Triangle(Color color, int xPosition, int yPosition, int size) {
        super(color, xPosition, yPosition, size);
    }

    public void draw(Graphics g) {
        g.setColor(color);
        int[] xPoints = { position.x + size, position.x, position.x + 2 * size };
        int[] yPoints = { position.y, position.y + 2 * size, position.y + 2 * size };
        g.fillPolygon(xPoints, yPoints, 3);
    }

    public void handleKeyPress(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (keyCode == KeyEvent.VK_PLUS || keyCode == KeyEvent.VK_ADD) {
            resizeShape(1);
        } else if (keyCode == KeyEvent.VK_MINUS || keyCode == KeyEvent.VK_SUBTRACT) {
            resizeShape(-1);
        }
    }
}