All pastes #748611 Raw Edit

angry clock driver

public java v1 · immutable
#748611 ·published 2007-10-24 23:06 UTC
rendered paste body
/*k i cant figure out what the problem is with this... im supposed to basically make a clock, and right now i push buttons to move the hands, so im not even worrying about how to work with actual time... i cant get my hand to move properly. i can however redraw a new hand everytime where i want it (see moveHand2) but i cant just reset the bounds (see moveHand)if i try to pass a Line object into a method it compiles fine. but when i push the button that calls the method nothing happens and i get a large amount of technogarble relating to actionListener. any suggestions?*/import java.awt.*;import javax.swing.*;public class Driver  extends  ThreeButtons{	private ThreeButtonFrame  clockWin;	private Oval face;	public Line longHand, shortHand;	private int handPos = 90;	private double cos[] = new double[361];	private double sin[] = new double[361];	public Driver()   {		clockWin = new ThreeButtonFrame("A clock!");		clockWin.setLayout(null);		for (int i = 0; i<360 ;i++){ //initialize sin cos values for quick use later			cos[i] = Math.cos(Math.toRadians(i));			sin[i] = Math.sin(Math.toRadians(i));		}		//setBounds(20, 20, 600, 500); jframe bounds		Oval face = new Oval(125, 50, 350, 350); //sets a yellow oval		face.setBackground(Color.yellow);		clockWin.add(face,0);		//LINE (x, y)-(x + c!(th) * 50, y - s!(th) * 50), 4 'drawline borrowed from a qbasic program i wrote... that WORKS! $%#^		Line longHand = new Line(300, 225, (int)(300+cos[90]*175), (int)(225-sin[90]*175) ); // initializes the line at 12 o clock		longHand.setBackground(Color.black);		clockWin.add(longHand,0);		clockWin.repaint();	}	public  void  rightAction()   {		int x1,x2,y1,y2;		if (handPos-30 >= 0) //moves 30 degree sright			handPos -= 30;		else if (handPos-30<0)			handPos += 330;		x1 = 300;		x2 = (int)(300+cos[handPos]*175.0); // calculates new coordinates (as ints)		y1 = 225;		y2 = (int)(225-sin[handPos]*175.0);		System.out.println(handPos);		moveHand2(x1,y1,x2,y2);	}	public  void  midAction()   {				//moveHand(longHand,300,225,300,225); //ERROR!!		}	public  void  leftAction()   {		int x1,x2,y1,y2;		if (handPos+30 < 360)			handPos += 30;		else if (handPos+30>=360)			handPos -= 330;		x1 = 300;		x2 = (int)(300+cos[handPos]*175.0);		y1 = 225;		y2 = (int)(225-sin[handPos]*175.0);		System.out.println(handPos);		//moveHand2(x1,y1,x2,y2);	}	private void moveHand(Line lineMoved, int x1, int y1, int x2, int y2) // apparently it doesnt allow me to pass a Line into a method. but its not a compiker error ust an error when i run	{		lineMoved.setBounds(x1,y1,x2,y2); // is this even the proper command to move it? the line.java file doesnt say		clockWin.repaint();	}	private void moveHand2(int x1, int y1, int x2, int y2)	{        Line line;        line = new Line(x1,y1,x2,y2);	//initializes a new line and draws it...		line.setBackground(Color.black);		clockWin.add(line,0);		clockWin.repaint();		}/* failed tactic which would pass the line out, and id pass it back in and remove it every time i run the method	private Line moveHand2(Line deleteLine, int x1, int y1, int x2, int y2)	{        Line line;        //setLocation(locX,locY); ???		line = new Line(x1,y1,x2,y2);		//line = new Line(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1-x2)+1, Math.abs(y1-y2)+1);		//line.setForeground(getForeground());		line.setBackground(Color.black);		//window.getContentPane().add(line);		clockWin.add(line,0);		clockWin.remove(deleteLine);		clockWin.repaint();		return line;		}*/}