Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package triangle;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.geom.Line2D;
- public class Triangle {
- int triLength;
- int numOfSides;
- Color triColor;
- int x;
- int y;
- public Triangle (int sides, Color c, int length, int xCoor, int yCoor) {
- triLength = length;
- numOfSides = sides;
- triColor = c;
- x = xCoor;
- y = yCoor;
- }
- public void setNew(int sides, Color c, int length, int xCoor, int yCoor) {
- triLength = length;
- numOfSides = sides;
- triColor = c;
- x = xCoor;
- y = yCoor;
- }
- public void draw(Graphics2D g2) {
- g2.setColor(triColor);
- if (numOfSides == 1) {
- Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
- g2.draw(one);
- }
- else if (numOfSides == 2) {
- Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
- Line2D.Double two = new Line2D.Double(x, y + triLength, x + triLength, y + triLength);
- g2.draw(one);
- g2.draw(two);
- }
- else if (numOfSides == 3) {
- Line2D.Double one = new Line2D.Double(x, y, x, y + triLength);
- Line2D.Double two = new Line2D.Double(x, y + triLength, x + triLength, y + triLength);
- Line2D.Double three = new Line2D.Double(x, y, x + triLength, y + triLength);
- g2.draw(one);
- g2.draw(two);
- g2.draw(three);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement