Presentation.


86 views
Uploaded on:
Category: Sports / Games
Description
Presentation Interactive media Utilization of sound, picture, representation and video Makes applications "wake up" Presentation (cont.) We will concentrate on Picture control fundamentals Making smooth movements Tweaking activity applets Playing sound records (by means of AudioClip interface) Making picture maps
Transcripts
Slide 1

Presentation Multimedia Use of sound, picture, representation and feature Makes applications “come alive”

Slide 2

Introduction (cont.) We will concentrate on Image-control fundamentals Creating smooth movements Customizing activity applets Playing sound documents (through AudioClip interface) Creating picture maps

Slide 3

Loading, Displaying and Scaling Images Demonstrate some Java interactive media capacities java.awt.Image unique class (can\'t be instantiated) Can speak to a few picture record positions e.g., GIF, JPEG and PNG javax.swing.ImageIcon Concrete class

Slide 4

Objects of class Image must be made by means of strategy getImage Objects of class ImageIcon may be made by means of ImageIcon constructor Method drawImage showcases Image object on screen Overloaded system drawImage presentations scaled Image object on screen 1/LoadImageAndScale.java 2/Load a picture and presentation it in its unique size 3/and scale it to twice its unique width and stature. 4/Load and showcase the same picture as an ImageIcon. 5 6/Java center bundles 7 import java.applet.Applet; 8 import java.awt.*; 9 10/Java augmentation bundles 11 import javax.swing.*; 12 13 open class LoadImageAndScale broadens JApplet { 14 private Image logo1; 15 private ImageIcon logo2; 16 17/burden picture when applet is stacked 18 open void init () 19 { 20 logo1 = getImage( getDocumentBase(), "logo.gif" ); 21 logo2 = new ImageIcon( "logo.gif" ); 22 } 23 24/showcase picture 25 open void paint( Graphics g ) 26 { 27/draw unique picture 28 g.drawImage( logo1, 0 , 0 , this ); 29 30/attract picture scaled to fit width of applet 31/and stature of applet short 120 pixels 32 g.drawImage( logo1, 0 , 120 , 33 getWidth(), getHeight() - 120 , this ); 34 LoadImageAndScale.java Lines 14 and 20 Lines 15 and 21 Line 28 Lines 32-33

Slide 5

Method paintIcon shows ImageIcon object on screen 35/draw symbol utilizing its paintIcon system 36 logo2.paintIcon( this , g, 180 , 0 ); 37 } 38 39 }/end class LoadImageAndScale LoadImageAndScale.java (Part 2) Line 36 Program Output Size of the applet: 340 x 340

Slide 6

Animating a Series of Images Demonstrate quickening arrangement of pictures Images are put away in cluster

Slide 7

Create exhibit that stores arrangement of ImageIcon items 1/LogoAnimator.java 2/Animation a progression of pictures 3 4/Java center bundles 5 import java.awt.*; 6 import java.awt.event.*; 7 8/Java expansion bundles 9 import javax.swing.*; 10 11 open class LogoAnimator amplifies JPanel 12 executes ActionListener { 13 14 ensured ImageIcon images[];/cluster of pictures 15 16 secured int totalImages = 30 ,/number of pictures 17 currentImage = 0 ,/current picture file 18 animationDelay = 50 ,/millisecond delay 19 width,/picture width 20 tallness;/picture stature 21 22 ensured String imageName = "deitel" ;/base picture name 23 ensured Timer animationTimer;/Timer drives movement 24 25/introduce LogoAnimator by stacking pictures 26 open LogoAnimator() 27 { 28 initializeAnimation(); 29 } 30 31/instate activity 32 ensured void initializeAnimation() 33 { 34 pictures = new ImageIcon[ totalImages ]; 35 LogoAnimator.java Lines 14 and 34

Slide 8

Load ImageIcon objects into exhibit Override technique paintComponent of class JPanel to show ImageIcon s Timer conjures strategy actionPerformed each animationDelay ( 50 ) milliseconds 36/burden pictures 37 for ( int tally = 0 ; tally < images.length; ++count ) 38 images[ check ] = new ImageIcon( getClass().getResource( 39 "images/" + imageName + tally + ".gif" ) ); 40 41 width = images[ 0 ].getIconWidth();/get symbol width 42 stature = images[ 0 ].getIconHeight();/get symbol tallness 43 } 44 45/show current picture 46 open void paintComponent( Graphics g ) 47 { 48 super .paintComponent( g ); 49 50 images[ currentImage ].paintIcon( this , g, 0 , 0 ); 51 currentImage = ( currentImage + 1 ) % totalImages; 52 } 53 54/react to Timer\'s occasion 55 open void actionPerformed( actionEvent ) 56 { 57 repaint();/repaint artist 58 } 59 60/begin or restart liveliness 61 open void startAnimation() 62 { 63 if ( animationTimer == invalid ) { 64 currentImage = 0 ; 65 animationTimer = new Timer( animationDelay, this ); 66 animationTimer.start(); 67 } 68 else/proceed from last picture showed 69 if ( ! animationTimer.isRunning() ) 70 animationTimer.restart(); LogoAnimator.java (Part 2) Lines 37-39 Lines 46-52 Lines 55-58 and 65

Slide 9

Method stop demonstrates that Timer ought to quit producing occasions 71 } 72 73/stop activity clock 74 open void stopAnimation() 75 { 76 animationTimer.stop(); 77 } 78 79/return least size of movement 80 open Dimension getMinimumSize() 81 { 82 return getPreferredSize(); 83 } 84 85/return favored size of liveliness 86 open Dimension getPreferredSize() 87 { 88 return new Dimension( width, tallness ); 89 } 90 91/execute liveliness in a JFrame 92 open static void fundamental( String args[] ) 93 { 94/make LogoAnimator 95 LogoAnimator liveliness = new LogoAnimator(); 96 97/set up window 98 JFrame window = new JFrame( "Animator test" ); 99 100 Container holder = window.getContentPane(); 101 container.add( movement ); 102 103 window.setDefaultCloseOperation( JFrame. EXIT_ON_CLOSE ); 104 LogoAnimator.java (Part 3) Line 76

Slide 10

105/size and showcase window 106 window.pack(); 107 insets = window.getInsets(); 108 109 window.setSize( animation.getPreferredSize().width + 110 insets.left + insets.right, 111 animation.getPreferredSize().height + 112 insets.top + insets.bottom ); 113 114 window.setVisible( genuine ); 115 animation.startAnimation();/start liveliness 116 117 }/end strategy principle 118 119 }/end class LogoAnimator LogoAnimator.java (Part 4)

Slide 11

import java.applet.Applet; import java.awt.Graphics; open class Anim1a develops Applet executes Runnable { int position = 0; int increase = 3; Thread t; public void begin() { if (t == invalid) { t = new Thread(this); t.start(); } } public void stop() { if (t != invalid) { t.stop(); t = invalid; } } public void paint(Graphics g) { g.fillOval(5, 5 + position, 30, 30); }

Slide 12

public void run() { while (genuine) { attempt { Thread.sleep(50); } get (InterruptedException e) {} position += increase; if (position > 50 || position < 0) increment = - increase; repaint(); } } }

Slide 13

import java.applet.Applet; import java.awt.Graphics; open class Anim1n broadens Applet actualizes Runnable { int position = 0; int increase = 3; Thread t; open void begin() { if (t == invalid) { t = new Thread(this); t.start(); } open void stop() { t = invalid; } open void paint(Graphics g) { g.fillOval(5, 5 + position, 30, 30); } The rendition without belittled stop() system if (t != invalid) { t.stop(); t = invalid; }

Slide 14

public void run() { Thread thisThread = Thread.currentThread(); while ( t == thisThread ) { attempt { Thread.sleep(50); } get (InterruptedException e) {} position += increase; if (position > 50 || position < 0) increment = - increase; repaint(); } } }

Slide 15

import java.applet.Applet; import java.awt.Graphics; class Animation amplifies Thread { private Anim1c appl; private int increase = 3; Animation(Anim1c a) { appl = a; } public void run() { while (genuine) { attempt { Thread.sleep(50); } get (InterruptedException e) {} appl.setpos(increment); if (appl.getpos() > 50 || appl.getpos() < 0) increment = - increase; appl.repaint(); } } }

Slide 16

open class Anim1c augments Applet { private int position = 0; private Thread t; public void begin() { if (t == invalid) { t = new Animation(this); t.start(); } } open int getpos() { return position; } open void setpos(int a) { position += a; } open void stop() { if (t != invalid) { t.stop(); t = invalid; } } public void paint(Graphics g) { g.fillOval(5, 5 + position, 30, 30); } }

Slide 17

import java.applet.Applet; import java.awt.Graphics; class Animation augments Thread { private Applet appl; protected int increase = 3; protected int position = 0; protected int delay = 50; Animation(Applet a) { appl = a; } public void run() { while (genuine) { attempt { Thread.sleep(pause); } get (InterruptedException e) {} position += increase; if (position > 50 || position < 0) increment = - increase; appl.repaint(); } } public void draw(Graphics g) { g.fillOval(5, 5 + position, 30, 30); } }

Recommended
View more...