enable transitions on java image change - java

I'm writing a small application which aims to display a catalogue on screen. The window is splitted in three main blocks:
On the left I have the articles' list, on the right a panel for image rendering and under this last component I have some labels for the information.
Now when I select an article I paint the image on the panel and fill the information's into the labels. When I have more than one image associated with the selected article I start a swing timer and I swap the images Evey 5 seconds...
How can I make the photo change more pretty introducing some fancy animations on image change? Do you know any library that could me help?
If you do that directly by code an example and a little explanation would be great.
Thanks in advance
Marco

You can do some basic animation pretty easily with basic Java2D features, but it will take some more effort to add something actually interesting.
You can check out my own library demo (source included) for the ImageTransitionPanel example - it allows to perform a transition between two different Swing components with some interesting animations:
Web Look and Feel demo
There is also a full source of the ImageTransitionPanel included in the demo and sources. That class basically creates all of the transition effects and performs the transition.

You can have endless fun with the getSubImage() method of BufferedImage, illustrated here, and AlphaComposite, illustrated here. See also the Java 2D API.

Related

Using multiple backgrounds in Android Application

Here is a scenario on which i done a lot of research on google but hopeless. the scenario is, i am going to develop a 2D game in which i want to use multiple backgrounds and i want to translate them as they are moving forward, it must look like one background is near and translating/moving fast and the other background is a bit far and translating/moving a little slow. the nearer background have almost full intensity and the farer background have a bit low intensity. you can say they have different transparency levels. the question is, how can i get this task done or is this possible to use multiple backgrounds.
any suggestion will be appreciated.
as an example, see the image of BADLAND game bellow.
I think as far as I got your question you want to put two or more images one over another. I mean if you are trying to overlap the multiple backgrounds and asking for it yes it can be done easily.
What you need to do is to use the FrameLayout. as
"FrameLayout represents a simple layout for the user interface of
Android applications. It is usually used for displaying single Views
at a specific area on the screen or overlapping its child views."
and then you can implements the animations on them and translate them You can find different types of translation over them.
Here is all about using the frame layout frameLayout1 framelayout2 and for animations and translation here are links. link , link2 , link3

Scroll a java 2d game tile map, while generating additional tiles

Finally decided to learn 2d (for now) java game programming. Am working on a game that has a central object that the user will guide with the directional keys. I have that working perfectly, cobbled together from examples and tutorials I've found.
I'm using this method of generating colored background tiles but I'd like to scroll (move) the background as the primary object the user is moving reaches the window edges. I'm fairly sure I can make that work, I have the basics in place, but I can't find a good tutorial or actual demonstration of a way to continue to generate additional tiles to fill in the space the user is moving too.
At this point, this is purely background and I have no need to save the exact tiles generated - but eventually I would like this ability. I'm sure I'll have to find a way to divide the areas into "chunks" like minecraft does.
But for now - how can I continually fill in the area with the same pattern? Or is there a better way to create the tiles that's better for this?
Instead of a solid color you can use a TexturePaint, as shown here. Let your model contain a reference to the desired texture for each grid cell. Let your view use a flyweight pattern for rendering, as illustrated here.

Arranging images according to background in Java

I'm trying to develop a Java program that does the following:
uses a background picture of a network diagram of clients
positions an image of a bandwidth graph to respective client
refreshes the image of graph every 5 seconds which it fetches from another program that constantly produces snapshots of bandwidth
Now, I can set the background picture and I'm pretty confident that I will be able to refresh the images by using a timer. What I am trying to plan out is how I am going to position these images to the respective clients which is displayed in the background picture. I did some research and it appears that I have several options but I want to make sure I am choosing the right one before I run into problems further down the line.
It seems to me that using a GridBagLayout would be the choice for me, however I would like a second opinion for a more experienced population. If using a GridBagLayout is the correct choice, could you recommend any good tutorials that would help me understand this Layout Manager? Please keep in mind that I have limited experience with Java, especially with GUI oriented Java.
EDIT: If I am not explaining the concept well enough please let me know.
check this out-
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
GridLayout is likely to meet your needs and it is easy to use - the assumption I make is that image of bandwidth graph is the same/fixed ...
Look for an example here
http://www.roseindia.net/tutorialsearch/?t=java+gridlayout+color
Try Google the keyword "GridLayout" - there are plenty of hits ...
If you want to do advanced layouts, you should take a look at MigLayout.
It's an extremely flexible layout manager that can pretty much act as a replacement for any/all of the existing Swing layout managers. It's worth using if you want to do difficult / complex layouts.
It feels more like a HTML table layout tool, enabling multi-column spans etc. and arbitrary scaling rules.
The "Quick Start Guide" is very good with lots of examples - I'd suggest taking a look at that if you want to evaluate MigLayout for your project.
If the 'bandwidth graph' image(s) is on top of the BG image, look to OverlayLayout
A layout manager to arrange components over the top of each other. ..
OTOH I would not use a layout strategy for this, instead..
Create a BufferedImage the size of the BG.
Paint the BG to the image.
Display the image in a label.
When it comes time to paint the graphs, get a Graphics instance for the image in the label, and paint them to that. If the graphs are always the same size and shape and do not have transparency, you can simply paint them. Otherwise, draw the BG first.

Simple execution sequence for real time systems drawn in Java

I need to draw some execution sequences for some real time systems scheduled using rate monotonic algorithm. The drawing has to be done using Java and it has to be very basic.
Do you a very simple way to do this drawing? Simpler than Graphics2D?
Thanks a lot!
The diagram I want to be as simple or even simpler as this one:
I would suggest you to try with Processing, which is able to do such things with Java in zero time.. home page here.
You can easily embed a Processing frame inside your app, but remember that they are based on AWT so they are heavy weight and don't like being overlayed (for example in a JInternalFrame)
By the way what you seem to want to draw is a Gantt chart right?
You can try with JFreeChart too (see demo here), it's quite customizable and works fine.. homepage here

scroll bar problems in java Layered Panes

I've been trying to build this small java app. I find it very difficult to design UI in java, tasks that seem very simple become complicated and all these strange misbehaviors occur. In my app I've created a JLayeredPane which contains two layers. One on top on the other, They both contain scrollbars.
Here's an explanation of the two layers:
Layer 1:
A very big image inside something similar to a scrollpane. The image is scrollable.
Layer 2:
A graphics2d object, this object draws an image. Once the image reaches a certain length, the layer gets a scrollpane that advances with the drawing with time.
I'd like to connect both layers. I want layer two to update the scrollbar on layer 1. Meaning that once it reaches a certain length, both scrollbars will advance together. When I try doing that, the two scroll bars really do advance, but ( ! ) this strange flickering occurs. I don't understand what is the reason for the flickering. Is there any other way to implement this in a simple manner? I must have the second layer on top of the first one (drawing on top of image)
since I cannot open a special post for thanking the wonderful people of this forum, I'll do it here. Thank you, you are great help. I hope this problem is solvable as well.
It sounds like you're repainting the entire component in some costly way each time - you could try to paint to a BufferedImage to save the image rather than re-generate it each time. Or you could try to mess around with how repaints are handled. I'd suggest this article and this page on Sun's website - both discuss performant painting practices.
Without seeing your code it's quite hard to guess where is the problem. Probably you're getting more paint() events than you really need.
Also you can try JXLayer (http://weblogs.java.net/blog/alexfromsun/archive/2008/06/the_new_jxlayer.html) to show your graphics2d layer.

Categories