Sunday, April 15, 2007

Make The Swing Fly

Recently this thing struck my head that i can make my JFrame(Swing components)"Fly In" when the application is started and fly out when the quit button is hit and ended up with the following code.Use it and add a better entrance and exit effect to your applications!!!!!
I'll be adding it to NYouTube.

Enjoy!
:-)


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {

JFrame f;
JButton jb;
Dimension t;
public Test(){
f=new JFrame("Flying window");
jb=new JButton("Quit");
//Get the screen size
t=Toolkit.getDefaultToolkit().getScreenSize();
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//The Fly Out effect
for(int i=t.width/2;i>=0;i-=2)
{
f.setLocation(i,i);
f.repaint();

}
System.exit(0);
}
});

f.getContentPane().add(jb);
f.pack();
f.setSize(100,100);
f.setDefaultCloseOperation(3);
f.setVisible(true);
//The Fly In effect
for(int i=0;i<=t.width/2;i+=2)
{
f.setLocation(i,i);
f.repaint();

}

}
public static void main(String[] s)
{
new Test();
}

}

6 comments:

Klaus said...

Hello,
this is a cool effect, but I'm in doubt, if it will show the same behaviour when I have a really complicated JFrame containing lots of components that have to be redrawn all the time your frame will "fly in or out"...
--Klaus

Ashish Lijhara said...

klaus i have simply changed setLocation() attributes dynamically till the position i want the frame to stop so it will work with the JFrame no matter how complex it may be

Klaus said...

Sounds good, I will give it a try...
--Klaus

Ashish Lijhara said...

i am sure u'll like the effect

Anonymous said...

The Tax Return Crack-Up<2>
I was not shocked because this was old news -- practically ancient, in fact. In R. Microsoft Office Emmett Tyrrell, Office 2010 Jr.'s most recent book The Clinton Microsoft Office 2010 Crack-
Up, page fiv Office 2007 e, paragraph two, we learn that in Bill Clinton's "first four years out of the White H Microsoft Office 2007 ouse, he ea Office 2010 key rned over Office 2010 download $43 million Office 2010 Professional after
expenses... Microsoft outlook "
The next Outlook 2010 page directs Windows 7 us to Appendix Microsoft outlook 2010 I, a list of the conniving couple's fees for speeches and book royalties and other income. The first

Ashish Lijhara said...

Meh! Seems no parallelism whatsoever!