当前位置: 首页>>代码示例>>Java>>正文


Java Component.getGraphics方法代码示例

本文整理汇总了Java中java.awt.Component.getGraphics方法的典型用法代码示例。如果您正苦于以下问题:Java Component.getGraphics方法的具体用法?Java Component.getGraphics怎么用?Java Component.getGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Component的用法示例。


在下文中一共展示了Component.getGraphics方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BufferedImageGraphicsConfig

import java.awt.Component; //导入方法依赖的package包/类
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.width = bufImg.getWidth();
    this.height = bufImg.getHeight();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:BufferedImageGraphicsConfig.java

示例2: aplicarTextura

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Aplicar uma textura no gráfico passado por parâmetro
 * @param textura imagem da textura a ser aplicada
 * @param component Gráfico que receberá a textura
 */
public static void aplicarTextura(ImageIcon textura, Component component) {
    BufferedImage bi = Img.ImageIconToBufferedImage(textura);
    Graphics2D g2 = (Graphics2D) component.getGraphics();
    Rectangle r = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
    g2.setPaint(new TexturePaint(bi, r));
    Rectangle rect = new Rectangle(0, 0, component.getWidth(), component.getHeight());
    g2.fill(rect);
    g2.dispose();
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:15,代码来源:Img.java

示例3: BufferedImageGraphicsConfig

import java.awt.Component; //导入方法依赖的package包/类
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp,
                                   double scaleX, double scaleY)
{
    if (comp == null) {
        this.gd = new BufferedImageDevice(this);
    } else {
        Graphics2D g2d = (Graphics2D)comp.getGraphics();
        this.gd = g2d.getDeviceConfiguration().getDevice();
    }
    this.model = bufImg.getColorModel();
    this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
    this.scaleX = scaleX;
    this.scaleY = scaleY;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:BufferedImageGraphicsConfig.java

示例4: CanvasWrapper

import java.awt.Component; //导入方法依赖的package包/类
public CanvasWrapper(MithrilClient mithrilClient, Component parent, ReflectionHooks hooks) {
	this.mithrilClient = mithrilClient;
	this.parent = parent;
	this.hooks = hooks;
	this.wrapper = new GraphicsWrapper(parent.getGraphics(), this);
}
 
开发者ID:jonathanedgecombe,项目名称:mithril,代码行数:7,代码来源:CanvasWrapper.java

示例5: paint

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:68,代码来源:RepaintArea.java

示例6: paint

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to {@code paint} or {@code update}
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:68,代码来源:RepaintArea.java


注:本文中的java.awt.Component.getGraphics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。