// The "CosineLaw" class.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
public class CosineLaw121 extends Applet implements MouseListener
{
int choice = 0;
//delay method
public static void delay (int milliseconds)
{
try
{
Thread.sleep (milliseconds);
}
catch (InterruptedException e)
{
}
}
public void init ()
{
setSize (640, 400);
setBackground (new Color (0, 0, 0));
addMouseListener (this);
JFrame frame = new JFrame ();
MyPanel panel = new MyPanel ("triangles.jpg");
frame.setContentPane (panel);
frame.setDefaultCloseOperation (3);
frame.setBounds (new Rectangle (500, 500));
frame.setVisible (true);
panel.repaint ();
}
public void paint (Graphics g)
{
if (choice == 0)
{
int i;
for (i = 0 ; i < 25 ; i++)
{
g.setColor (Color.black);
g.fillRect (0, 0, 1000, 1000);
g.setFont (new Font ("Ravie", 3, 20));
g.setColor (Color.red);
g.drawString ("Question One", 230, 0 + i);
}
delay (300);
g.setFont (new Font ("Times New Roman", 3, 15));
g.drawString ("These diagrams represent 3 problems. A strategy for each problem", 160, 40);
g.drawString ("is listed, but not in the correct order.", 160, 60);
g.drawString (" 1) Match each diagram to a strategy. Explain your reasoning.", 160, 80);
g.drawString (" 2) Apply each strategy to the matched diagram. (Calculate)", 160, 100);
delay (1000);
g.setFont (new Font ("Times New Roman", 3, 12));
g.setColor (Color.red);
g.drawString ("a)Notice that the", 100, 310);
g.drawString ("triangle has a right", 100, 320);
g.drawString ("angle. Use either", 100, 330);
g.drawString ("the sine or cosine", 100, 340);
g.drawString ("ratio.", 100, 350);
g.drawString ("b)Use the sine rule", 250, 310);
g.drawString ("with 2 angles and ", 250, 320);
g.drawString ("there opposite sides.", 250, 330);
g.drawString ("Solve the resulting", 250, 340);
g.drawString ("equation for the unknown.", 250, 350);
g.drawString ("c)Use the cosine rule", 400, 310);
g.drawString ("with 1 angle and 2 sides", 400, 320);
g.drawString ("to find the remaining", 400, 330);
g.drawString ("sides.", 400, 340);
g.setColor (Color.white);
g.fillRect (305, 360, 50, 20);
g.setColor (Color.black);
g.drawString ("NEXT", 310, 373);
}
else if (choice == 1)
{
int i;
for (i = 0 ; i < 50 ; i++)
{
g.setColor (Color.black);
g.fillRect (0, 0, 1000, 1000);
g.setFont (new Font ("Ravie", 3, 20));
g.setColor (Color.red);
g.drawString ("Example", 230, 0 + i);
}
//triangle image
g.setColor (Color.red);
delay (100);
g.drawLine (150, 250, 300, 250);
delay (100);
g.drawLine (150, 250, 120, 100);
delay (100);
g.drawLine (120, 100, 300, 250);
delay (100);
g.setFont (new Font ("Times New Roman", 3, 15));
g.setColor (Color.yellow);
g.drawString ("A", 115, 95);
delay (100);
g.drawString ("B", 140, 265);
delay (100);
g.drawString ("C", 305, 255);
delay (100);
g.setColor (Color.orange);
g.drawString ("a", 220, 265);
delay (100);
g.drawString ("b", 215, 170);
delay (100);
g.drawString ("c", 125, 180);
delay (100);
//question
g.setColor (Color.red);
g.drawString ("Find side 'a' to the nearest whole number", 100, 300);
g.drawString ("Find angles B and C to the nearest degrees", 100, 320);
delay (100);
g.drawString ("A = 21 degrees", 100, 340);
g.drawString ("b = 27", 100, 360);
g.drawString ("c = 20", 100, 380);
delay (100);
g.drawString ("Try to solve it yourself", 100, 400);
delay (100);
g.drawString ("You can check your answer afterwards, just click the solution button", 100, 420);
delay (700);
//solution button
g.setColor (Color.white);
g.fillRect (450, 350, 100, 40);
g.setColor (Color.black);
g.drawRect (455, 355, 90, 30);
g.drawString ("Solution", 475, 375);
}
else if (choice == 2)
{
int i;
for (i = 0 ; i < 50 ; i++)
{
g.setColor (Color.black);
g.fillRect (0, 0, 1000, 1000);
g.setFont (new Font ("Ravie", 3, 20));
g.setColor (Color.red);
g.drawString ("Solution", 250, 0 + i);
}
g.setFont (new Font ("Times New Roman", 3, 10));
g.drawString ("2 2 2", 110, 133);
g.drawString ("2 2 2", 117, 211);
g.setFont (new Font ("Times New Roman", 3, 15));
g.drawString ("Answer:", 100, 100);
delay (200);
g.drawString ("b = 27 c = 20 <A = 21", 100, 120);
g.drawString ("a = 27 + 20 - 2(27)(20)(cos 21)", 100, 140);
g.drawString ("a = 729 + 400 - 1080(cos 21)", 100, 160);
g.drawString ("a = 11", 100, 180);
g.drawString (" ", 100, 200);
delay (200);
g.drawString ("20 = 11 + 27 - 2(11)(27)(cos C)", 100, 220);
g.drawString ("400 = 121 +729 - 594(cos C)", 100, 240);
g.drawString ("594(cos C) = 450", 100, 260);
g.drawString ("cos C = 450/594", 100, 280);
g.drawString ("<C = 41 degrees", 100, 300);
g.drawString (" ", 100, 320);
delay (200);
g.drawString ("<B = 180 - <A - <C", 100, 340);
g.drawString ("<B = 180 - 21 - 41", 100, 360);
g.drawString ("<B = 118 degrees", 100, 380);
//restart button
g.setColor (Color.white);
g.fillRect (450, 200, 100, 40);
g.setColor (Color.black);
g.drawRect (455, 205, 90, 30);
g.drawString ("Restart", 475, 225);
}
}
public void mouseClicked (MouseEvent event)
{
int x, y;
x = event.getX ();
y = event.getY ();
if (choice == 0)
{
if (x > 300 && x < 365 && y > 360 && y < 385)
{
choice = 1;
repaint ();
}
}
else if (choice == 1)
{
if (x > 450 && x < 550 && y > 350 && y < 390)
{
choice = 2;
repaint ();
}
}
else if (choice == 2)
{
if (x > 450 && x < 550 && y > 200 && y < 240)
{
choice = 0;
repaint ();
}
}
}
public void mousePressed (MouseEvent event)
{
}
public void mouseReleased (MouseEvent event)
{
}
public void mouseEntered (MouseEvent event)
{
}
public void mouseExited (MouseEvent event)
{
}
class MyPanel extends JComponent
{
private Image myImage;
public MyPanel (String imageName)
{
super ();
setImage (imageName);
}
public void paint (Graphics g)
{
super.paint (g);
g.drawImage (myImage, 0, 0, this);
}
public void setImage (String fileName)
{
//myImage = getToolkit().getImage (fileName);
}
}
}
|