import mypackage.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.MouseInputListener;
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.Color;
import java.awt.Shape;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.awt.geom.Arc2D;
import java.awt.geom.Point2D;
import javax.swing.JApplet;
import javax.swing.*;
import java.awt.Graphics2D;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JFrame;
public class ProgramProj extends JFrame implements ActionListener, MouseInputListener
{
JPanel pNorth;
JPanel row1;
JPanel row2;
JPanel pSouth;
JPanel pEast;
JPanel pWest;
JPanel pCenter;
JFrame frame;
CircleComponent mycounter;
Boolean c;
Shape[][] grid; // Grid array
int rw; // Grid circles width
int rh; // Grid circles height
int GapConstant; // Gap between each circle in the grid
int xpos; // x position of grid
int ypos; // y position of grid
int xcolpos; // Position of where column chosen
int ycolpos; // Position of where column chosen
int xposcounter; // Position of the moving counter
int cypos;
int leftxpos;
int rightxpos;
int counterxpos;
int[][] x;
/* if(xcolpos >= xpos -(GapConstant/2) && xcolpos <= xpos + (rw+(GapConstant/2)))
{
System.out.println("Column 1");
}
else
{
System.out.println("Not Column 1");
}
*/
public class MouseMovedListener implements MouseMotionListener
{
public void mouseMoved(MouseEvent e)
{
}
//http://hivemind.apache.org/hivemind1/hivemind/apidocs/src-html/org/apache/hivemind/HiveMind.html#line.158
public void mouseDragged(MouseEvent e) {}
}
public void mouseClicked(MouseEvent e)
{
xcolpos = e.getX(); //get the x coordinate after mouse is clicked on the applet
calculatecolumn(); //call the calculate column method
}
public void mouseMoved(MouseEvent e) {
xposcounter = e.getX();
for(int i = 0; i <= grid.length; i++)
{
//Center the grid
leftxpos = pCenter.getWidth()/2 - ((GapConstant*(grid.length)+(grid.length*rw))/2) + rw*i + GapConstant*i;
rightxpos = leftxpos +rw;
//Show the counter appearing above the columns the mouse is over
if(xposcounter >= leftxpos && xposcounter <= rightxpos)
{
counterxpos = xposcounter;
mycounter = new CircleComponent(counterxpos, ypos, rw, rh);
//mycounter.translate(xposcounter, ypos);
repaint();
System.out.println(counterxpos);
c = true;
//graf.drawOval(leftxpos, ypos, 10, 10);
//pCenter.add(circle);
//mycounter.setVisible(true);
}
}
}
public static void main(String args[])
{
new ProgramProj();
}
public void mouseExited(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}
public ProgramProj()
{
setSize(1000,700);
c = new Boolean(false);
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setLayout (new BorderLayout());
pNorth = new JPanel();
add(pNorth, BorderLayout.NORTH);
row1 = new JPanel();
row2 = new JPanel();
pSouth = new JPanel();
add(pSouth, BorderLayout.SOUTH);
pEast = new JPanel();
add(pEast, BorderLayout.EAST);
pWest = new JPanel();
add(pWest, BorderLayout.WEST);
pCenter = new JPanel();
add(pCenter, BorderLayout.CENTER);
pNorth.setLayout (new BorderLayout());
pNorth.setBackground(Color.white);
row1.setBackground(Color.white);
row2.setBackground(Color.white);
pSouth.setLayout (new BorderLayout());
pSouth.setBackground(Color.white);
pEast.setLayout (new BorderLayout());
pEast.setBackground(Color.white);
pWest.setLayout (new BorderLayout());
pWest.setBackground(Color.white);
pCenter.setLayout (new BorderLayout());
pCenter.setBackground(Color.white);
JLabel one = new JLabel("Titles");
add(pNorth, BorderLayout.NORTH);
pNorth.add(row1, BorderLayout.NORTH);
pNorth.add(row2, BorderLayout.SOUTH);
pNorth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
pEast.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
pSouth.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
pWest.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
pCenter.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
JLabel two = new JLabel("a");
pSouth.add(two);
JLabel three = new JLabel("a");
pEast.add(three);
JLabel four = new JLabel("a");
pWest.add(four);
JButton cmdCustomer = new JButton("Add Customer");
row2.add(cmdCustomer);
JButton cmdEmployee = new JButton("Add Employee");
row2.add(cmdEmployee);
JButton cmdFinance = new JButton("Finance");
row2.add(cmdFinance);
JButton cmdDiscounts = new JButton("Discounts");
row2.add(cmdDiscounts);
ImageIcon picture = new ImageIcon("mebw.jpg");
JLabel five = new JLabel(picture);
pCenter.add(five, BorderLayout.CENTER);
///GRID////
GapConstant = 10; //Gap between each circle in the grid
rw = 60; //Circles width in the grid
rh = 60; //Circles height in the grid
grid = new Shape[6][5];
x = new int[5][5];
for(int row = 0; row<5;row++)
{
for(int column =0; column<5;column++)
{
x[row][column] = 0;
}
}
x[1][3] =1;
showgrid();
setVisible(true);//SET APPLICATION FRAME VISIBLE
}
public void paint (Graphics graf)
{
super.paint(graf);
for(int i = 0; i <= grid.length; i++)
{
//Center the grid
xpos = pCenter.getWidth()/2 - ((GapConstant*(grid.length+6)+(grid.length*rw))/2) + rw*i + GapConstant*i;
for(int j = 0; j <= grid[0].length; j++)
{
ypos = pCenter.getHeight()/2 - ((GapConstant*(grid.length-10)+(grid.length*rh))/2) + rh*j + GapConstant*j;
//Draw array of ovals
graf.drawOval(xpos,ypos, rw, rh);
//Draw vertical lines from right to left
graf.drawLine(xpos+(rw+GapConstant/2),ypos-GapConstant/2,xpos+(rw+GapConstant/2),ypos+(rh+GapConstant/2));
//Draw vertical lines from left to right
graf.drawLine(xpos-(GapConstant/2),ypos-GapConstant/2,xpos-(GapConstant/2),ypos+(rh+GapConstant/2));
//Draw horizontal lines from top to bottom
graf.drawLine(xpos-(GapConstant/2),ypos-GapConstant/2,xpos+(rw+GapConstant/2),ypos-GapConstant/2);
//Draw horitonzal lines from bottom to top
graf.drawLine(xpos-(GapConstant/2),ypos+(rw+GapConstant/2),xpos+(rw+GapConstant/2),ypos+(rw+GapConstant/2));
}
}
}