import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;
import javax.swing.Timer;
import java.awt.MouseInfo;
public class PaintDemo1 extends JFrame implements ActionListener
{
static final int HOUR = 0;
static final int TWELVE = 12;
static final int TWENTY_FOUR = 24;
static final int THIRTY_SIX = 36;
static final int FORTY_EIGHT = 48;
private FountainAnimator animator;
private Timer timer;
private JScrollPane jsp;
private int xLoc;
private int xLoc2, xLoc3, xLoc4;
private int yLoc,yLoc2,yLoc3,yLoc4;
private int timesCalledCounter;
private String time;
private int hour, minute, second;
private Timer clockTimer;
private ClockListener cl;
// private int a;
private double xLocation;
private double yLocation;
private AnalogClockListener acli;
private class AnalogClockListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
public class ShowMouseLocation extends JFrame implements ActionListener
{
private JLabel positions;
private String str;
public ShowMouseLocation()
{
positions = new JLabel();
add(positions);
}
public void actionPerformed(ActionEvent e)
{
xLocation = MouseInfo.getPointerInfo().getLocation().x;
yLocation = MouseInfo.getPointerInfo().getLocation().y;
str = "<br>"+xLocation + "</br>" + "<br>" + yLocation + "</br>";
System.out.println(str);
repaint();
}
public void paint(Graphics g)
{
super.paint(g);
positions.setText(str);
}
}
private class ClockListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Calendar cal = Calendar.getInstance();
int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
minute = cal.get(Calendar.MINUTE);
second = cal.get(Calendar.SECOND);
if (hourOfDay < 12)
{ // beginning of if
if (minute < 10)
{ // beginning of if
if (second < 10)
{ // beginning of if
hour = hourOfDay;
time = hour + ":0" + minute + ":0" + second + " A.M.";
} // end if
else
{ // begin else
hour = hourOfDay;
time = hour + ":0" + minute + ":" + second + " A.M.";
} // end else
} // end if
else
{ // begin else
if (second < 10)
{ // begin if
hour = hourOfDay;
time = hour + ":" + minute + ":0" + second + " A.M.";
} // end if
else
{ // begin else
hour = hourOfDay;
time = hour + ":" + minute + ":" + second + " A.M.";
} // end else
} // end else
} // end if
else if (hourOfDay == 12)
{ // begin else if
if (minute < 10)
{ // beginning of if
if (second < 10)
{ // beginning of if
hour = hourOfDay;
time = hour + ":0" + minute + ":0" + second + " P.M.";
} // end if
else
{ // begin else
hour = hourOfDay;
time = hour + ":0" + minute + ":" + second + " P.M.";
} // end else
} // end if
else
{ // begin else
if (second < 10)
{ // begin if
hour = hourOfDay;
time = hour + ":" + minute + ":0" + second + " P.M.";
} // end if
else
{ // begin else
hour = hourOfDay;
time = hour + ":" + minute + ":" + second + " P.M.";
} // end else
} // end else
} // end else if
else
{ // begin else
if (minute < 10)
{ // beginning of if
if (second < 10)
{ // beginning of if
hour = hourOfDay - 12;
time = hour + ":0" + minute + ":0" + second + " P.M.";
} // end if
else
{ // begin else
hour = hourOfDay - 12;
time = hour + ":0" + minute + ":" + second + " P.M.";
} // end else
} // end if
else
{ // begin else
if (second < 10)
{ // begin if
hour = hourOfDay - 12;
time = hour + ":" + minute + ":0" + second + " P.M.";
} // end if
else
{ // begin else
hour = hourOfDay - 12;
time = hour + ":" + minute + ":" + second + " P.M.";
} // end else
} // end else
} // end else
animator.repaint();
} // end method
} // end class
public PaintDemo1()
{
timesCalledCounter = 0;
setVisible(true);
animator = new FountainAnimator();
animator.setVisible(true);
timer = new Timer(0, animator);
timer.setDelay(1000);
timer.start();
cl = new ClockListener();
clockTimer = new Timer(0,cl);
clockTimer.setDelay(1000);
clockTimer.start();
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, MouseListener
{
private ShowMouseLocation sml;
private Timer aTimer;
public FountainAnimator()
{
super(new BorderLayout());
setBackground(Color.GREEN);
sml = new ShowMouseLocation();
sml.setVisible(true);
aTimer = new Timer(0,sml);
aTimer.setDelay(100);
System.out.println(xLocation);
System.out.println(yLocation);
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mousePressed(MouseEvent e){
xLocation = e.getXOnScreen();
yLocation = e.getYOnScreen();
System.out.println(xLocation);
sml.repaint();
}
private int getTimeInterval()
{
if (minute == HOUR)
return HOUR;
else if (minute == TWELVE)
return TWELVE;
else if (minute == TWENTY_FOUR)
return TWENTY_FOUR;
else if (minute == THIRTY_SIX)
return THIRTY_SIX;
else
return FORTY_EIGHT;
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
drawSidewalk(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);
drawFountain(g);
animateFountain(g);
drawLake(g);
drawDigitalClock(g);
drawRegularClock(g);
}
public void drawParkShelter(Graphics g)
{
}
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);
g.setColor(Color.BLACK);
g.draw3DRect(100,50,420,300, true);
}
public void drawRegularClock(Graphics g)
{
g.setColor(Color.BLACK);
g.drawOval(3000,3000, 150,150);
g.fillOval(2990,2990,170,170);
g.setColor(Color.WHITE);
g.fillOval(3000,3000,150,150);
g.setColor(Color.BLACK);
g.setFont(new Font("Arial Bold", Font.BOLD, 17));
g.drawString("12", 3065, 3015);
g.setColor(Color.DARK_GRAY);
g.drawLine(3072, 3020, 3072, 3005);
g.setColor(Color.BLACK);
g.drawString("6", 3071, 3150);
g.setColor(Color.DARK_GRAY);
g.drawLine(3073,3135, 3073, 3150);
}
public void drawDigitalClock(Graphics g)
{
Polygon poly = new Polygon();
poly.addPoint(1000,2485);
poly.addPoint(982, 2525);
poly.addPoint(1189,2525);
poly.addPoint(1172, 2485);
g.setColor(Color.BLACK);
g.fillPolygon(poly);
g.setColor(Color.LIGHT_GRAY);
g.drawPolygon(poly);
g.setColor(Color.YELLOW);
g.setFont(new Font("Arial Bold Italic", Font.BOLD + Font.ITALIC, 27));
g.drawString(time, 1003,2510);
}
public void animateFountain(Graphics g)
{
g.setColor(new Color(0,159,206));
g.fillOval(xLoc,yLoc, 10, 10);
g.fillOval(xLoc2,yLoc2,10,10);
g.fillOval(xLoc3,yLoc3, 10,10);
g.fillOval(xLoc4, yLoc4, 10,10);
g.setColor(Color.BLACK);
g.drawOval(xLoc, yLoc, 10,10);
g.drawOval(xLoc2, yLoc2, 10,10);
g.drawOval(xLoc3, yLoc3, 10,10);
g.drawOval(xLoc4, yLoc4, 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)
{
if (timesCalledCounter ==0)
{
xLoc = 325;
yLoc = 125;
timesCalledCounter++;
}
else if (timesCalledCounter ==1)
{
xLoc = 350;
yLoc = 138;
timesCalledCounter++;
}
else if (timesCalledCounter ==2)
{
xLoc =373;
yLoc = 150;
timesCalledCounter++;
}
else
{
xLoc = 385;
yLoc = 170;
timesCalledCounter = 0;
}
animator.repaint();
}
}
public void actionPerformed(ActionEvent e)
{
// animator.repaint();
// Do I even need this listener?
}
}