不需要啊,直接g.drawLine(x1,y1,x2,y2)就ok了

解决方案 »

  1.   


    DebugGraphicsjava.lang.Object
      java.awt.Graphics
          javax.swing.DebugGraphics 
    void drawLine(int x1, int y1, int x2, int y2) 
              Overrides Graphics.drawLine. drawLine
    //此方法可以画
    public void drawLine(int x1,
                         int y1,
                         int x2,
                         int y2)Overrides Graphics.drawLine. Specified by:
    drawLine in class Graphics
    Parameters:
    x1 - the first point's x coordinate.
    y1 - the first point's y coordinate.
    x2 - the second point's x coordinate.
    y2 - the second point's y coordinate.
      

  2.   

    TO JavaVsNet(JavaVsNet)我知道啊,但是现在在做图形学的作业,必须自己用算法实现画线啊!
    这个算法是一个个的填充象素,我找不到setPixs()函数
    所有就想在自己定义的paintLine()函数里给drawLine()函数两个相等的端点画一个点
      

  3.   

    TO swallowsky(我是流氓,我怕谁)看到了,谢谢,
      

  4.   

    没想过,DebugGraphics中的源码为:
    public void drawLine(int x1, int y1, int x2, int y2) {
            DebugGraphicsInfo info = info();        if (debugLog()) {
                info().log(toShortString() +
                           " Drawing line: from " + pointToString(x1, y1) +
                           " to " +  pointToString(x2, y2));
            }        if (isDrawingBuffer()) {
                if (debugBuffered()) {
                    Graphics debugGraphics = debugGraphics();                debugGraphics.drawLine(x1, y1, x2, y2);
                    debugGraphics.dispose();
                }
            } else if (debugFlash()) {
                Color oldColor = getColor();
                int i, count = (info.flashCount * 2) - 1;            for (i = 0; i < count; i++) {
                    graphics.setColor((i % 2) == 0 ? info.flashColor : oldColor);
                    graphics.drawLine(x1, y1, x2, y2);
                    Toolkit.getDefaultToolkit().sync();
                    sleep(info.flashTime);
                }
                graphics.setColor(oldColor);
            }
            graphics.drawLine(x1, y1, x2, y2);
        }试图追踪最终的实现,但是竟然到了sun.awt.SunGraphicsCallback,这是个没有公开源码的类,在rt.jar包里,晕...
      

  5.   

    用Dj可以反编译,不过里面的类库太多,有本书里专门讲过sun里没公开过的包,不过忘了名字
      

  6.   

    TO JavaVsNet(JavaVsNet):就是说DebugGraphics里也没有实现画线功能了?
    一般在一个Frame里画线的时候
    public class MyFrame extends JFrame
    {
       public MyFrame()
      {
      }
      public void paint(Graphics g)
     {
         g.drawLine(....); //这里的g是Graphics类型的,但是Graphics并没有
         g.drawxxxx();     //实现drawLine()等函数,那么我想这个g应该是一个继承了
    }                      //Graphics的类(并实现了drawLine()等抽象函数)的一个对象
                          //那这个类是什么啊????
      

  7.   

    555555555555那我应该怎么办??如果JAVA里有setPixel()函数就好了
      

  8.   

    不对,就算有setPixel()函数,我也要找到实现了它的类才可以啊
      

  9.   

    Graphics2D可以实现很多功能
    那个g实际是继承自Graphics2D
      

  10.   

    我查了文档,发现Graphics2D也没有实现drawLine()函数,而且简单的从Graphics继承了这个函数.....
      

  11.   

    最终实现是在sun.awt.SunGraphicsCallback这里了,这些可能接近底层,sun都隐藏了.
      

  12.   

    hxshandle(有妖怪啊)说的有道理
    可以使用inner类
    在public void paint(Graphics g)里写一个类,类里有自己定义的画点,画线函数。然后就可以直接调用g.drawLine()函数画点了。(但是我觉得用画线的函数画点非常不爽,有没有直接画点的函数???)你们说呢???
      

  13.   

    说来说去到底是什么实现drawLine啊,哪里都没有定义这个方法,为什么会实现画图呢?顶!
      

  14.   

    我记得JAVA2D里面有个叫Line2D的类可以直接自动连接的!
    Line2D.float(start x,start y,end x,end y);
    只要点两点就可以了。不像Drawline()那样一直跟踪鼠标的!
      

  15.   

    去api里面慢慢找吧
    我以前也找过一次
    不过现在真的又想不起来了
      

  16.   

    drawLine除了draw line还能干什么,为什么还要用到Graphics呢画东西直接用paint里面穿过来的,那个不知具体是什么class的Graphics就可以了,
    而且知道这个class的方法再简单不过了
    public void paint(Graphics g) {
      System.out.println(g.getClass());
    }