home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-10-03 | 2.3 KB | 85 lines |
- /*
- * @(#)Example1.java 1999/09/28
- *
- * Copyright (c) 1999, David Griffiths. All Rights Reserved.
- *
- * This software is the proprietary information of David Griffiths.
- * This source code may not be published or redistributed without the
- * express permission of the author.
- *
- * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
- * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- */
-
- /**
- * This first example creates a GIF animation of a coloured square in motion.
- * @version 1.0 1999/09/28
- * @author David Griffiths
- */
-
- import java.util.Hashtable;
- import java.io.*;
- import java.awt.*;
- import java.awt.event.*;
-
- public class Example1 {
- private Frame frm;
- private Animator animator;
- private Graphics g;
- private final static int WIDTH = 200;
- private final static int HEIGHT = 200;
- private final static int BORDER = 20;
-
- public static void main (String[] args) {
- Example1 g = new Example1();
- g.init();
- }
-
- public void init() {
- frm = new Frame();
- frm.setLayout(new BorderLayout());
- frm.setTitle("Processing...");
- frm.setSize(WIDTH, HEIGHT + BORDER);
- frm.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- public void windowOpened(WindowEvent e) {
- createAnim();
- }
- });
- frm.show();
- }
-
- private void createAnim() {
- Image imgMain = frm.createImage(WIDTH, HEIGHT);
- Graphics gMain = imgMain.getGraphics();
-
- animator = Animator.getInstance("GIF", WIDTH, HEIGHT);
- animator.setFPS(40);
- g = frm.getGraphics();
-
- for (int i = 0; i < 100; i+= 3) {
- gMain.setColor(Color.white);
- gMain.fillRect(0, 0, WIDTH, HEIGHT);
- gMain.setColor(new Color(2 * i, 0, 255 - 2 * i));
- gMain.fillRect(i, i, 100, 100);
- animator.addImage(imgMain, frm);
- g.drawImage(imgMain, 0, BORDER, frm);
- }
-
- try {
- animator.getAnimation().serializeTo(new PrintStream(
- new FileOutputStream("ex1.gif")));
- }
- catch (IOException e) {
- }
-
- System.exit(0);
- }
- }
-