/* * [TestPan.java] * * Summary: Test smooth scrolling. * * Copyright: (c) 1998-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2002-06-28 original. */ package com.mindprod.smooth; import javax.swing.JFrame; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.RenderingHints; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /** * Test smooth scrolling. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2002-06-28 original. * @since 2002-06-28 */ public class TestPan implements Runnable { public static void main( String[] args ) { // size of big image will slowly pan int w = 800; int h = 600; JFrame f = new JFrame(); f.pack(); Image bigImage = f.createImage( w, h ); if ( bigImage == null ) { System.out.println( "failed to create image" ); } Graphics g = bigImage.getGraphics(); Graphics2D g2d = null; if ( g instanceof Graphics2D ) { g2d = ( Graphics2D ) g; g2d.addRenderingHints( new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ) ); } g.setColor( Color.RED ); g.fillRect( 0, 0, w, 168 ); g.setColor( Color.BLUE ); g.fillRect( 0, 168, w, h ); g.setColor( Color.WHITE ); g.setFont( new Font( "Arial", Font.BOLD, 48 ) ); FontMetrics fm = g.getFontMetrics(); int strHeight = fm.getHeight(); g.drawString( "AQUEDUCT", ( ( w - fm.stringWidth( "AQUEDUCT" ) ) / 2 ), strHeight ); int y = strHeight + 168; for ( int i = 0; i < h / strHeight; i++ ) { g.drawString( i + " Now is the time for all good men to come to the aid of the party.", 10, y ); y += strHeight; } // start the scroll. ScrollingImage tp = new ScrollingImage( bigImage, /* image to scroll */ 100, /* slowness */ 200, /* height */ new TestPan() /* notify */ ); tp.setBackground( Color.green ); f.getContentPane().add( tp ); f.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent we ) { System.exit( 0 ); } } ); f.pack(); f.setVisible( true ); } public void run() { System.out.println( "scrolling cycle complete." ); } }