import java.applet.*; import java.awt.*; public class StressPlan extends Applet { Font font = new Font("TimesRoman",Font.PLAIN,12); TextField volumeField, pathlengthField, precisionField; Choice materialChoice; Panel instPanel; Label[] instrumentLabels; Checkbox[] unitBoxes, precisionBoxes; CheckboxGroup unitGroup, precisionGroup; StressCalculator calculator = new StressCalculator(); TextArea results; public void init() { setLayout( new BorderLayout() ); setBackground(Color.white); instPanel = new Panel(); Label title = new Label("BT8 Configurator", Label.CENTER); Panel panel = new Panel(); Panel boxPanel = new Panel(); boxPanel.setLayout( new FlowLayout()); title.setFont(new Font("TimesRoman",Font.PLAIN,20)); add("North", title); add("Center", panel); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); Label unitLabel = new Label("Calculation Units:", Label.CENTER); unitLabel.setFont(font); unitGroup = new CheckboxGroup(); unitBoxes = new Checkbox[2]; unitBoxes[0] = new Checkbox("MPa", unitGroup, false); unitBoxes[1] = new Checkbox("ksi", unitGroup, true); unitBoxes[0].setFont(font); unitBoxes[1].setFont(font); boxPanel.add(unitLabel); boxPanel.add(unitBoxes[0]); boxPanel.add(unitBoxes[1]); c.ipadx = 5; c.weightx = 1.0; c.weighty = 1.0; c.gridwidth = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.NONE; gridbag.setConstraints(boxPanel,c); panel.add(boxPanel); materialChoice = new Choice(); materialChoice.addItem("Iron"); materialChoice.addItem("Stainless Steel"); materialChoice.addItem("Aluminum"); materialChoice.setFont(font); instPanel.setLayout( new GridLayout(0,2) ); instrumentLabels = new Label[5]; instrumentLabels[0] = new Label("Material: ", Label.RIGHT); instrumentLabels[1] = new Label("90deg. pathlength (mm): ", Label.RIGHT); instrumentLabels[2] = new Label("Precision (ksi): ", Label.RIGHT); instrumentLabels[3] = new Label("Precision Units: ", Label.RIGHT); instrumentLabels[4] = new Label("Meas. volume (mm^3): ", Label.RIGHT); precisionGroup = new CheckboxGroup(); precisionBoxes = new Checkbox[2]; precisionBoxes[0] = new Checkbox("%", precisionGroup, false); precisionBoxes[1] = new Checkbox("Absolute", precisionGroup, true); Panel precisionBoxPanel = new Panel(); precisionBoxPanel.setLayout(new FlowLayout()); precisionBoxPanel.add(precisionBoxes[0]); precisionBoxPanel.add(precisionBoxes[1]); int[] resInts = new int[3]; double[] resValues = new double[3]; resInts[0] = 0; //material choice resInts[1] = 0; //units of stress 0 = MPa; 1 = kpsi resInts[2] = 0; //units for precision 0 = %; 1 = absolute resValues[0] = 50.0; // pathlength mm resValues[1] = 10.0; // precision percent resValues[2] = 8.0; // cubic millimeters pathlengthField = new TextField(String.valueOf(resValues[0]),8); pathlengthField.setFont(font); precisionField = new TextField(String.valueOf(resValues[1]),8); precisionField.setFont(font); volumeField = new TextField(String.valueOf(resValues[2]),8); volumeField.setFont(font); for(int i=0;i 343.0) { // 7mm on each side cubed volume = 343.0; volumeField.setText(String.valueOf(volume)); } double pathlength = 50.0; try { pathlength = Double.valueOf(pathlengthField.getText()).doubleValue(); } catch (NumberFormatException exc) { } if (pathlength < 0.0) { pathlength = 0.0; pathlengthField.setText(String.valueOf(pathlength)); } double precision = 10.0; try { precision = Double.valueOf(precisionField.getText()).doubleValue(); } catch (NumberFormatException exc) { } if (precision <= 0.0) { precision = 0.01; precisionField.setText(String.valueOf(precision)); } String precisionType = precisionGroup.getCurrent().getLabel(); if (precisionType.equalsIgnoreCase("%")) { if (precision > 100.0) { precision = 100.0; precisionField.setText(String.valueOf(precision)); } } int material = (int)materialChoice.getSelectedIndex(); String materialName = materialChoice.getSelectedItem(); String unitType = unitGroup.getCurrent().getLabel(); String precisionString = "%"; if (precisionType.equalsIgnoreCase("%")) { precisionString = "%"; } else { precisionString = unitType; } //Do calculation StressOutput output = calculator.calculateStress(volume, pathlength, precision, material, unitType ); //assemble text of result. String outputString = "This configuration for BT8" +" is:\n"; outputString += materialName+" is set as the sample material.\n"; outputString += "Calculating in units of "+unitType+".\n"; outputString += (new Format("Pathlength: %9.4f").format(pathlength)) +" mm \n" +(new Format("Precision: +/- %9.4G").format(precision)) +" "+precisionString+"\n"; outputString += (new Format("Measurement Volume: %9.4f").format(volume)) +" mm^3\n"; outputString += (new Format("Intensity at sample: %9.4G").format(output.intensity)) +" Counts/sec\n"; outputString += (new Format("Measurement Time: %9.0f").format(output.time)) +" min\n"; outputString += (new Format("Wavelength Used: %9.4G").format(output.wavelength)) +" A\n"; outputString += "Crystal Plane: ("+output.plane+").\n"; results.setText(outputString); validate(); } public void updateUnits() { String precisionType = precisionGroup.getCurrent().getLabel(); String unitType = unitGroup.getCurrent().getLabel(); String precisionString = "%"; if (precisionType.equalsIgnoreCase("%")) { precisionString = "%"; } else { precisionString = unitType; } instrumentLabels[2].setText("Precision ("+ precisionString+ "): "); validate(); } public boolean action(Event e, Object a) { if (e.target instanceof Checkbox) { updateUnits(); } writeOutput(); return true; } }