• Lenguaje

    Java usando Applet

  • Descripción

    Dado un triángulo de lados a, b y c, donde a > c y a > b. Determine el tipo de triángulo de acuerdo a las siguientes condiciones:
    Si a2 = b2 + c2 -> es un triángulo rectángulo.
    Si a2 < b2 + c2 -> es un triángulo acutángulo.
    Si a2 > b2 + c2 -> es un triángulo obtusángulo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class TipoDeTriangulo extends Applet implements ActionListener {

    private static final long serialVersionUID = 1L;
    private TextField field_a, field_b, field_c;
    private Button button;

    @Override
    public void init() {
        field_a = new TextField(4);
        field_b = new TextField(4);
        field_c = new TextField(4);
        button = new Button("Procesar");
        setLayout(new BorderLayout());
        Panel panel, subpanel;
        panel = new Panel(new BorderLayout());
        subpanel = new Panel(new GridLayout(3, 1));
        subpanel.add(new Label("Ingresa el valor de a:"));
        subpanel.add(new Label("Ingresa el valor de b:"));
        subpanel.add(new Label("Ingresa el valor de c:"));
        panel.add(subpanel, BorderLayout.WEST);
        subpanel = new Panel(new GridLayout(3, 1));
        subpanel.add(field_a);
        subpanel.add(field_b);
        subpanel.add(field_c);
        panel.add(subpanel);
        add(panel, BorderLayout.NORTH);
        panel = new Panel(new FlowLayout());
        panel.add(button);
        add(panel);
        button.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent actionEvent) {
        double a, b, c;
        try {
            a = Double.parseDouble(field_a.getText());
            b = Double.parseDouble(field_b.getText());
            c = Double.parseDouble(field_c.getText());
        } catch (NumberFormatException numberFormatException) {
            return;
        }
        if(a*a==b*b+c*c)
            javax.swing.JOptionPane.showMessageDialog(this, "Rect\u00E1ngulo");
        if(a*a<b*b+c*c)
            javax.swing.JOptionPane.showMessageDialog(this, "Acut\u00E1ngulo");
        if(a*a>b*b+c*c)
            javax.swing.JOptionPane.showMessageDialog(this, "Obtus\u00E1ngulo");
    }

}