xonecas.io
101
Sh

shapesaver / files

shapesaver / Shape.java

1.4 KB
1/*
2sean caetano martin
3seancaetanomartin@gmail.com
4CIS 255 HY
5Shape.java - abstract superclass
6assignment#5
73/28/11
8*/
9
10import java.awt.Color;
11import java.awt.Graphics;
12
13public abstract class Shape
14{
15	// instance variables
16	private int x1;
17	private int x2;
18	private int y1;
19	private int y2;
20	private Color myColor;
21
22	//default contructor
23	public Shape ()
24	{
25		this.x1 = 0;
26		this.y1 = 0;
27		this.x2 = 0;
28		this.y2 = 0;
29		myColor = Color.BLACK;
30	}// end default contructor
31
32	// contructor
33	public Shape (int x1, int x2, int y1, int y2, Color color)
34	{
35		setX1(x1);
36		setX2(x2);
37		setY1(y1);
38		setY2(y2);
39
40	}// end contructor
41
42	// get x1
43	public int getX1 ()
44	{return x1;}
45
46	// get x2
47	public int getX2 ()
48	{return x2;}
49
50	// get y1
51	public int getY1 ()
52	{return y1;}
53
54	// get y2
55	public int getY2 ()
56	{return y2;}
57
58	// get color
59	public Color getColor()
60	{return myColor;}
61
62	public void setX1 (int x1)
63	{
64		if (x1>=1){this.x1 = x1;}
65		else{this.x1 = 0;}
66	}//end set x1
67
68	public void setX2 (int x2)
69	{
70		if (x2>=1){this.x2 = x2;}
71		else{this.x2 = 0;}
72	}//end set x2
73
74	public void setY1 (int y1)
75	{
76		if (y1>=1){this.y1 = y1;}
77		else{this.y1 = 0;}
78	}//end set y1
79
80	public void setY2 (int y2)
81	{
82		if (y2>=1){this.y2 = y2;}
83		else{this.y2 = 0;}
84	}//end set y2
85
86	// draw ensure abstract
87	public abstract void draw (Graphics g);
88
89}//end shape