// // newAngle.java // newAngle // // Created by Chris Thiel on Sat Sep 21 2002. // Copyright (c) 2002 Chris Thiel. All rights reserved. // Educational use is free with permission // send an email to me at cct@ktb.net // // A simple Java applet that helps a student // coordinate co-ords to form angles that are // bisectors or vertical angles. // // ver 1.0 -21 Sept 02- // ver 1.1 -22 Sept 02- Adds checkbox for minor arc angle measurement. // ver 1.2 -17 Sept 03 - adjusted panels import java.awt.*; import java.applet.*; import java.awt.event.*; import java.util.EventListener; public class newAngle extends Applet implements ActionListener,MouseListener { myCanvas canvas; Panel np=new Panel(); Panel wp=new Panel(); Panel cp=new Panel(); Panel sp=new Panel(); Panel ep=new Panel(); Label l1=new Label("co-ords "); Label l2=new Label(" x"); Label l3=new Label(" y"); Label lA=new Label(" A"); Label lB=new Label(" B"); Label lC=new Label(" C");// not used TextField Ax=new TextField("50",5); TextField Ay=new TextField("20",5); TextField Bx=new TextField("40",5); TextField By=new TextField("-20",5); TextField Cx=new TextField(5);//not used TextField Cy=new TextField(5);//not used Button redrawBtn=new Button("Redraw"); Checkbox minorArc=new Checkbox("Always measure the minor angle"); public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mousePressed(MouseEvent e){ if (e.getSource()==minorArc){ canvas.ax=Float.valueOf(Ax.getText()).doubleValue() ; canvas.ay=Float.valueOf(Ay.getText()).doubleValue() ; canvas.bx=Float.valueOf(Bx.getText()).doubleValue() ; canvas.by=Float.valueOf(By.getText()).doubleValue() ; canvas.minorArc=!minorArc.getState();//opposite, since not yet changed canvas.repaint(); } } public void init() { setLayout(new BorderLayout()); add("North",np); np.setBackground(Color.orange); //set up check box minorArc.addMouseListener(this); np.add(minorArc); // add("Center",cp); // cp.setBackground(Color.yellow); canvas= new myCanvas(); add("Center", canvas ); canvas.setSize(200,300); add("South",sp); sp.setBackground(Color.red); add("West", wp); wp.setBackground(Color.cyan); add("East", ep); ep.setBackground(Color.orange); redrawBtn.addActionListener(this); sp.add(redrawBtn); wp.setLayout(new GridLayout(4,3)); wp.add(l1); wp.add(l2); wp.add(l3); wp.add(lA); wp.add(Ax); wp.add(Ay); wp.add(lB); wp.add(Bx); wp.add(By); //wp.add(lC); //wp.add(Cx); //wp.add(Cy); repaint(); } public void actionPerformed(ActionEvent e){ canvas.ax=Float.valueOf(Ax.getText()).doubleValue() ; canvas.ay=Float.valueOf(Ay.getText()).doubleValue() ; canvas.bx=Float.valueOf(Bx.getText()).doubleValue() ; canvas.by=Float.valueOf(By.getText()).doubleValue() ; canvas.minorArc=minorArc.getState(); canvas.repaint(); } public void paint (Graphics g) { } } class myCanvas extends Canvas { private Font font = new Font("serif", Font.ITALIC + Font.BOLD, 14); public String t; public double ax=50.0; public double ay=20.0; public double bx=40.0; public double by=-20.0; public boolean minorArc=false; myCanvas(){ setBackground(Color.yellow); } private int sX(double x){ return (int)(5*x); } private int sY(double y){ return 125-(int)(5*y); } private double angleA(){ double d=Math.sqrt((sY(ay)-sY(0))*(sY(ay)-sY(0))+(sX(ax)-150)*(sX(ax)-150)); double acute= (180/Math.PI)*Math.asin((sY(0)-sY(ay))/d); if (acute<0) acute *= -1; if ((sX(ax)>150)&&(sY(ay)>=sY(0))) acute = acute+180;//bottom right if ((sX(ax)>150)&&(sY(ay)=sY(0))) acute = 360-acute;//bottom left if ((minorArc)&&(acute>180)) acute=360-acute; acute=.1*(int)(acute*10); return acute; } private double angleB(){ double d=Math.sqrt((sY(by)-sY(0))*(sY(by)-sY(0))+(sX(bx)-150)*(sX(bx)-150)); double acute= (180/Math.PI)*Math.asin((sY(0)-sY(by))/d); if (acute<0) acute *= -1; if ((sX(bx)>150)&&(sY(by)>=sY(0))) acute = acute;//bottom right if ((sX(bx)>150)&&(sY(by)<=sY(0))) acute = 360-acute;//top right if ((sX(bx)<=150)&&(sY(by)>=sY(0))) acute = 180-acute;//bottom left if ((sX(bx)<=150)&&(sY(by)180)) acute=360-acute; acute=.1*(int)(acute*10); return acute; } public void paint( Graphics g ){ g.setColor(Color.black); g.setColor(Color.blue); g.setFont(font); g.drawString("m