Quiero hacer una intefaz para calcular el area de un triangulo equilátero , quiero que en JText Field Base el usuario pueda introducir un valor double que seria la base del triangulo y que en el JText Field Altura el usuario pueda introducir otro valor double que seria la altura del triangulo . Despues me gustaria que el jButton1 calcule el area de un triagulo equilatero (base*altura)/2 , me imprima el resultado en el jLabel areaResult y si es posible me imprima el procedimiento en el Jlabel proced. Si alguien me pudiera dar algunos consejos estaria muy agradecido , soy nuevo en esto de Java y solo he conseguido crear la interfaz y algunos botones. Gracias de antemano. aqui debajo esta el codigo que tengo escrito en NetBeans 12.0
import java.awt.DisplayMode;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.Scanner;
/**
*
* @author Bernat
*/
public class Triangulo extends javax.swing.JFrame {
/**
* Creates new form Triangulo
*/
public Triangulo() {
initComponents();
this.setLocationRelativeTo(null);
}
@Override
public Image getIconImage() {
Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("imagenes/logohp.png"));
return retValue;}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
Base = new javax.swing.JTextField();
Altura = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
proced = new javax.swing.JLabel();
areaResult = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jTextField1.setFont(new java.awt.Font("Nirmala UI", 0, 10)); // NOI18N
jTextField1.setText("SOLO TRIANGULOS EQUILATEROS(de momento)");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 20, -1, -1));
jTextField2.setEditable(false);
jTextField2.setBackground(new java.awt.Color(0, 0, 0));
jTextField2.setForeground(new java.awt.Color(255, 255, 255));
jTextField2.setText("@bernsteinn");
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
Base.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BaseActionPerformed(evt);
}
});
getContentPane().add(Base, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 110, 110, -1));
getContentPane().add(Altura, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 140, 110, -1));
jButton1.setText("CALCULAR");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 190, -1, -1));
jLabel2.setFont(new java.awt.Font("Microsoft Yi Baiti", 0, 24)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Base");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 90, 50, 50));
jLabel3.setFont(new java.awt.Font("Microsoft Yi Baiti", 0, 24)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Altura");
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 130, 70, 30));
jLabel4.setFont(new java.awt.Font("Yu Gothic UI", 0, 18)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("AREA(Resultat)=");
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 260, 180, 30));
proced.setFont(new java.awt.Font("Segoe UI", 0, 18)); // NOI18N
proced.setForeground(new java.awt.Color(255, 255, 255));
proced.setText("AREA(Procediment)=");
getContentPane().add(proced, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 240, -1, -1));
areaResult.setBackground(new java.awt.Color(255, 255, 255));
getContentPane().add(areaResult, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 270, 130, 20));
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 246, 100, 20));
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/fondo-abstracto-degradado-negro-simple_1962-1556.jpg"))); // NOI18N
jLabel1.setText("jLabel1");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 300));
pack();
}// </editor-fold>
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void BaseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
double base = new Double(Base.getText());
double altura = new Double(Altura.getText());
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Triangulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Triangulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Triangulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Triangulo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Triangulo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Altura;
private javax.swing.JTextField Base;
private javax.swing.JLabel areaResult;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JLabel proced;
// End of variables declaration
}```