http://www.sureshotsoftware.com/webeffects/slideshow/index.html
It probably uses the AlphComposite class as shown
in this text based example..
<http://java.sun.com/products/java-media/2D/samples/FadeTextSplash.java>
(I have also used AC for fading images, but that
source is stand alone and uses the same technique)
I am sure there was also a good demo using images
in the Graphics2D demo.
HTH
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200707/1
Thanks ,
I downloaded and tested this code below
http://java.sun.com/developer/technicalArticles/Threads/applet/SlideShow.java
now I'd change its paint process >>>>
try {
while ( noStopRequested ) {
waitWhilePaused();
curFrame = ( curFrame + 1 ) % images.length;
repaint();
Thread.sleep(3000);
}
http://java.sun.com/products/java-media/2D/samples/FadeTextSplash.java
with that in your >>>
http://java.sun.com/products/java-media/2D/samples/FadeTextSplash.java
and I'm confused about all of these different method....
Can give me a little help ?
Thanks a lot in advance.
> and I'm confused about all of these different method....
> Can give me a little help ?
You are tackling something a little too difficult for this stage --
trying to run before you walk. I suggest you give yourself a drawing
problem without any animation to start.
See http://mindprod.com/products.html#SCREWS
Something on that order.
Perhaps you might tackle drawing a graph given a set of points.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Compliment for your fine and rich work .
I understand your Srews applet...but is rather distant to my "fade"
problem .Have you something nearest ?
Many thanks.
>
>Compliment for your fine and rich work .
>I understand your Srews applet...but is rather distant to my "fade"
>problem .Have you something nearest ?
It is closer than you think.
Try doing something like screws and have a "FADE" button. Each time
you hit it it adds a constant to the background colour and calls
repaint.
Now you can see the fade effect by rapidly tapping the button.
Now read up on timers, http://mindprod.com/jgloss/timer.html
to figure out how to automate somebody tapping your fade button many
times a second.
You are then very close.
I've found the fade effect I was looking for here >>>
http://www.fouda.de/html/applets/effects.htm
and it is not job of AlphComposite class to do fade , but of
MemoryImageSource Class .
>How can be obtained the grate effects as in this applet >>>> ?
>
>http://www.sureshotsoftware.com/webeffects/slideshow/index.html
the authors are offering the software free. The download button
appears broken. I would contact the author and ask for the source.
failing that download the applet and decompile it.
se.bysoft.sureshot.products.webeffects.applet.SlideShowApplet.class in
jar slideshow.jar and resources.jar
See http://mindprod.com/jgloss/decompiler.html
The way to do that is with AlphaComposite as Andrew Thompson said. It
is actually fairly simple to do the drawing. The complicated part is
the logic to flip through the images. If you don't like my images,
specify some of your own. They might not have anything different on
them depending on when you try this. They come from one of my webcams.
You can play with the timing to get the transitions to happen as you
like them.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class Fader extends JPanel implements Runnable {
final BufferedImage[] images = new BufferedImage[6];
volatile BufferedImage first,next;
volatile AlphaComposite comp1 =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
volatile AlphaComposite comp2 =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f);
public Fader() {
try {
for (int i=0; i<images.length; i++)
images[i] = ImageIO.read(
// new File(Integer.toString(i+1) + "0_min_ago.jpg"));
new URL("http://www.thealpacastore.com/alpacacam/" +
Integer.toString(i+1) + "0_min_ago.jpg"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
setPreferredSize(new Dimension(
images[0].getWidth(),images[0].getHeight()));
}
public void run() {
while (true) {
for (int i=0; i<images.length; i++) {
first = images[i];
if (i < images.length - 1)
next = images[i+1];
else
next = images[0];
for (int j=0; j<60; j++) {
comp1 = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER,1.0f / (j + 1));
comp2 = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER,(j + 1) / 60.0f);
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ie) { }
}
try {
Thread.sleep(1000);
} catch (InterruptedException ie) { }
}
}
}
public void paintComponent(Graphics g2D) {
Graphics2D g = (Graphics2D)g2D;
g.setComposite(comp1);
g.drawImage(first,0,0,null);
g.setComposite(comp2);
g.drawImage(next,0,0,null);
}
public static void main(String[] args) {
Runnable r = new Runnable() {
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Fader fader = new Fader();
frame.add(fader);
frame.pack();
frame.setVisible(true);
new Thread(fader).start();
}
};
EventQueue.invokeLater(r);
}
}
--
Knute Johnson
email s/nospam/knute/
The Jad decompilation gives an anonymous source...but its recompilation
works fine. For example , five different methods are named "a"
(...with different arguments)
and many fields have lost their own name... (see below).I suppose
there isn't
nothing to do, is it ?
_flddo = new Image[e];
_fldlong = new String[e];
_fldgoto = new String[e];
a = new String[e];
_fldchar = new String[e];
_fldbyte = new Font[e];
_fldtry = new int[e];
_fldnew = new int[e];
_fldelse = new boolean[e];
_fldcase = new Color[e];
_fldint = new int[e];
Thanks a lot for your code.
I had the code from
http://www.fouda.de/html/applets/effects.htm
that uses MemoryImageSource Class .....and now seems more complex....
Only the applet version has problems about an " access denied "...though
the images files are in the same folder of the .class file (this has
allowed to work the application version...)
Thanks again.
Applets generally can't read files. Applets can get files from their
own jar or from a socket connection to the same server that serves the
Applet.
Also from ..
URL url = new URL(apple.getDocumentBase(), "pic1.gif");
.which should give an URL pointing to pic1.gif in the same
directory as the web page.
Resources on the server do not need to be jar'ed,
to be accessible by URL.
Yes. Absolutely. I'm so used to packing everything into jars I forgot
about that.
Otherwise you must include it as a resource in the jar.
See http://mindprod.com/jgloss/resource.html
There is nothing you can do since the names of local variables are
not included in the class file.
You can use IntelliJ with the global renamer. As you get more and
more vars renamed, the code will make more and more sense, making it
easier to rename other vars.
No. This is wrong. Resources in the code's
archives can be accessed via getResource() -
to get an URL - but if you can form *any*
valid URL to the same server, an applet can
reach 'above' its own codebase to fetch
resources. Here is the proof.
I have an applet here..
http://www.physci.org/test/applet/access/
You can verify from the HTML that the
codebase is ".", the current directory,
deep within the 'test' directory of my
site. It tries to fetch the index.html
at the root of the site, and display it
in a JEditorPane. It works just 'fine'*
here in Java 6/IE 6/Win XP. * Rendering
is a bit off, but then, the document
might be a bit malformed.
Here is the applet code..
<sscce>
import javax.swing.*;
import java.net.URL;
public class ShowDocument extends JApplet {
public void init() {
String urlString = getParameter("url");
if(urlString==null) {
urlString = JOptionPane.showInputDialog(this,
"URL to display?",
"http://www.physci.org/index.html");
}
JEditorPane output;
try {
URL url = new URL(urlString);
output = new JEditorPane(url);
getContentPane().add( new JScrollPane(output,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED ) );
} catch(Exception e) {
e.printStackTrace();
output = new JEditorPane();
output.setText( "Error: " + e.getMessage() );
getContentPane().add( output );
}
}
}
</sscce>
And this is the simple HTML..
[html]
<!DOCTYPE HTML>
<HTML>
<HEAD>
<title>Show Document</title>
</HEAD>
<BODY>
<h1>Show Document Applet</h1>
<APPLET
CODE="ShowDocument.class"
archive='showdoc.jar'
CODEBASE="."
WIDTH=800
HEIGHT=600></APPLET>
</BODY>
</HTML>
[/html]
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via http://www.javakb.com
I'm not allowed to use it in the applet < init> method.......
I get >>>>
/home/lando/PgmJava/Fadera.java:81: non-static method getDocumentBase()
cannot be referenced from a static context
URL url1 = new URL(Fadera.getDocumentBase(), "men1.jpg");
>
So don't (refer to it from a static context), instead..
URL url1 = new URL(getDocumentBase(), "men1.jpg");
.within the 'init()' of the Fadera applet, should work just fine.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via http://www.javakb.com
Thanks,this is fine...but I cannot find examples and I cannot
build the image....
> final BufferedImage[] images = new BufferedImage[6];
>
>
>
> try {
>
>
> URL url1 = new URL(getDocumentBase(), "men1.jpg");
>
> images[0] = getImage(url1);
Complain about BufferedImage ....but I've it !
What is the method ?
>
> /home/lando/PgmJava/Fadera.java:85: incompatible types
> found : java.awt.Image
> required: java.awt.image.BufferedImage
> images[0] = getImage(url1);
You need to explain this better so we understand what you problem is.
>> final BufferedImage[] images = new BufferedImage[6];
>>
>>
>> try {
>>
>> URL url1 = new URL(getDocumentBase(), "men1.jpg");
>>
>> images[0] = getImage(url1);
>
> Complain about BufferedImage ....but I've it !
> What is the method ?
Are you using a really old compiler? You should be using at least 1.4
version compiler, preferably a 6.
>>
>> /home/lando/PgmJava/Fadera.java:85: incompatible types
>> found : java.awt.Image
>> required: java.awt.image.BufferedImage
>> images[0] = getImage(url1);
A BufferedImage is an Image but an Image is not a BufferedImage.
If you are using a compiler before 1.4 then you need to use things like
MediaTracker and Applet.getImage(). If you have the new compiler forget
all of that old stuff and use the ImageIO class methods. They are much
easier to use.
Thanks and sorry for my bad English....
> javac -version
> javac 1.5.0_07
> java version "1.5.0_07"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
> Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)
...then should it work ?
Code is a lot more instructive than English*.
Can you post an SSCCE** of the code you are
currently having trouble with?
Also very helpful is an URL to the applet on the
internet, working or not.
* Thank you for taking the effort to write the
only language I understand.
** <http://www.physci.org/codes/sscce.html>
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200707/1
>>Otherwise you must include it as a resource in the jar.
>>See http://mindprod.com/jgloss/resource.html
>
>No. This is wrong. Resources in the code's
>archives can be accessed via getResource() -
>to get an URL - but if you can form *any*
>valid URL to the same server, an applet can
>reach 'above' its own codebase to fetch
>resources. Here is the proof.
The use of class file outside jars is only for single-class
experiments.
Yes you can subsist your whole life on a diet of Gerber baby food,
but that is not what is taught in nutrition school.
Understand that nearly everything I say is directed to the newbies
here. I make simplifying rules of thumb all the time, and one of them
is you MUST use jars for any multi class or Applet project.
It will save you endless grief.
My point was not about class files specifically,
but *resources* in general. Please read what I
said, again.
What I said was written thinking about *image*
files (as in the OP's post, but dealing with *HTML*
files, as the *resource*). I was quite specific about
*not* using class files.
Please pay attention Roedy, and if you do not understand
my point, feel free to ask, rather than post these pithy
messages about 'baby food'. You are quite the noob.
when it comes to applets (and web start, for that matter),
so please pay attention, and eat your mushy carrots,
rather than try educating *me* about things you obviously
do not understand.
>It will save you endless grief.
Yeah.. right.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200707/1
Thanks to see my post ,..but at this moment I am in a complete loop !
So as in loop is my web page !
I 've to reset and restart everything.
...then I cannot show you the complete documentation you need...
I can only say this code below give "access denied " also with files in
the same folder of .class file.
> public class Fadera extends JApplet {
>
>
> final BufferedImage[] images = new BufferedImage[4];
> volatile BufferedImage first,next;
> volatile AlphaComposite comp1 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
> volatile AlphaComposite comp2 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f);
>
>
>
> public void init() {
>
> try {
> for (int i=0; i<images.length; i++)
> images[i] = ImageIO.read(
>
> new File("men" + Integer.toString(i+1) + ".jpg"));
>
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
>
The code below (very the same !...) works with images in same folder
> public class Fadera extends JApplet {
>
>
> final BufferedImage[] images = new BufferedImage[4];
> volatile BufferedImage first,next;
> volatile AlphaComposite comp1 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
> volatile AlphaComposite comp2 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f);
>
>
>
> String s[] = { "pic_1h.jpg", "pic_2h.jpg", "pic_3h.jpg", "pic_4h.jpg"};
>
> for ( int i = 0; i < images.length; i++ ) {
> File f = new File("/home/lando/Desktop/fade/" + s[i]);
> try {
>
> // Read in a BufferedImage from a file.
> images[i] = ImageIO.read(f);
>
>
>
> } catch (IOException e) {
> System.err.println("Error reading file: " + f);
> System.exit(1);
> }
> }
>
And the code below that in compilation gives
> /home/lando/PgmJava/Fadera.java:85: incompatible types
> found : java.awt.Image
> required: java.awt.image.BufferedImage
> images[0] = getImage(url1);
> public class Fadera extends JApplet {
>
>
> final BufferedImage[] images = new BufferedImage[4];
> volatile BufferedImage first,next;
> volatile AlphaComposite comp1 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
> volatile AlphaComposite comp2 =
> AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f);
>
>
>
>
> try {
>
> URL url1 = new URL(getDocumentBase(), "men1.jpg");
>
> BufferedImage [0] images = getImage(url1);
>
>
>
>
> } catch (IOException ioe) {
> ioe.printStackTrace();
>
> }
My web interface to this forum might be deleting
the code you post, but - I'm sorry - I do not *see*
your code. The only code I see on this thread, is
that posted by Knute.
Please link to your web page that has the
applet. From that page, link to the *exact*
code being used for the applet (please link
directly to the Java source file).
(As an aside, I have not tried Knute's code, but
am confident he knows what needs to be done,
have you tried Knute's code?)
Knute's code works very fine as application ,this is why I'm trying
to do an applet version,...without results.
Locally the images are read , but "repaint" doesn't render
them.(certanly is a my applet error).
On the web page the images get access denied....
My web page >>>> http://digilander.libero.it/landodgl/Fadera.html
and applet source below >>>
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.font.*;
import javax.swing.*;
import javax.imageio.*;
import java.net.*;
public class Fadera extends JApplet {
final BufferedImage[] images = new BufferedImage[4];
volatile BufferedImage first,next;
volatile AlphaComposite comp1 =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f);
volatile AlphaComposite comp2 =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f);
private Thread timerThread;
private volatile boolean noStopRequested;
private boolean paused;
private final Object pauseLock = new Object();
private void printThreadName(String prefix) {
String name = Thread.currentThread().getName();
System.out.println(prefix + name);
}
public void init() {
String s[] = { "pic_1h.jpg", "pic_2h.jpg", "pic_3h.jpg",
"pic_4h.jpg"};
for ( int i = 0; i < images.length; i++ ) {
File f = new File(s[i]);
try {
// Read in a BufferedImage from a file.
images[i] = ImageIO.read(f);
} catch (IOException e) {
System.err.println("Error reading file: " + f);
System.exit(1);
}
}
setPreferredSize(new Dimension(
images[0].getWidth(),images[0].getHeight()));
System.out.println("comando startthread");
startThread() ;
}
private void startThread() {
paused = true;
noStopRequested = true;
// Use this inner class to hide the public run method
Runnable r = new Runnable() {
public void run() {
runWork();
}
};
timerThread = new Thread(r, "Timer");
timerThread.start();
printThreadName("startThread is ");
}
private void stopThread() {
noStopRequested = false;
timerThread.interrupt();
printThreadName("stopThread is ");
}
public void runWork() {
while (true) {
for (int i=0; i<images.length; i++) {
first = images[i];
if (i < images.length - 1)
next = images[i+1];
else
next = images[0];
for (int j=0; j<60; j++) {
comp1 = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER,1.0f / (j + 1));
comp2 = AlphaComposite.getInstance(
AlphaComposite.SRC_OVER,(j + 1) / 60.0f);
System.out.println("lando runwork repaint");
repaint();
try {
Thread.sleep(50);
} catch (InterruptedException ie) { }
}
try {
Thread.sleep(1000);
} catch (InterruptedException ie) { }
}
}
}
private void setPaused(boolean newPauseState) {
synchronized ( pauseLock ) {
if ( paused != newPauseState ) {
paused = newPauseState;
pauseLock.notifyAll();
}
}
}
private void waitWhilePaused() throws InterruptedException {
synchronized ( pauseLock ) {
while ( paused ) {
pauseLock.wait();
}
}
}
public void start() {
setPaused(false);
printThreadName("start is ");
}
public void stop() {
setPaused(true);
printThreadName("stop is ");
Aaaah.. I had not realised Knute posted an application version.
>My web page >>>> http://digilander.libero.it/landodgl/Fadera.html
Un-huhh.. Seeing the File objects still in the code, I
skipped the web page - it would not work.
Here is my variant of (your version of) Knute's code.
<http://www.physci.org/test/applet/slideshow/>
the altered code is linked from the page.
A couple of notes.
- I added status bar messages to tell the user when
images were loaded, but it is criminally slow here
(takes around 2 minutes to load those 4 smallish
images I used), so better feedback would be good.
- The code uses ImageIO, which I would probably do
for applications, but applets do have convenience methods
for loading images that date back to Java 1.1* - it might
be worth using applet methods for getting images in
this applet.
- The original code called System.exit(1) on error,
but an applet is prevented from doing that - that part
should also be changed - but I forgot to change it
(sue me).
* AlphaComposite was introduced in 1.2 (AFAIR), so that
would peg the minimum Java for this applet at Java 1.2.
HTH
Compliments ,it works both locally and on the web
My web page >>>> http://digilander.libero.it/landodgl/Fadera.html
Thank a lot.
Nice pics. I particularly like the blue fly - is it cropped?
There is something very odd going on with those images.
I pulled them directly - they all seem to be 318x238px,
yet my usual software for loading them says there is
an invalid file marker (for the first two - at least), and the
applet claims 340x340 - but crops them here.
Try resaving them using other software.
About the HTML. It works OK here in IE (but that
is no measure) but the HTML is wrong - and malformed -
I would recommend some *important* changes.
..
<APPLET code="Fadera.class"
PARAM images= "pic_1h.jpg , pic_2h.jpg , pic_3h.jpg , pic_4h.jpg ">
WIDTH=340
HEIGHT=340>
</APPLET>
..
Should be ..
<APPLET code="Fadera.class"
WIDTH="340"
HEIGHT="340">
<PARAM name="images" value= "pic_1h.jpg , pic_2h.jpg , pic_3h.jpg , pic_4h.
jpg " />
</APPLET>
.but I would recommend removing all spaces
from the param attribute, also..
<PARAM name="images" value= "pic_1h.jpg,pic_2h.jpg,pic_3h.jpg,pic_4h.jpg" />
>Thank a lot.
You're welcome, though I feel it is mostly Knute's
code got you there, with Roedy providing a lot of
encouragement along the way.
Hi ,
The emages size is 320 x 240 ,my setting 340 x 340 refers to preceding
images.
Now is right.
Setting (that should be right...) >>>
<PARAM name="images" value= "pic_1h.jpg , pic_2h.jpg , pic_3h.jpg ,
pic_4h.
jpg ">
I get >>>>>
> java.lang.NullPointerException
> at Fadera.init(Fadera.java:35)
> at sun.applet.AppletPanel.run(AppletPanel.java:378)
> at java.lang.Thread.run(Thread.java:595)
>
I had found the settings below empirically ! is the only way to work....
<PARAM images= "pic_1h.jpg , pic_2h.jpg , pic_3h.jpg , pic_4h.
jpg " >
Maybe something in the code ...not aligned....
The HTML on the site is the exact same rubbish I
first saw.
> Setting (that should be right...) >>>
> <PARAM name="images" value= "pic_1h.jpg , pic_2h.jpg , pic_3h.jpg ,
>pic_4h.
> jpg ">
The leading '<' will probably not work if the element
is left where it was. But I cannot tell, from that one
line, *where* in the applet element it is being put.
Why not put that *exact* HTML into the page and put it
on the net (and stop whining at me about how it does
not work!).
Maybe you should put up a Fadera1.html (note the
number) while we are testing.
> I get >>>>>
>> java.lang.NullPointerException
If my changes caused that behaviour, and you put
them up on your site, we could all help you debug it.
Sorry ,I had misplaced the fields ....now it's ok.
Thanks again .
>...I had misplaced the fields ....now it's ok.
Yay! Just revisited it. And yes, *now* the applet
is showing the correct size and not cropping the
images. The HTML looks good (though actual
validation is always the best way to check).
>Thanks again .
You're welcome. Glad you got the effect you
were after. :-)