
import javax.swing.*;
import java.awt.*;

public class SimpleAnimation {

	int x = 0;
	int y = 0;
	int r = 20;
	
	int panel_w = 400;
	int panel_h = 400;
	int win_w = panel_w + 10; // got these numbers after frame.setVisible() using insets code below
	int win_h = panel_h + 30;
	
	public static void main(String[] args) 
	{
		SimpleAnimation gui = new SimpleAnimation();
		gui.go();
		System.out.println("done");
	}
	
	public void go() 
	{
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		MyDrawPanel drawPanel = new MyDrawPanel();
		
		frame.getContentPane().add(drawPanel);
		frame.setSize(win_w, win_h);
		frame.setVisible(true);
		
		/*
		Insets ins = frame.getInsets();
		System.out.println("top = " + ins.top);
		System.out.println("bottom = " + ins.bottom);
		System.out.println("left = " + ins.left);
		System.out.println("right = " + ins.right);
		*/
		
		for (int i = 0; i < panel_w / 2; i++) {
			
			// draw
			
			drawPanel.repaint();
			
			// update
			
			x++;
			y++;
			
			// slow things down a bit
		
			try {
				Thread.sleep(20);		
			} catch (Exception ex) { }
	
		}
	}

	class MyDrawPanel extends JPanel {
		
		public void paintComponent(Graphics g)
		{
			g.setColor(Color.white);
			g.fillRect(0, 0, this.getWidth(), this.getHeight());
			
			g.setColor(Color.black);
			g.drawString("Hello", x-20, y);
			g.drawString("world", panel_w-x+20, panel_h-y);
		}
	}
}
