The String I'm painting will move...but only if I minimize and maximize the window. It's not repainting automatically. How come?
import java.lang.Thread; import java.awt.*; import java.util.*; import java.io.*; import javax.swing.*; public class Melissa extends Thread { Background b; private class Background extends JFrame { private String text; public Background(String name) { super(name); setVisible(true); setString(name); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void paint(Graphics g) { super.paint(g); Random r = new Random(); Random r2 = new Random(); int x = r.nextInt(300); int y = r.nextInt(300); int red = r2.nextInt(256); int green = r2.nextInt(256); int blue = r2.nextInt(256); g.setColor(new Color(red,green,blue)); g.drawString(getString(), x, y); } public void setString(String text) { this.text = text; } public String getString() { return text; } } public Melissa(String name) { super(name); b = new Background(name); System.out.println(this); start(); } public void run() { //Display info about this particular thread System.out.println(Thread.currentThread().getName()); try { Thread.sleep(9000); b.repaint(); } catch(InterruptedException ieRef) { System.out.println("Error!"); } } public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println("Enter text"); String text3 = console.nextLine(); Melissa m2 = new Melissa(text3); m2.run(); } }