我想重写Graphics类中的drawLine(int x1,int y1,int x2,int y2)这个方法,但在重写的方法中又要调用Graphics的drawLine(int x1,int y1,int x2,int y2)方法,要怎么做啊???import java.awt.*;
public abstract class MyGraphics extends Graphics
{
public void drawLine(int x1,int y1,int x2,int y2)
{
x1=x1+2;
y1=y1+2;
x2=x2+2;
y2=y2+2;
super.drawLine(x1,y1,x2,y2);
}
}
以上代码编译时说无法直接访问java.awt.Graphics中的抽象方法:super.drawLine(x1,y1,x2,y2)
这样做不行,那要怎么做啊,请指点一下~
public abstract class MyGraphics extends Graphics
{
public void drawLine(int x1,int y1,int x2,int y2)
{
x1=x1+2;
y1=y1+2;
x2=x2+2;
y2=y2+2;
super.drawLine(x1,y1,x2,y2);
}
}
以上代码编译时说无法直接访问java.awt.Graphics中的抽象方法:super.drawLine(x1,y1,x2,y2)
这样做不行,那要怎么做啊,请指点一下~
楼主【aheqq】截止到2008-07-02 13:59:32的历史汇总数据(不包括此帖):
发帖的总数量:3 发帖的总分数:60
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:3 未结的总分数:60
结贴的百分比:0.00 % 结分的百分比:0.00 %
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
真不明白楼主你想干什么
import java.awt.image.*;
import java.text.*;public class MyGraphics extends Graphics { private final Graphics g; public MyGraphics(Graphics g) {
if (g == null) throw new NullPointerException();
this.g = g;
} public void clearRect(int x, int y, int width, int height) {
g.clearRect(x, y, width, height);
} public void clipRect(int x, int y, int width, int height) {
g.clipRect(x, y, width, height);
} public void copyArea(int x, int y, int width, int height, int dx, int dy) {
g.copyArea(x, y, width, height, dx, dy);
} public Graphics create() {
return g.create();
} public void dispose() {
g.dispose();
} public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
g.drawArc(x, y, width, height, startAngle, arcAngle);
} public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
return g.drawImage(img, x, y, observer);
} public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
return g.drawImage(img, x, y, bgcolor, observer);
} public boolean drawImage(Image img, int x, int y, int width, int height,
ImageObserver observer) {
return g.drawImage(img, x, y, width, height, observer);
} public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor,
ImageObserver observer) {
return g.drawImage(img, x, y, width, height, bgcolor, observer);
} public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, ImageObserver observer) {
return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
} public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
int sx2, int sy2, Color bgcolor, ImageObserver observer) {
return g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
} public void drawLine(int x1, int y1, int x2, int y2) {
x1 = x1 + 2;
y1 = y1 + 2;
x2 = x2 + 2;
y2 = y2 + 2;
g.drawLine(x1,y1,x2,y2);
} public void drawOval(int x, int y, int width, int height) {
g.drawOval(x, y, width, height);
} public void drawPolygon(int[] points, int[] points2, int points3) {
g.drawPolygon(points, points2, points3);
} public void drawPolyline(int[] points, int[] points2, int points3) {
g.drawPolyline(points, points2, points3);
} public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
g.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
} public void drawString(String str, int x, int y) {
g.drawString(str, x, y);
} public void drawString(AttributedCharacterIterator iterator, int x, int y) {
g.drawString(iterator, x, y);
} public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
g.fillArc(x, y, width, height, startAngle, arcAngle);
} public void fillOval(int x, int y, int width, int height) {
g.fillOval(x, y, width, height);
} public void fillPolygon(int[] points, int[] points2, int points3) {
g.fillPolygon(points, points2, points3);
} public void fillRect(int x, int y, int width, int height) {
g.fillRect(x, y, width, height);
} public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
} public Shape getClip() {
return g.getClip();
} public Rectangle getClipBounds() {
return g.getClipBounds();
} public Color getColor() {
return null;
} public Font getFont() {
return g.getFont();
} public FontMetrics getFontMetrics(Font f) {
return g.getFontMetrics();
} public void setClip(Shape clip) {
g.setClip(clip);
} public void setClip(int x, int y, int width, int height) {
g.setClip(x, y, width, height);
} public void setColor(Color c) {
g.setColor(c);
} public void setFont(Font font) {
g.setFont(font);
} public void setPaintMode() {
g.setPaintMode();
} public void setXORMode(Color c1) {
g.setXORMode(c1);
} public void translate(int x, int y) {
g.translate(x, y);
}}
Graphics myg = new MyGraphics(g/*原始的Graphics对像*/);