I want the cyan rectangle to move but it don't.
package circlegame.main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class game extends JFrame {
Rectangle r1 = new Rectangle(30,50,30,40);
Rectangle r2 = new Rectangle(300,150,30,40);
move1 m1 = new move1();
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
game frame = new game();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//thread
public class move1 extends Thread
{
public void run(){
//infinate loop
while(true)
{
try
{
repaint();
Thread.sleep(100);
}
catch(Exception e)
{
break;
}
}
}
}
public void paint(Graphics frame){
super.paint(frame);
frame.setColor(Color.CYAN);
frame.fill3DRect(r1.x, r1.y, r1.width, r1.height,true);
frame.setColor(Color.BLUE);
frame.fill3DRect(r2.x, r2.y, r2.width, r2.height,true);
}
public void move(){
try
{
r1.x +=(int)r1.x;
r1.setLocation(r1.x, r1.y);
}
catch(Exception e)
{
System.out.print("Error");
}
}
/**
* Create the frame.
*/
public game() {
super("Circlegame");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 400, 350);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 255));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
m1.start();
}
}
why doesn't it work?