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

📄 shapes2.java

📁 一个用Java写的
💻 JAVA
字号:
/****************************************************************** * Copyright (C) 2002-2006 Andrew Girow. All rights reserved.     * * ---------------------------------------------------------------* * This software is published under the terms of the TinyLine     * * License, a copy of which has been included with this           * * distribution in the TINYLINE_LICENSE.TXT file.                 * *                                                                * * For more information on the TinyLine,                          * * please see <http://www.tinyline.com/>.                         * *****************************************************************/package tinyapp;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.util.zip.*;import java.awt.image.*;import com.tinyline.svg.*;import com.tinyline.tiny2d.*;import com.tinyline.app.PPSVGCanvas;import com.tinyline.app.PlayerListener;import com.tinyline.app.SVGEvent;import com.tinyline.app.MouseHandler;/** * The <tt>Shapes</tt> application demostrates how to create basic * SVG shapes using the DOM-like API and the Direct TinyLine API. * <p> * This code is based on Kevin Lindsey SVG Tutorial that you can * find here at * http://www.kevlindev.com/tutorials/basics/shapes/svg/ * <p> * @author (C) Andrew Girow * @version 1.10 * <p> */public class Shapes2 extends Frame implements ActionListener{  // The menu  MenuBar menuBar1 = new MenuBar();  Menu menuFile = new Menu();  MenuItem menuExit;  MenuItem menuCircle, menuRect;  // The SVG canvas  PPSVGCanvas canvas;  // event handlers  MouseHandler currentMouseHandler;  /**   * Constructs a new <tt>Shapes</tt> instance.   */  public Shapes2()  {  }  public void init()  {    setLayout(null);    setTitle("Shapes SVG Demo");    // Create the SVG canvas    Dimension dim = getSize();    canvas = new PPSVGCanvas(dim.width-10,dim.height-10);    canvas.setBounds(5,5,dim.width-10,dim.height-10);    add(canvas);    // Add the default events listener    PlayerListener defaultListener = new PlayerListener(canvas);    canvas.addEventListener("default", defaultListener, false);    // Add the custom events listener    ShapesListener customListener = new ShapesListener(canvas);    canvas.addEventListener("", customListener, false);    // Sets the mouse handler    currentMouseHandler = new MouseHandler(canvas);    currentMouseHandler.type = MouseHandler.LINK_MOUSE;    canvas.addMouseListener(currentMouseHandler);    canvas.addMouseMotionListener(currentMouseHandler);    // Create and add menu items//   this.setBackground(SystemColor.control);    menuFile.setLabel("File");    menuExit = new MenuItem("Exit");    menuExit.addActionListener(this);    menuCircle = new MenuItem("Circle");    menuCircle.addActionListener(this);    menuRect = new MenuItem("Rect");    menuRect.addActionListener(this);    menuFile.add(menuCircle);    menuFile.add(menuRect);    menuFile.add(menuExit);    menuBar1.add(menuFile);    setMenuBar(menuBar1);    // This tells the canvas that it can draw the image.    // Loads the default font!!!    SVGDocument doc = canvas.loadSVG(getClass().getResourceAsStream("/tinyapp/images/helvetica.svg"));    SVGFontElem font = SVGDocument.getFont(doc,SVG.VAL_DEFAULT_FONTFAMILY);    SVGDocument.defaultFont = font;    // Start the event queue    canvas.start();    // Loads the background SVGT image    canvas.goURL( getClass().getResource("/tinyapp/images/shapes.svg").toExternalForm()   );  }  public static final int SHAPE_CIRCLE   = 0;  public static final int SHAPE_RECT     = 1;  public static final int USER_EVENT     = 100;  /**   * Performs the action defined for menu items.   */  public void actionPerformed(ActionEvent e)  {     Object source = e.getSource();     SVGEvent event = null;     if(source == menuExit)         System.exit(0);     else if(source == menuCircle)     {        event = new SVGEvent(USER_EVENT, new TinyNumber(SHAPE_CIRCLE ));        canvas.postEvent(event);     }     else if(source == menuRect)     {        event = new SVGEvent(USER_EVENT, new TinyNumber(SHAPE_RECT ));        canvas.postEvent(event);     }  }    /**     * Main. Runs the Shapes sample appplication     */    public static void main(String[] args)    {        Shapes2 shape = new Shapes2();        // Typical iPAQ or Zaurus dimentions 240 * 320        shape.setBounds(0,0,240,320);        shape.init();        // For desktops is better 480 * 480//      viewer.setBounds(0,0,480,480);        shape.setVisible(true);    }}

⌨️ 快捷键说明

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