File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes animating a gif Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "animating a gif" Watch "animating a gif" New topic
Author

animating a gif

jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
Hi,
I have been trying to build an applet to make a book open and print text into the gif image from a HTML file and I am completely stumped. I have read several tutorials and am very confused.
Please, if you can give me any direction on which way to go it would help me immensely.
Ps. I can code but am not sure how to interface images and text.
jim
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Hi Jim!
I am not sure I understand your question, particularly the part about "print text into the gif image from a HTML file". Is it possible for you to word your question a different way or perhaps give a link to a site which does what you want so we could see an example?
Thanks.
Stephanie
jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
Stephanie,
Basically all I am trying to do is get a book object to animate open into a two page format which then displays the text files that I want the book to show.
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Jim,
Do you already have the images files to make the book animation and want to know how to display the animation or are you trying to draw these yourself? I am still not clear. Maybe if you post the code you've completed so far it would help.
Thanks.
Stephani
jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
hi,
All I really have now is a picture of a book, a picture of an open book, and a HTML file with text. I am new to JAVA and have read several tutorials. I have been trying to put text boxes into gif's and write my code there but have had no luck. A publisher told me I would have to make a JAVA applet.
I really need general information right now like what methods I can call to call the open book and write text into them or should I just use the open book as a background image and write a type of layer over it.
jim
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Hi Jim,
Well, your idea about

should I just use the open book as a background image and write a type of layer over it

would definitely be the easiest thing to do.
One very simple example would be something like:

Of course, this assumes that you have openBook.gif in the same directory as the html file that includes your applet code and that the book picture is the proper size. (Also, you would probably have to play around with where the text is drawn in the paint() method to get it to look right).
Also, in the example above, the text printed is just an array of Strings. You had said you wanted to read it from an html file, so you would probably have to use the URL class to do so. Here is a helpful link about this:
http://java.sun.com/docs/books/tutorial/networking/urls/index.html
In particular, look at the section titled "Reading Directly from a URL".
Also, the example above does not format the text (font, size, bold or italic, etc.). If it is important to you to keep the formating, one idea would be to use a JEditorPane over the book image. This class can be constructed using the URL of your html file, then set to read-only so the user can't edit it.
There are several ways to implement animation, but frankly I don't think a two-image animation is worth that much effort. Unless you include more frames between the book being closed and the book being open, it probably won't really look like it is opening. However, if you decide this is an important issue, let us know and I
will look for some sample code for you.
I hope this is helpful and not confusing. Being new to Java you have taken on a pretty aggressive first project. I applaud your effort. If anything I've said is not clear or I have misunderstood your goal, please post again and I'll try to get you more examples.
Stephanie
[This message has been edited by Stephanie Grasson (edited March 20, 2001).]
jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
Stephanie,
Thanks, that should keep me busy for a little while. Also, I am very interested in having the book look like it is opening. I would like to make it look realistic as possible and would really appreciate it if you could tell me where some additional code is.
jim
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Jim,
This is a slightly modified version of some code from pp.260-263 of Java2 for Professional Developers by Michael Morgan. It creates an applet which displays an animation.

It assumes that images "Book1.gif" through "Book9.gif" are in the same directory as the html file that includes the applet. You could substitute in your book images if you'd like to see how they would look so far, but I really suspect you will need more than 2 to make it convincing.
I hope this is helpful for you.
Stephanie
jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
Stephanie,

I cant begin to thank you enough. I've been looking everywhere for something to start with and this is just too good to be true.
Thanks again.
jim
jim, valenta
Ranch Hand

Joined: Mar 16, 2001
Posts: 47
Stephanie,
Is it too late to clarify something??
When you said "Of course, this assumes that you have openBook.gif in the same directory as the html file that includes your applet code and that the book picture is the proper size."
The open book will be approximately twice as large as the closed book, will that be alright?? Or did you mean that the gif should be able to fit into the applet?
jim
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Jim,

When you said "Of course, this assumes that you have openBook.gif in the same directory as the html file that includes your applet code and that the book picture is the proper size." The open book will be approximately twice as large as the closed book, will that be alright?? Or did you mean that the gif should be able to fit into the applet?

You need to account for all three things:
(1)
The book gif should be large enough so that there is room to diplay text on it (or you should stretch it before displaying).
(2)
The gif definitely needs to fit in the applet. You can account for that when you write your html file that contains the applet. For example, lets say that the gif of the open book is 200 pixels wide and 100 pixels high. When you specify the width and height of the applet in your html code, you need to make sure they are at least big enough to hold the gif. For example:

<HTML>
<APPLET CODE = "BookApplet.class" WIDTH = 200 HEIGHT = 100>
</APPLET>
</HTML>

would make the applet just big enough to hold the gif and nothing else.
(3)
About the open book being twice as big as the closed book:
generlly speaking, all frames in an animation are the same size. One idea would be to make all gifs the same size using a background. This could be as simple as a solid color rectangle. The closed book would probably be on the right side of this rectangle, whereas the open book would be in the middle. Picture a real book closed on a desk. The desk would be analogous to the background. When the book opened, the part of the desk covered by opening it would be to the left of the original book position. Does that make sense?
One other thought: the example animation applet runs the animation while the browser is open to that page. I would think you would not want to run your animation continuously like that. One idea would be to show the book opening animation only when the applet first started. Then include a button in your applet called Turn Page. The animation of a page turning could be played whenever the user clicked that button, and the code to update the text to show the next portion could also be here. Just a thought.
Good luck.
Stephanie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: animating a gif