2015-6-13
来源:互联网 发布:爱淘宝红包 1元 0.5元 编辑:程序博客网 时间:2024/06/08 10:17
经过几天讲解和练习,实现了继承的实例,
在此过程中,感觉主要难度在于子类的继承对象以及强制转换,
例:
import java.awt.Color;
import java.awt.Graphics;
public class Line extends Shape{
public Line(int x1, int y1, int x2, int y2, Color color) {
super(x1, y1, x2, y2, color);
// TODO Auto-generated constructor stub}
public void draw(Graphics g) {
g.drawLine(x1, y1, x2, y2);
}
}
import java.awt.Graphics;
public class Line extends Shape{
public Line(int x1, int y1, int x2, int y2, Color color) {
super(x1, y1, x2, y2, color);
// TODO Auto-generated constructor stub}
public void draw(Graphics g) {
g.drawLine(x1, y1, x2, y2);
}
}
if ("10".equals(draw.str)) {
// draw.g.drawLine(x1, y1, x2, y2);
// 创建一个直线对象
shape = new Line(x1,y1,x2,y2,draw.color);
x1 = x2;
y1 = y2;
// draw.g.drawLine(x1, y1, x2, y2);
// 创建一个直线对象
shape = new Line(x1,y1,x2,y2,draw.color);
x1 = x2;
y1 = y2;
再如:
} else if ("2".equals(draw.str)) {
draw.g.setColor(Color.white);
BasicStroke basicstroke = new BasicStroke(10);
Shape shape = new Coph(x1,y1,x2,y2,draw.color.white);
Graphics2D graphics2d = (Graphics2D) draw.g;
graphics2d.setStroke(basicstroke);
draw.g.drawLine(x1, y1, x2, y2);
list.add(shape);
x1 = x2;
y1 = y2;
draw.g.setColor(Color.white);
BasicStroke basicstroke = new BasicStroke(10);
Shape shape = new Coph(x1,y1,x2,y2,draw.color.white);
Graphics2D graphics2d = (Graphics2D) draw.g;
graphics2d.setStroke(basicstroke);
draw.g.drawLine(x1, y1, x2, y2);
list.add(shape);
x1 = x2;
y1 = y2;
总之,强制转化得新建一对象,毕竟这是子类的属性。
0 0
- 2015-6-13
- 2015-6-13
- 每日一题B 2015-6-1 13:23
- 6-13
- 2015-1-13
- CSS:01-13-2015
- 2015-1-13感
- 03-13-2015
- 2015-4-13_OC
- 2015-06-13
- [2015-08-13] python023
- 2015-08-13
- 2015-09-13
- 2015/10/13
- 2015-10-13
- 2015-12-13
- 2015-5-13-1
- HTML基础-01-13-2015
- textarea中的错误
- SGU130 Circle
- leetcode--Convert Sorted Array to Binary Search Tree
- 135 南冥 曹植 有何所關
- 134 東洲 成悌元 聲極悽咽
- 2015-6-13
- 《设计模式》学习体会
- chapter12test5
- 文件的切割与合并练习
- bzoj 4127: Abs
- CSS盒子模型
- spring 配置<context:component-scan base-package=” ”/>
- C++默认参数
- 深入浅出NodeJS笔记(一)