import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;
import javax.swing.Timer;
public class PaintDemo1 extends JFrame implements ActionListener
{
private FountainAnimator animator;
private Timer timer;
private JScrollPane jsp;
private int xLoc, yLoc;
public PaintDemo1()
{
setVisible(true);
animator = new FountainAnimator();
animator.setVisible(true);
timer = new Timer(1000, animator);
timer.setDelay(1000);
timer.start();
Graphics graphics = getGraphics();
jsp = new JScrollPane(animator, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS , JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Dimension d = new Dimension(9000,9000);
animator.setPreferredSize(d);
animator.revalidate();
animator.setSize(d);
animator.setAutoscrolls(true);
setContentPane(jsp);
}
public static void main(String[] args)
{
PaintDemo1 pd1 = new PaintDemo1();
pd1.setVisible(true);
}
public class FountainAnimator extends JPanel implements ActionListener
{
public FountainAnimator()
{
super(new BorderLayout());
setBackground(Color.GREEN);
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(new Color(88,88,88));
Polygon poly = new Polygon();
poly.addPoint(200, 200);
poly.addPoint(400, 200);
poly.addPoint(400, 300);
poly.addPoint(100, 300);
g.fillPolygon(poly);
g.setColor(Color.BLACK);
g.drawPolygon(poly);
Polygon poly2 = new Polygon();
poly2.addPoint(200, 200);
poly2.addPoint(250, 100);
poly2.addPoint(450, 110);
poly2.addPoint(400, 200);
g.setColor(Color.BLUE);
g.fillPolygon(poly2);
g.setColor(Color.BLACK);
g.drawLine(200, 200, 250, 100);
g.drawLine(250, 100, 450, 110);
g.drawLine(450, 110, 400, 200);
Polygon poly3 = new Polygon();
poly3.addPoint(100, 300);
poly3.addPoint(100, 200);
poly3.addPoint(250, 100);
poly3.addPoint(200, 200);
g.setColor(new Color (88, 88,88));
g.fillPolygon(poly3);
g.setColor(Color.BLACK);
g.drawLine(100, 300, 100, 200);
g.drawLine(100, 200, 250, 100);
Polygon poly4 = new Polygon();
g.setColor(new Color(88,88,88));
poly4.addPoint(450, 110);
poly4.addPoint(510, 270);
poly4.addPoint(400,300);
poly4.addPoint(400, 200);
g.fillPolygon(poly4);
g.setColor(Color.BLACK);
g.drawPolygon(poly4);
drawSidewalk(g);
drawFountain(g);
animateFountain(g);
drawLake(g);
g.fillOval(8000,300, 100,100);
}
public void drawFountain(Graphics g)
{
g.setColor(new Color(95,95,95));
g.drawOval(300, 120, 65, 65);
g.setColor(Color.BLACK);
g.drawOval(320, 140, 25, 25);
g.setColor(new Color(95,95,95));
g.fillOval(320, 140, 25, 25);
g.setColor(new Color(50,50,50));
Polygon poly = new Polygon();
poly.addPoint(325, 153);
poly.addPoint(325, 125);
poly.addPoint(330, 115);
poly.addPoint(340, 125);
poly.addPoint(340, 153);
g.fillPolygon(poly);
g.setColor(Color.BLACK);
g.drawPolygon(poly);
}
public void drawSidewalk(Graphics g)
{
// g.setColor(new Color(183,183,183));
// g.fill3DRect(100,50,420,300,true);
}
public void animateFountain(Graphics g)
{
int newRed = Color.BLUE.getRed() + 10;
int newGreen = Color.BLUE.getGreen() + 10;
int newBlue = Color.BLUE.getBlue();
g.setColor(new Color(newRed, newGreen, newBlue));
g.setColor(new Color(newRed, newGreen, newBlue));
g.fillOval(xLoc,yLoc, 10, 10);
g.setColor(Color.BLACK);
g.drawOval(xLoc,yLoc,10,10);
// repaint();
}
public void drawLake(Graphics g)
{
g.setColor(new Color(9,34, 136));
g.fillOval(500,500, 300, 200);
g.setColor(Color.BLACK);
g.drawOval(500,500,300,200);
}
public void actionPerformed(ActionEvent e)
{
for (int x = 325; x < 352; x++)
{
for (int y = 125; y < 155; y++)
{
xLoc = x;
yLoc = y;
repaint();
}
}
// animator.repaint();
System.out.println("Executed now");
timer.restart();
}
}
public void actionPerformed(ActionEvent e)
{
// animator.repaint();
// Do I even need this listener?
}
public abstract class MyGraphics extends Graphics
{
}
}