Ever need to make an image blink continuously to signal for some kind of incoming activity? Well....I'm going to share a simple sample on how to do that.
import java.awt.Graphics; |
The concept of this BlinkingLabel class is to pass in a secondary image along with another JLayeredPane object which is the main container for the original image. That is to say we are actually making use of the 2 images one of which shows the original state and the other is actually the lighted up state. Upon instantiating an object with this class, the secondary image will be toggled on and off with a variable of 400 milliseconds. You can tweak this setting if you wish it to be faster or slower.
Of course this is just one of the ways to make an image blink repeatedly. I'm sure there are other methods like overriding the paintComponent method or something.
If you've enjoyed this article, drop me a comment!
Create your own media player with Java Media Framework(JMF)
Posted by Fast Fire Fish in java, programming
For those who are working with Java, you might be interested with Java's capability of playing media files with its Java Media Framework(JMF). Today I'm going to share a simple guide to get this working.
Steps
1)Get the installation software from Sun's website here.
2)You might need to restart your machine as one of my friends had this problem and it was resolved after that.
3)Copy and paste the code from here
4)If you do not have a sample mpeg file, you might want to download it here. Save the file to some location in your harddisk and remember where u save it.
5)Compile and launch the code with assuming you already have the standard jdk package installed. Select the mpeg file from the location where it is stored and it should start the video playing.
That's it! I hope I made it simpler if you are looking for a crash course.
For a more detailed explanation of the codes, I believe the source has already explained in great detail.