//import java packages for applet, and event
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
//class InputNamesFrame Frame
public class AnglePowerMeter extends Frame implements ActionListener
{
private int click;
//declare new borderlayout for the layout of the whole screen
BorderLayout layout = new BorderLayout ();
//declare panels for the borderlayout
Panel center = new Panel ();
Panel top = new Panel ();
Panel left = new Panel ();
Panel right = new Panel ();
Panel bottom = new Panel ();
Panel middle = new Panel ();
//initialize labels to prompt users for input of names
Label question = new Label ("Get Ready to choose your Power and Angle!", Label.CENTER);
Label getAngle = new Label ("Angle", Label.LEFT);
Label getPower = new Label ("Power", Label.LEFT);
//new textfields for input of names
TextField pAngle = new TextField (2);
TextField pPower = new TextField (2);
//buttons to continue and play, or reset all textfields, or cancel and go back to main menu
Button startAngle = new Button ("Angle Start");
Button startPower = new Button ("Power Start");
Button cancel = new Button ("Cancel");
//declare objects used in this object >.>
//MeterEngine meter = new MeterEngine ();
//double value of the angle to int value to string
// String angle = Math.round (exp) + "";
//constructor method
AnglePowerMeter (String title)
{
super (title);
resize (300, 150);
setLayout (layout);
top.setLayout (new FlowLayout ());
top.add (question);
add ("North", top);
center.setLayout (new FlowLayout ());
center.add (middle);
add ("Center", center);
middle.setLayout (new FlowLayout ());
middle.add ("West", getAngle);
getAngle.setBackground (Color.white);
middle.add ("West", pAngle);
pAngle.setEditable (false);
middle.add ("East", getPower);
getPower.setBackground (Color.white);
middle.add ("East", pPower);
pPower.setEditable (false);
left.setLayout (new FlowLayout ());
add ("West", left);
right.setLayout (new FlowLayout ());
add ("East", right);
bottom.setLayout (new FlowLayout ());
bottom.add (startAngle);
// startAngle.setMnemonic (KeyEvent.VK_A); //alt a shortcut
startAngle.addActionListener (this);
bottom.add (startPower);
bottom.add (cancel);
add ("South", bottom);
}
public void paint (Graphics g)
{
setBackground (Color.black);
}
public void actionPerformed (ActionEvent e)
{
Object source = e.getSource ();
if (source == startAngle)
{
double c = 1.8, i = 1, max = 90, exp = 0;
final double inc = 0.000355; //speed at while it increases
boolean f = false, g = false;
while (true)// #1
{
while (f == false) //increasing speed going up to 90
{
exp = Math.pow (c, i);
i += inc;
pAngle.setText (Math.round (exp) + "");
if (exp > max)
{
f = true;
g = false;
} //end if
} //end while
while (g == false) //decreasing speed going down from 90
{
exp = Math.pow (c, i);
i -= inc;
pAngle.setText (Math.round (exp) + "");
if (exp < 1)
{
g = true;
f = false;
} //end if
} //end while
} //end while
//end while
click++;
}
else if (source == startPower)
{
double c = 1.8, i = 1, exp = 0, max = 1000;
final double inc = 0.000543; //speed at which it increases
boolean f = false, g = false;
while (true)//#2
{
while (f == false)
{
exp = Math.pow (c, i);
pPower.setText (Math.round (exp) + "");
i += inc;
if (exp > max)
{
f = true;
g = false;
} //end if
} //end while
while (g == false)
{
exp = Math.pow (c, i);
pPower.setText (Math.round (exp) + "");
i -= inc;
if (exp < 1)
{
g = true;
f = false;
} //end if
} //end while
} //end while
}
else if (source == cancel)
{
pAngle.setText ("");
pPower.setText ("");
dispose ();
}
}
} |