/*
=========================================================
				APP5.JAVA

  Shift Register With Feed-Back
=========================================================
*/
import java.applet.*;
import java.awt.*;

//for commentaries see App1.java or App2.java
public class app5 extends Applet
{
	box5 flip1=new box5(this);
	//here cursor=new here(this);
		
	private Label lclock= new Label("CLK 5V");
	Label lQ3=new Label("1");
	Label lQ2=new Label("1");
	Label lQ1=new Label("0");
	Label lQ0=new Label("1");
	Label lsQ3=new Label("Q3");
	Label lsQ2=new Label("Q2");
	Label lsQ1=new Label("Q1");
	Label lsQ0=new Label("Q0");
	Label text=new Label("");
	
	
	boolean clock=false;
	int dx, dy;
	
	
	public app5()
	{
	}

	public String getAppletInfo()
	{
		return "Name: app5\r\n" +
		       "Author: Ana Cristina Fernandez\r\n" +
		       "Created with Microsoft Visual J++ Version 1.1";
	}
	public void init()
	{
    	add(lclock);
		add(lQ3);
		add(lQ2);
		add(lQ1);
		add(lQ0);
		add(lsQ3);
		add(lsQ2);
		add(lsQ1);
		add(lsQ0);
		add(text);
	}

	public void paint(Graphics g)
	{
		Color cl=g.getColor();
		g.setColor(Color.blue);
		g.drawString("Shift Register With Feed-Back", 20,20);
		g.setColor(cl);
		//These are the only two values we need to define
		dx=120;
		dy=120;
		
		flip1.coordenades(dx,dy);
		flip1.paint(g);
		flip1.coordenades(dx+120,dy);
		flip1.paint(g);
		flip1.coordenades(dx+240,dy);
		flip1.paint(g);
		flip1.coordenades(dx+360,dy);
		flip1.paint(g);
		
		g.drawLine(dx-40,dy+150-50,dx+390,dy+150-50);

		
		//clock
		g.setColor(Color.red);
		g.drawLine(dx-20,dy+150-50,dx-40,dy+150-50);
		g.drawLine(dx-40,dy+150-50,dx-40,dy+140-50);
		g.drawLine(dx-50,dy+140-50,dx-50,dy+150-50);
		g.drawLine(dx-50,dy+150-50,dx-60,dy+150-50);

		//arrow to help the student click in the right place in the applet.
		//This is an example that will be placed in all the applets in the future.
		g.drawLine(dx-45, dy+150-30, dx-45,dy+150-40);
		g.drawLine(dx-45-30, dy+150, dx-45,dy+150-30);
		g.drawLine(dx-45-2, dy+150-40+2, dx-45,dy+150-40);
		g.drawLine(dx-45+2, dy+150-40+2, dx-45,dy+150-40);
		g.drawString("click here", dx-45-30-20, dy+150+10);


		if (clock) {g.drawLine(dx-37,dy+140-50,dx-52, dy+140-50);}
		else {g.drawLine(dx-37,dy+136-50,dx-52, dy+136-50);}

		//cursor.paint(g);

		lclock.move(dx-120 , dy+90);
		lQ3.move(dx+75 , dy-55);
		lQ2.move(dx+75+120 , dy-55);
		lQ1.move(dx+75+240 , dy-55);
		lQ0.move(dx+75+360 , dy-55);
		lsQ3.move(dx+72 , dy-75);
		lsQ2.move(dx+72+120 , dy-75);
		lsQ1.move(dx+72+240 , dy-75);
		lsQ0.move(dx+72+360 , dy-75);
		text.move(dx+200,dy+250);

		g.setColor(cl);
		g.drawLine(dx-30,dy+15,dx,dy+15);
		g.drawLine(dx-30,dy+15,dx-30,dy-80);
		g.drawLine(dx-30,dy-80,dx-30+(4*120)+50,dy-80);
		g.drawLine(dx-30+(4*120)+50,dy-80,dx-30+(4*120)+50,dy+15);
		g.drawLine(dx-30+(4*120)+50,dy+15,dx-30+(4*120),dy+15);

		g.drawLine(dx-30,dy+65,dx,dy+65);
		g.drawLine(dx-30,dy+65,dx-30,dy+155);
		g.drawLine(dx-30,dy+155,dx-30+(4*120)+50,dy+155);
		g.drawLine(dx-30+(4*120)+50,dy+155,dx-30+(4*120)+50,dy+65);
		g.drawLine(dx-30+(4*120)+50,dy+65,dx+420,dy+65);

		g.drawLine(dx+60,dy+15,dx+120,dy+15);
		g.drawLine(dx+60,dy+15+50,dx+120,dy+15+50);
		g.drawLine(dx+60+120,dy+15,dx+120+120,dy+15);
		g.drawLine(dx+60+120,dy+15+50,dx+120+120,dy+15+50);
		g.drawLine(dx+60+240,dy+15,dx+120+240,dy+15);
		g.drawLine(dx+60+240,dy+15+50,dx+120+240,dy+15+50);
		g.drawLine(dx+60+360,dy+15,dx+90+360,dy+15);

		//arrows
		g.drawLine(dx+240+2,dy+155-2,dx+240,dy+155);
		g.drawLine(dx+240+2,dy+155+2,dx+240,dy+155);
		g.drawLine(dx+240+2,dy-80-2,dx+240,dy-80);
		g.drawLine(dx+240+2,dy-80+2,dx+240,dy-80);

		
		

	}

	
	/*public boolean mouseMove(Event evt, int x, int y)
	{
		//record the mouse location
		cursor.m_dimCursorLoc=new Dimension(x,y);
		repaint();
		return true;
	}

	public boolean mouseDrag(Event evt, int x, int y)
	{
		return true;
	}
*/
	public boolean mouseDown(Event evt, int x, int y)
	{
		if ((x>(dx-55)) & (x<(dx-35)) & (y<(dy+160-50)) & (y>(dy-120-50)) )
		{
			clock=true;
			repaint();
			
			text.setText(lQ0.getText());
			lQ0.setText(lQ1.getText());
			lQ1.setText(lQ2.getText());
			lQ2.setText(lQ3.getText());
			lQ3.setText(text.getText());
			text.setText("");
			
			
		}

		return true;
	}

	public boolean mouseUp(Event evt, int x, int y)
	{
		clock=false;
		repaint();
		return true;
	}




}

	


