View Single Post
  #1 (permalink)  
Old 07-22-2007, 11:14 PM
toby toby is offline
Member
 
Join Date: Jul 2007
Posts: 40
toby is on a distinguished road
Help with images...
I have a coding problem... and if someone can help me finish it.. it would be grateful...
I can't make the numbers to respond to the answers...... and follow the image says...

Code:
Code:
import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class TriangleArea extends Applet implements ActionListener { private Label lblInstructions, lblSideA, lblSideB, lblSideC, lblSelect, lblAngles, lblArea, lblRightAngle; private TextField txtSideA, txtSideB, txtSideC; private Button btnCM, btnM, btnKM; double[] angles = new double[3]; double radians; public void init() { setLayout(null); setupGUIComponents(); final int WIDTH = 470, HEIGHT = 220; setSize(WIDTH, HEIGHT); } public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand(); lblAngles.setText("Three angles are "+angles[0]+"degree, "+angles[1]+"degree and "+angles[2]+"degree"); lblArea.setText("Area of the triangle is "+command); lblRightAngle.setText("It is a "+command+" triangle"); } private void setupGUIComponents() { // initiaze the components lblInstructions = new Label("Enter the length of the sides of a triangle"); lblSideA = new Label("a"); txtSideA = new TextField(5); lblSideB = new Label("b"); txtSideB = new TextField(5); lblSideC = new Label("c"); txtSideC = new TextField(5); lblSelect = new Label("Select unit:"); btnCM = new Button("cm"); btnM = new Button("m"); btnKM = new Button("km"); lblAngles = new Label(); lblArea = new Label(); lblRightAngle = new Label(); // add action-listeners to the buttons btnCM.addActionListener(this); btnM.addActionListener(this); btnKM.addActionListener(this); // allign the components to the frame lblInstructions.setBounds(100,10,250,20); lblSideA.setBounds(100,35,20,20); txtSideA.setBounds(220,35,115,20); lblSideB.setBounds(100,55,20,20); txtSideB.setBounds(220,55,115,20); lblSideC.setBounds(100,75,20,20); txtSideC.setBounds(220,75,115,20); lblSelect.setBounds(130,100,70,20); btnCM.setBounds(210,100,30,20); btnM.setBounds(245,100,30,20); btnKM.setBounds(280,100,30,20); lblAngles.setBounds(20,140,410,20); lblArea.setBounds(20,165,410,20); lblRightAngle.setBounds(20,190,410,20); // add the components to the frame add(lblInstructions); add(lblSideA); add(txtSideA); add(lblSideB); add(txtSideB); add(lblSideC); add(txtSideC); add(lblSelect); add(btnCM); add(btnM); add(btnKM); add(lblAngles); add(lblArea); add(lblRightAngle); } private double[] getAngles(int a, int b, int c) { // create an array to store the 3 angles double[] angles = new double[3]; double radians; // cast all the int values to double double dA=(double)a, dB=(double)b, dC=(double)c; // angle A in radians = cos^-1 (b^2 + c^2 - a^2 / 2bc) // and then convert the radians to degrees radians = Math.acos((dB*dB + dC*dC - dA*dA) / (2.0*dB*dC)); angles[0] = radians * 180.0 / Math.PI; // angle B in radians = cos^-1 (a^2 + c^2 - b^2 / 2ac) // and then convert the radians to degrees radians = Math.acos((dA*dA + dC*dC - dB*dB) / (2.0*dA*dC)); angles[1] = radians * 180.0 / Math.PI; // angle C in degrees = 180 - degrees A - degrees B angles[2] = 180.0 - angles[0] - angles[1]; // return the 3 angles return angles; } }
When i try to input the numbers into the textfield....
No number came out to the output....
If anyway.... can help to complete the java code...??
Thanks
Reply With Quote
Sponsored Links