// Copyright 1997, Joseph Bergin.  All rights reserved.  // Updated 2002 for Java 2import symantec.itools.awt.WrappingLabel;import java.awt.*;import java.applet.*;import java.awt.event.*;public class StabilityCalculator extends Applet {	public void init() 	{	super.init();		setLayout(null);		resize(560,310);		Color paleYellow = new Color(16777171);		Font timesRoman10 = new Font("TimesRoman", Font.PLAIN, 10);		Font dialog14 = new Font("Dialog", Font.PLAIN, 14);		setBackground(paleYellow);		xMissles = new TextField();		xMissles.setText("200");		xMissles.setBounds(105,94,35,28);	//	xMissles.setBackground(new Color(16777215));		add(xMissles);		yMissles = new TextField();		yMissles.setText("150");		yMissles.setBounds(105,140,35,28);	//	yMissles.setBackground(new Color(16777215));		add(yMissles);		xWarheads = new TextField();		xWarheads.setText("1");		xWarheads.setBounds(160,94,30,28);	//	xWarheads.setBackground(new Color(16777215));		add(xWarheads);		yWarheads = new TextField();		yWarheads.setText("3");		yWarheads.setBounds(160,140,30,28);	//	yWarheads.setBackground(new Color(16777215));		add(yWarheads);		xTotalWarheads = new TextField();		xTotalWarheads.setEnabled(false);		xTotalWarheads.setBounds(206,94,44,28);		xTotalWarheads.setBackground(paleYellow);		add(xTotalWarheads);		yTotalWarheads = new TextField();		yTotalWarheads.setEnabled(false);		yTotalWarheads.setBounds(206,140,44,28);		yTotalWarheads.setBackground(paleYellow);		add(yTotalWarheads);		xKillProb = new TextField();		xKillProb.setText(".9");		xKillProb.setBounds(266,94,30,28);	//	xKillProb.setBackground(new Color(16777215));		add(xKillProb);		yKillProb = new TextField();		yKillProb.setText(".8");		yKillProb.setBounds(267,140,30,28);	//	yKillProb.setBackground(new Color(16777215));		add(yKillProb);		xFirstStrike = new TextField();		xFirstStrike.setEnabled(false);		xFirstStrike.setBounds(324,94,96,28);		xFirstStrike.setBackground(paleYellow);		add(xFirstStrike);		yFirstStrike = new TextField();		yFirstStrike.setEnabled(false);		yFirstStrike.setBounds(325,140,96,28);		yFirstStrike.setBackground(paleYellow);		add(yFirstStrike);		threshold = new TextField();		threshold.setText("0.5");		threshold.setBounds(464,113,56,28);	//	threshold.setBackground(new Color(16777215));		add(threshold);		calculate = new Button("Calculate");		calculate.addActionListener(new CalculateListener());		calculate.setBounds(72,210,86,34);	//	calculate.setBackground(new Color(16777215));		add(calculate);		label1 = new Label("X");		label1.setBounds(70,97,23,21);		label1.setFont(dialog14);		add(label1);		label2 = new Label("Y");		label2.setBounds(69,144,23,21);		label2.setFont(dialog14);		add(label2);		label3 = new Label("Missles");		label3.setBounds(102,73,43,21);		label3.setFont(timesRoman10);		add(label3);		label8 = new Label("Stability Threshold");		label8.setBounds(450,87,90,21);		label8.setFont(timesRoman10);		add(label8);				wrappingLabel1 = new symantec.itools.awt.WrappingLabel();		wrappingLabel1.setText("Warheads  per  Missle");		wrappingLabel1.setBounds(154,58,50,38);		wrappingLabel1.setFont(timesRoman10);		add(wrappingLabel1);		wrappingLabel2 = new symantec.itools.awt.WrappingLabel();		wrappingLabel2.setText("Total Warheads");		wrappingLabel2.setBounds(208,58,49,38);		wrappingLabel2.setFont(timesRoman10);		add(wrappingLabel2);		wrappingLabel3 = new symantec.itools.awt.WrappingLabel();		wrappingLabel3.setText("Kill Probability per Warhead");		wrappingLabel3.setBounds(262,46,58,48);		wrappingLabel3.setFont(timesRoman10);		add(wrappingLabel3);		wrappingLabel4 = new symantec.itools.awt.WrappingLabel();		wrappingLabel4.setText("Probability of Successful First Strike");		wrappingLabel4.setBounds(334,46,70,48);		wrappingLabel4.setFont(timesRoman10);		add(wrappingLabel4);				Stability = new java.awt.TextField();		Stability.setEnabled(false);		Stability.setBounds(290,205,116,38);		Stability.setFont(new Font("Dialog", Font.BOLD|Font.ITALIC, 18));		Stability.setBackground(paleYellow);		add(Stability);		label4 = new Label("Stability Calculator");		label4.setBounds(10,1,276,53);		label4.setFont(new Font("Dialog", Font.PLAIN, 24));		add(label4);	}		private class CalculateListener implements ActionListener	{		public void actionPerformed(ActionEvent e)		{	calculate_Clicked();		}	}	private TextField xMissles;	private TextField yMissles;	private TextField xWarheads;	private TextField yWarheads;	private TextField xTotalWarheads;	private TextField yTotalWarheads;	private TextField xKillProb;	private TextField yKillProb;	private TextField xFirstStrike;	private TextField yFirstStrike;	private TextField threshold;	private Button calculate;	private Label label1;	private Label label2;	private Label label3;	private Label label8;	private symantec.itools.awt.WrappingLabel wrappingLabel1;	private symantec.itools.awt.WrappingLabel wrappingLabel2;	private symantec.itools.awt.WrappingLabel wrappingLabel3;	private symantec.itools.awt.WrappingLabel wrappingLabel4;	private TextField Stability;	private Label label4;	void calculate_Clicked() 	{	int xw = Integer.valueOf(xWarheads.getText()).intValue(),			yw = Integer.valueOf(yWarheads.getText()).intValue(), 			xm = Integer.valueOf(xMissles.getText()).intValue(),			ym = Integer.valueOf(yMissles.getText()).intValue();		int xwarheads = xm*xw;		int ywarheads = ym*yw;					float	t = Float.valueOf(threshold.getText()).floatValue(),				xk = Float.valueOf(xKillProb.getText()).floatValue(),				yk = Float.valueOf(yKillProb.getText()).floatValue();		if (xk > 1.0) // Sanity checks		{	xk = (float)1.0;			xKillProb.setText("1.0");		}		if (xk < 0.0)				{	xk = (float)0.0;			xKillProb.setText("0.0");		}				if (yk > 1.0)		{	yk = (float)1.0;			yKillProb.setText("1.0");		}		if (yk < 0.0)				{	yk = (float)0.0;					yKillProb.setText("0.0");		}						float	xfs = (float)Math.pow(1.0 - Math.pow(1.0 - xk, (float)(xwarheads)/(float)(ym)),  (float)(ym)),				yfs = (float)Math.pow(1.0 - Math.pow(1.0 - yk, (float)(ywarheads)/(float)(xm)),  (float)(xm));		// Formula fails if kill probability == 1.0.		if(xfs < .001) xfs = (float)0.0;		if(yfs < .001) yfs = (float)0.0;		xTotalWarheads.setText(""+xwarheads);		yTotalWarheads.setText(""+ywarheads);		if(xwarheads < ym) // Adjust in case kill probablility == 1. 			xfs = (float)0.0;		xFirstStrike.setText(""+xfs);		if(ywarheads < xm)			yfs = (float)0.0;		yFirstStrike.setText(""+yfs);		if(xfs < t && yfs < t)			Stability.setText("Stable");		else			Stability.setText("Unstable");			}}