1 30 31 package com.jgoodies.animation.examples.intro; 32 33 import java.awt.Component ; 34 import java.awt.Container ; 35 import java.awt.Dimension ; 36 37 import javax.swing.JFrame ; 38 import javax.swing.JOptionPane ; 39 40 import com.jgoodies.animation.AnimationUtils; 41 import com.jgoodies.animation.Animator; 42 43 51 public final class Intro { 52 53 56 private static final int DEFAULT_FRAME_RATE = 30; 57 58 61 private IntroPage introPage; 62 63 64 public static void main(String [] args) { 65 int fps = DEFAULT_FRAME_RATE; 67 if (args.length > 0) { 68 try { 69 fps = Integer.parseInt(args[0]); 70 } catch (NumberFormatException e) { 71 System.out.println("Could not parse the custom frame rate: " + args[0]); 72 } 73 } 74 System.out.println("The desired framerate is " + fps + '.'); 75 new Intro(fps); 76 } 77 78 79 84 private Intro(int fps) { 85 buildFrame(); 86 87 Runnable runnable = new Runnable () { 88 public void run() { 89 JOptionPane.showMessageDialog(null, "The End."); 90 } 91 }; 92 93 AnimationUtils.invokeOnStop(introPage.animation(), runnable); 94 Animator animator = new Animator(introPage.animation(), fps); 95 animator.start(); 96 } 97 98 99 101 104 private void buildFrame() { 105 JFrame frame = new JFrame (); 106 frame.setContentPane(buildContent()); 107 frame.setSize(350, 150); 108 frame.setTitle("JGoodies Animation :: Intro"); 109 frame.setDefaultCloseOperation(3); locateOnScreenCenter(frame); 111 frame.setVisible(true); 112 } 113 114 115 120 private Container buildContent() { 121 introPage = new IntroPage(); 122 return introPage.build(); 123 } 124 125 126 128 133 private void locateOnScreenCenter(Component component) { 134 Dimension paneSize = component.getSize(); 135 Dimension screenSize = component.getToolkit().getScreenSize(); 136 component.setLocation( 137 (screenSize.width - paneSize.width) / 2, 138 (screenSize.height - paneSize.height) / 2); 139 } 140 141 142 } | Popular Tags |