swing - How to add Transitions (Fade, dissolve etc ) in Java GUI -
i trying make game semester project. want show transition when user clicks on options button of game menu or when user clicks on credits button. want show transition when 1 panel replaces another. possible? using java swing library.
you should use cardlayout swap views (jpanels) in gui. fade effect not simple thing do, can done little work. i've done here create special class called swappingimgpanel extends jpanel, , fades 1 image using swing timer. specifically, program this:
- the program adds swapping components cardlayout using jpanel.
- it adds single swappingimgpanel, jpanel created draw 2 images, 1 of component fading out, , 1 of component fading in.
- when swap components, create images of 2 components, 1 visible, , 1 next visible.
- you send images swappingimgpanel instance
- you call
swap()
on swappingimgpanel instance. - the swappingimgpanel draw both images uses swing timer change graphic object's composite value. causes image partially visible.
- when swappingimgpanel's timer done,
done()
method called sets swappingimgpanel's state state.done. - the main gui listening swappingimgpanel's state value, , when achieves state.done, main gui shows actual next component (and not image of it).
Comments
Post a Comment