<HTML>
<HEAD>
<TITLE>DirectX Media SDK DirectAnimation Tutorial</TITLE>
<LINK REL=STYLESHEET HREF="../../../../../webcd/da/tutorial.css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="ROBOTS" CONTENT="noindex">
</HEAD>
<BODY BGCOLOR="WHITE" LINK=#0033CC TOPMARGIN=0 LEFTMARGIN=20>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->

<DIV CLASS="flush">
<TABLE WIDTH=100% BORDER=0 BGCOLOR=#000000>
<TR ALIGN=RIGHT><TD VALIGN=TOP><FONT CLASS=desc1 SIZE=2>
<A HREF="Section2.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_prev.gif"
 WIDTH=71 HEIGHT=16 BORDER=0 ALT="Previous Topic">
</A><A HREF="../../../../../webcd/da/tutorial_main.htm" TARGET="_top">
<IMG SRC="../../../../../media/image/d_home.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Tutorial Home Page"></A>
<IMG SRC="../../../../../media/image/d_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</FONT></TD><TD WIDTH=30></TD></TR></TABLE></DIV>
<FONT CLASS=title><CENTER>Section 3: Use AWT Controls</CENTER></FONT>
<BR>
<FONT CLASS=code>
</FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> This class extends Panel. It has four buttons - pause, restart, fast forward,
 rewind - and a scrollbar.  The scrollbar is used to control the playback rate
 at a finer level.</TD></TR></FONT></TABLE>
<FONT CLASS=code>class Controls extends Panel {<BR>
</FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Place the scrollbar at the center, then two buttons on either side.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">Controls(VCRModel movie) {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">_movie = movie;<BR>
setLayout(new BorderLayout());<BR>
</DIV><BR>
<DIV STYLE="margin-left: 0.25in">_rateBar = new Scrollbar(Scrollbar.HORIZONTAL, 10, 1, -40, 40);<BR>
add("Center", _rateBar);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Pause and restart buttons on the west side.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">Panel pWest = new Panel();<BR>
pWest.setLayout(new GridLayout(1, 2));<BR>
pWest.add(new Button("| |"));<BR>
pWest.add(new Button("&gt"));<BR>
add("West", pWest);<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Fast forward and rewind buttons on the east side.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.25in">Panel pEast = new Panel();<BR>
pEast.setLayout(new GridLayout(1, 2));<BR>
pEast.add(new Button("&gt&gt"));<BR>
pEast.add(new Button("&lt&lt"));<BR>
add("East", pEast);<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> The event handler when any buttons are pressed.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.125in">public boolean handleEvent(Event ev) {<BR>
</DIV><DIV STYLE="margin-left: 0.25in">switch (ev.id) {<BR>
</DIV><DIV STYLE="margin-left: 0.375in">case Event.SCROLL_LINE_UP:<BR>
case Event.SCROLL_LINE_DOWN:<BR>
case Event.SCROLL_PAGE_UP:<BR>
case Event.SCROLL_PAGE_DOWN:<BR>
case Event.SCROLL_ABSOLUTE:<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Scroll position changed: Clear the pause state, set the rate to
 the current scroll position.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.5in">_bPaused = false;<BR>
_movie.setRate(_rateBar.getValue());<BR>
return true;<BR>
</DIV><BR>
<DIV STYLE="margin-left: 0.375in">case Event.ACTION_EVENT:<BR>
</DIV><DIV STYLE="margin-left: 0.5in">if (ev.arg == "| |") {<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Pause: Toggle the pause state.  This means that pressing the pause
 button the second time resumes the normal playback rate.
 The normal playback rate is 10, the pause rate is 0.
 Need to reflect the current rate in the scrollbar.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.625in">int rate;<BR>
if (_bPaused) {<BR>
</DIV><DIV STYLE="margin-left: 0.75in">_bPaused = false;<BR>
rate = 10;<BR>
</DIV><DIV STYLE="margin-left: 0.625in">} else {<BR>
</DIV><DIV STYLE="margin-left: 0.75in">_bPaused = true;<BR>
rate = 0;<BR>
</DIV><DIV STYLE="margin-left: 0.625in">}<BR>
_movie.setRate(rate);<BR>
_rateBar.setValue(rate);<BR>
return true;<BR>
</DIV><DIV STYLE="margin-left: 0.5in">} else if (ev.arg == "&gt") {<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Restart: Clear the pause state, restart the movie at normal rate.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.625in">_bPaused = false;<BR>
_movie.restart();<BR>
_rateBar.setValue(10);<BR>
return true;<BR>
</DIV><DIV STYLE="margin-left: 0.5in">} else if (ev.arg == "&gt&gt</FONT><FONT CLASS=desc2> {// Fast forward</FONT><FONT CLASS=code><BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> FastForward: Clear the pause state, set rate to 30 and update the
 scrollbar position.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.625in">_bPaused = false;<BR>
_movie.setRate(30);<BR>
_rateBar.setValue(30);<BR>
return true;<BR>
</DIV><DIV STYLE="margin-left: 0.5in">} else if (ev.arg == "&lt&lt") {<BR>
</DIV></FONT>
<BR>
<TABLE><TR><TD WIDTH=500><FONT CLASS=desc1> Rewind: Clear the pause state, set rate to -30 and update the
 scrollbar position.</TD></TR></FONT></TABLE>
<FONT CLASS=code><DIV STYLE="margin-left: 0.625in">_bPaused = false;<BR>
_movie.setRate(-30);<BR>
_rateBar.setValue(-30);<BR>
return true;<BR>
</DIV><DIV STYLE="margin-left: 0.5in">}<BR>
</DIV><DIV STYLE="margin-left: 0.25in">}<BR>
return false;<BR>
</DIV><DIV STYLE="margin-left: 0.125in">}<BR>
</DIV><BR>
<DIV STYLE="margin-left: 0.125in">boolean _bPaused = false;<BR>
Scrollbar _rateBar;<BR>
VCRModel _movie;<BR>
</DIV>}<BR>
<BR>
<BR>
</FONT><FONT CLASS=link><A ID=cpslug HREF="../../../../../help/da/dalegal.htm" TARGET="_top">&#169; 1997 Microsoft Corporation. All rights reserved. Terms of Use.</A></FONT>

<BR>
<BR>
<DIV CLASS="flush">
<TABLE WIDTH=100% BORDER=0 BGCOLOR=#000000>
<TR ALIGN=RIGHT><TD VALIGN=TOP><FONT CLASS=desc1 SIZE=2>
<A HREF="Section2.html" TARGET="_top">
<IMG SRC="../../../../../media/image/u_prev.gif"
 WIDTH=71 HEIGHT=16 BORDER=0 ALT="Previous Topic">
</A><A HREF="../../../../../webcd/da/tutorial_main.htm" TARGET="_top">
<IMG SRC="../../../../../media/image/d_home.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Tutorial Home Page"></A>
<IMG SRC="../../../../../media/image/d_next.gif" WIDTH=48 HEIGHT=16 BORDER=0 ALT="Next Topic">
</FONT></TD><TR><TD WIDTH=30></TD></TR></TABLE></DIV>
</BODY>
</HTML>
