首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

svg圆桌面应用程序(一)

2012-12-22 
svg桌面应用程序(一)在java中显示svg图?下载bakit工程http://xmlgraphics.apache.org/batik/download.cgi

svg桌面应用程序(一)

在java中显示svg图

?

下载bakit工程

http://xmlgraphics.apache.org/batik/download.cgi

介绍

http://xmlgraphics.apache.org/batik/index.html

?

?创建svg文档对象

?

String parser = XMLResourceDescriptor.getXMLParserClassName();SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);File file = new File("bin/com/longshine/svg/ui/3D.svg");Document indexDoc = f.createDocument(file.toURL().toString());

?

?

在swing面板中加入文档对象显示?

?

JSVGCanvas canvas = new JSVGCanvas();//用于显示svg图canvas.setBackground(Color.BLACK);canvas.setVisible(true);canvas.setBounds(0, 0, 800, 600);canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);canvas.setDocument(indexDoc);this.add(canvas);//swing面板中加入画布

?

?

svg圆桌面应用程序(一)

?

?

?

?

?

?

?

?

?

?

package com.longshine.svg.ui;import java.awt.Color;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import javax.swing.JFrame;import org.apache.batik.dom.svg.SAXSVGDocumentFactory;import org.apache.batik.swing.JSVGCanvas;import org.apache.batik.util.XMLResourceDescriptor;import org.w3c.dom.Document;public class SVGUIApp extends JFrame{public void init(){this.setBounds(0, 0, 800, 600);this.setDefaultCloseOperation(3);this.setVisible(true);String parser = XMLResourceDescriptor.getXMLParserClassName();SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);File file = new File("bin/com/longshine/svg/ui/3D.svg");try {Document indexDoc = f.createDocument(file.toURL().toString());JSVGCanvas canvas = new JSVGCanvas();canvas.setBackground(Color.BLACK);canvas.setVisible(true);canvas.setBounds(0, 0, 800, 600);canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);canvas.setDocument(indexDoc);this.add(canvas);} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}public static void main(String[] args){new SVGUIApp().init();}}

?

?

?

?

热点排行