Оглавление |
Назад
// =======================================
// ColorRectangle.java
//
// (C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// =======================================
import java.awt.*;
public class ColorRectangle
{
public static void main(String args[])
{
MyColorRect rect = new MyColorRect(
0, 0, 10, 20, Color.black);
String szStr = rect.toString();
System.out.println(szStr);
rect.setMyRect(10, 20, 30, 40);
rect.setColor(Color.red);
szStr = rect.toString();
System.out.println(szStr);
}
}
class MyColorRect extends MyRect
{
protected Color rectColor;
MyColorRect(int x1, int y1,
int x2, int y2, Color colr)
{
super(x1, y1, x2, y2);
rectColor = colr;
}
public void setColor(Color colr)
{
rectColor = colr;
}
public String toString()
{
String sz = "Object MyRect: (" +
x1 + ", " + y1 + ", " +
x2 + ", " + y2 + "), " +
rectColor.toString();
return sz;
}
}
class MyRect
{
protected int x1;
protected int y1;
protected int x2;
protected int y2;
MyRect(int x1, int y1, int x2, int y2)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public void setMyRect(int x1, int y1,
int x2, int y2)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public String toString()
{
String sz = "Object MyRect: (" +
x1 + ", " + y1 + ", " +
x2 + ", " + y2 + ")";
return sz;
}
}
Назад |