I am trying to move an label/icon & button from one place to another place using setLocation
method but for some reason the objects are moving but not in motion. So if any one knows how to do this thing please tell me.
How to create a label or any component that moves from one place to another place in JFrame?
Below I have shown the code:
jl = JLabel
jf = JFrame
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jbtn)
{
for(int i=0;i<=30;i++)
{
jl.setLocation(100,100+i);
jl.repaint();
jf.repaint();
try
{
Thread.sleep(50);
}
catch(Exception ae)
{
ae.printStackTrace();
}
}
}
}