import java.awt.*; public class Details extends Rectangle { private int WIDTH; private int HEIGHT; private SineWave sine1, sine2; private Bragg bragg; private Rectangle detectorBox; private int leftMargin = 20; private int rightMargin = 50; private int length = 200; // width of sine waves private int height1 = 40; // height of sine1 private int height2 = 80; // height of sie2 private int amplitude = 12; private FontMetrics fm; //--------------------CONSTRUCTOR---------------------------- public Details(int xnew, int ynew, int wnew, int hnew) { super(xnew, ynew, wnew, hnew); detectorBox = new Rectangle(x+width/2-70, y+height2+40, 140, 80); } //---------------------------DRAW--------------------------- public void draw(Graphics g, SineWave s1, SineWave s2, Bragg b) { this.bragg = new Bragg(Bragg.FORMULA, b.getLambda(Bragg.FORMULA), b.getDistance(Bragg.FORMULA), b.getTheta()); this.sine1 = new SineWave(s1.getWavelength(), amplitude, s1.getPhase()); this.sine2 = adjust(s2); if(fm == null) fm = g.getFontMetrics(); initArea(g); drawGraphPaper(g); drawRays(g); drawRightAngle(g); drawVertDash(g); drawAtoms(g); drawSineWaves(g); drawText(g); drawDetector(g); drawDisplay(g); drawLight(g); } //-------------------------PRIVATE METHODS----------------- private void initArea(Graphics g) { g.setColor(Color.white); g.fill3DRect(x, y, width, height, true); g.setColor(Color.black); g.drawRect(x,y,width,height); } //-------- private void drawGraphPaper(Graphics g) { g.setColor(Color.lightGray); for (int i = 10; i= 360) ph1 -= 360; float ph2 = sine2.getPhase(); while (ph2 >= 360) ph2 -= 360; float combined = Math.abs(ph1 - ph2); if (combined > 180) combined = 360 - combined; float fangle = combined*100f/180f; radius = 55; Point parrow = MyMath.rotate(center, startAngle+105-fangle, radius); g.drawLine(center.x, center.y, parrow.x, parrow.y); g.drawLine(center.x, center.y, parrow.x-1, parrow.y); g.drawLine(center.x, center.y, parrow.x+1, parrow.y); } private void drawLight(Graphics g) { Rectangle light = new Rectangle(detectorBox.x+detectorBox.width-15, detectorBox.y+5, 10,10); Color color; if(bragg.satisfied(1)) color = Color.green; else color = Color.red; g.setColor(color); g.fillOval(light.x, light.y, light.width, light.height); g.setColor(Color.black); g.drawOval(light.x, light.y, light.width, light.height); } //------- private SineWave adjust(SineWave s) { double distance = bragg.getDistance(Bragg.GRAPH); double theta = MyMath.toRadians(bragg.getTheta()); // in Radians distance = distance*Math.sin(theta); return new SineWave(s.getWavelength(), amplitude, s.getPhase((float)distance)); } }