f0d86c65cb10001c1943ad5354082a0e

来自「Internet 开发技术分章节代码和自己完成的课程设计全代码(在zuoye文件」· 代码 · 共 70 行

TXT
70
字号
import java.awt.*;
import java.io.*;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;

public class draw1{

 

    public void paint(Graphics2D g2d) {

        g2d.setPaint(Color.red);

        g2d.fill(new Rectangle(10, 10, 100, 100));

    }

 

    public static void main(String [] args) throws IOException {

        // Get a DOMImplementation

        DOMImplementation domImpl =

            GenericDOMImplementation.getDOMImplementation();

        String svgNamespaceURI = "http://www.w3.org/2000/svg";

 

        // Create an instance of org.w3c.dom.Document

        Document document = 

            domImpl.createDocument(svgNamespaceURI, "svg", null);

 

        // Create an instance of the SVG Generator

        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

 

        // Render into the SVG Graphics2D implementation

        draw1 test = new draw1();

        test.paint(svgGenerator);

 

        // Finally, stream out SVG to the standard output using UTF-8

        // character to byte encoding

        boolean useCSS = true; // we want to use CSS style attribute

        Writer out = new OutputStreamWriter(System.out, "UTF-8");

        svgGenerator.stream(out, useCSS);

    }

}

⌨️ 快捷键说明

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