Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Tester {
- public static void main(String[] args) {
- Frame frame = new Frame();
- frame.start();
- }
- }
- class Frame {
- private JFrame frame;
- private Paint oval;
- private int x,y;
- Frame(){
- x = y = 120;
- frame = new JFrame();
- oval = new Paint();
- }
- public void start() {
- frame.getContentPane().add(oval);
- frame.setSize(700, 700);
- frame.setVisible(true);
- for(int count = 0;count <400;count++) {
- x++;
- y++;
- oval.repaint();
- try {
- Thread.sleep(25);
- } catch (Exception ex) {
- }
- }
- }
- class Paint extends JPanel {
- public void paintComponent(Graphics g) {
- g.setColor(Color.WHITE);
- g.fillRect(0, 0, this.getWidth(), this.getHeight());
- g.setColor(Color.ORANGE);
- g.fillOval(x,y, 100, 100);
- }
- }
- }
- g.setColor(Color.WHITE);
- g.fillRect(0, 0, this.getWidth(), this.getHeight());
- public class Tester {
- public static void main(String[] args) {
- Frame frame = new Frame();
- frame.start();
- }
- }
- class Frame {
- private JFrame frame;
- private Paint oval;
- private int x,y;
- Frame() {
- x = y = 120;
- frame = new JFrame();
- oval = new Paint();
- }
- public void start() {
- frame.getContentPane().add(oval);
- frame.setSize(700, 700);
- frame.setVisible(true);
- for (int count = 0;count <400;count++) {
- x++;
- y++;
- **frame.repaint();**
- try {
- Thread.sleep(25);
- } catch (Exception ex) {
- }
- }
- }
- class Paint extends JPanel {
- public void paintComponent(Graphics g) {
- g.setColor(Color.ORANGE);
- g.fillOval(x,y, 100, 100);
- }
- }
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g); // <<<
- g.setColor(Color.ORANGE);
- g.fillOval(x,y, 100, 100);
- }
Add Comment
Please, Sign In to add comment