I have this code, the idea is that through the Runnable interface, a thread is created that calls a "move" method, the method moves a JLabel object. The program compiles everything but does not move the JLabel object. I have tried to make the JLabel object static, the method, to make them public, but nothing. Could you help me:)
Thread Class
package pruebasgraficas;
import static java.lang.Thread.sleep;
public class Hilo implements Runnable
{
@Override
public void run()
{
do
{
try
{
sleep (1000);
}catch (InterruptedException e)
{
;
}
PruebasGraficas pu = new PruebasGraficas();
pu.mover();
}while(true);
}
}
TestingGraphic class
package pruebasgraficas;
import java.awt.Color;
import javax.swing.*;
public class PruebasGraficas extends JFrame{
private JLabel et1;
private static Hilo h1;
public PruebasGraficas()
{
super("mover");
setLayout(null);
et1 = new JLabel( );
et1.setSize(30,30);
et1.setLocation(10,10);
et1.setOpaque(true);
et1.setBackground(Color.BLACK);
add(et1);
h1 = new Hilo();
}
public static void main(String[] args)
{
PruebasGraficas o = new PruebasGraficas();
o.setSize(500,500);
o.setVisible(true);
h1.run();
}
public void mover()
{
et1.setLocation( et1.getX() + 5, et1.getY() );
}
}