-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyShape.java
More file actions
73 lines (68 loc) · 1.37 KB
/
Copy pathMyShape.java
File metadata and controls
73 lines (68 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.awt.*;
public abstract class MyShape implements Cloneable
{
//****************************properties****************************************
private int x1;
private int y1;
private int x2;
private int y2;
private Color color;
MyShape shape;
//*************************constructors***************************************
public MyShape(int a, int b, int c, int d, Color col)
{
this.x1=a;
this.y1=b;
this.x2=c;
this.y2=d;
this.color=col;
}
//****************************methods**************************************
public abstract void drawShape(Graphics g);
//clone object and create new points
public Object clone() throws CloneNotSupportedException
{
try {
return (MyShape) super.clone();
}catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return this;
}
//getters & setters
public int getX1(){
return x1;
}
public int getY1(){
return y1;
}
public int getX2(){
return x2;
}
public int getY2(){
return y2;
}
public Color getColor(){
return color;
}
public void setX1(int a){
this.x1=a;
}
public void setY1(int b){
this.y1=b;
}
public void setX2(int c){
this.x2=c;
}
public void setY2(int d){
this.y2=d;
}
public void setColor (Color col){
this.color=col;
}
//moving start point of shape 10 pixels right and down
public void move() {
setX1(this.x1+10);
setY1(this.y1+10);
}
}