1 Bài 3 - TH Java Sun Nov 04, 2012 3:57 pm
Admin
Admin
Bài 3: xây dựng lớp Hình Học
( Write by MRKHOA92)
- Code:
import java.util.Date;
import javax.swing.JFrame;
public class HinhHoc extends JFrame{
String color;
boolean filled;
Date createDate;
public HinhHoc() {
color = "Nocolor";
filled = false;
createDate = new Date();
}
public HinhHoc(String color,boolean filled) {
this.color = color;
this.filled = filled;
createDate = new Date();
}
public String getColor() {
return this.color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean fill) {
filled = fill;
}
public Date getDate() {
return createDate;
}
public String toString(){
String str;
str = "Mau sac => ";
str += color;
if(filled) str += ", Tomau => Da duoc to, ";
else str += ", Tomau => Chua duoc to, ";
str += "Ngay tao => ";
str += createDate.toString();
return str;
}
public static void main(String args[]) {
HinhHoc object1 = new HinhHoc("RED",true);
System.out.println(object1.toString());
}
}
( Write by MRKHOA92)