Es muy simple, sólo tienes que llamar al método repaint() cada vez que modifiques las coordenadas del punto para que se dibuje en donde apunten las coordenadas. Cada vez que se repita el proceso llamas a Sleep y así.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
public class AyudaForo extends JPanel{
private static int xinicial = 0, yinicial = 0;
private static int xfinal = 0, yfinal = 0;
private static boolean terminar = false;
private static final byte tamanoPelota=30;
public static AyudaForo animacion = new AyudaForo(0,0,200,200);
public AyudaForo(int xinicial, int yinicial, int xfinal, int yfinal) {
this.xinicial = xinicial;
this.yinicial = yinicial;
this.xfinal = xfinal;
this.yfinal = yfinal;
}
public void paint(Graphics g) {
super.paint(g);
pintarPunto(g, xinicial, yinicial);
}
public void pintarPunto(Graphics g2, int x, int y) {
g2.setColor(Color.blue);
g2.fillOval(x, y, tamanoPelota, tamanoPelota);
}
public static void run() {
while (!terminar) {
xinicial++;
yinicial++;
if (xinicial == xfinal && yinicial == yfinal) {
break;
}
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
animacion.repaint();
}
}
public static void main(String[] args) throws InterruptedException {
JFrame ventana = new JFrame("animacion corriendo");
ventana.setBounds(0, 0, 500, 500);
ventana.add(animacion);
ventana.setVisible(true);
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
run();
System.out.println("Hilo terminado");
}
}
public static void run() {
//Aquí utiliza tu algoritmo para ir modificando las variables que te había mencionado
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
animacion.repaint();
}
// If targetLocation does not exist, it will be created.
public void copyDirectory(File sourceLocation , File targetLocation)
throws IOException {
if (sourceLocation.isDirectory()) {
if (!targetLocation.exists()) {
targetLocation.mkdir();
}
String[] children = sourceLocation.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
}
} else {
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
#include <fstream>
#include <string>
int main()
{
std::ifstream file("NomFichero.txt");
std::string linea;
while (std::getline(file, linea))
{
// Ahora puedes hacer lo que sea con "linea".
}
}