Commit e67a92d3 authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch14] Pool Puzzle

parent fe39ef48
Loading
Loading
Loading
Loading
+42 −0
Changes for src/main/java/ch14/Animate.java: 42 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch14;

import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

public class Animate {
  int x = 1;
  int y = 1;

  public static void main(String[] args) {
    Animate gui = new Animate();
    gui.go();
  }

  public void go() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(
            JFrame.EXIT_ON_CLOSE);
    MyDrawP drawP = new MyDrawP();
    frame.getContentPane().add(drawP);
    frame.setSize(500, 270);
    frame.setVisible(true);
    for (int i = 0; i < 124; i++, y++, x++) {
      x++;
      drawP.repaint();
      try {
        TimeUnit.MILLISECONDS.sleep(50);
      } catch (Exception ex) {
      }
    }
  }

  class MyDrawP extends JPanel {
    public void paintComponent(Graphics g) {
      g.setColor(Color.white);
      g.fillRect(0, 0, 500, 250);
      g.setColor(Color.blue);
      g.fillRect(x, y, 500 - x * 2, 250 - y * 2);
    }
  }
}
 No newline at end of file