⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawsample.java

📁 JSP中文介绍,对于菜鸟有用
💻 JAVA
字号:
import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.font.FontRenderContext;import java.awt.font.TextLayout;import java.awt.geom.Point2D;import java.text.AttributedCharacterIterator;/** * This class shows how to construct and draw a TextLayout. * * This class constructs a TextLayout from an  * AttributedCharacterIterator and draws it. */public class DrawSample extends Component {    // The TextLayout to draw.    private TextLayout textLayout;    public DrawSample(AttributedCharacterIterator text) {        FontRenderContext frc = SampleUtils.getDefaultFontRenderContext();        // Create a new TextLayout from the given text.        textLayout = new TextLayout(text, frc);    }    /**     * Compute a location within this Component for textLayout's origin,     * such that textLayout is centered horizontally and vertically.     * Note that this location is unknown to textLayout;  it is used only     * by this Component for positioning.     */    private Point2D computeLayoutOrigin() {        Dimension size = getSize();        Point2D.Float origin = new Point2D.Float();        origin.x = (float) (size.width - textLayout.getAdvance()) / 2;        origin.y = (float) (size.height - textLayout.getDescent() + textLayout.getAscent()) / 2;        return origin;    }    /**     * Draw textLayout.     */    public void paint(Graphics g) {        Graphics2D graphics2D = (Graphics2D) g;        Point2D origin = computeLayoutOrigin();        // Draw textLayout at origin.        textLayout.draw(graphics2D, (float) origin.getX(), (float) origin.getY());    }    public static void main(String[] args) {        AttributedCharacterIterator text = SampleUtils.getText(args);        Component sample = new DrawSample(text);        SampleUtils.showComponentInFrame(sample, "Draw Sample");    }}

⌨️ 快捷键说明

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