dvgraphicsinfox.java

来自「ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c」· Java 代码 · 共 92 行

JAVA
92 行
字号
package edu.odu.cs.zeil.AlgAE.Client.DataViewer;import java.awt.Canvas;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Image;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.GraphicsInfo;/** *  Graphics context information, with support for double buffering. * *  @author Steven J. Zei */public class DVGraphicsInfo extends GraphicsInfo{  /**   *  The image that new drawing is written into.   */  Image drawTo;  /**   *  The image with old drawing that the canvas is repainted from.   */  Image repaintFrom;    /**   *  Build a graphics context.   *   *  @param c The canvas that this graphic information is associated with.   */  DVGraphicsInfo()  {    super();    repaintFrom = drawTo = null;    textOffset.width = 0;  }    /**   *  Initialize the graphics data member <code>g</code> to a valid   *  graphics context and sets the canvasSize and textOffset values.   */  public void openGraphics()  {    canvasSize = canvas.getSize();    if (drawTo == null)      {	drawTo = canvas.createImage (canvasSize.width, canvasSize.height);	g = drawTo.getGraphics();	g.setColor(canvas.getBackground());	g.fillRect(0, 0, canvasSize.width, canvasSize.height);	g.setFont (font);	if (textOffset.width == 0)	  {	    FontMetrics fm = g.getFontMetrics();	    textOffset.width = (fm.charWidth('X') + 1) / 2;	    textOffset.height = (fm.getAscent() + 1) / 2;	  }      }  }    /**   *  Indicates that the graphics data member <code>g</code> is no longer   *  in use.   *   *  @param wasWrittenTo  Input parameter, true if anything has been   *     written to the graphics context since it was opened.   *     False if we were "only looking".   */  public void closeGraphics(boolean wasWrittenTo)  {    if (wasWrittenTo)      {	repaintFrom = drawTo;	drawTo = null;      }  }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?