When I click on the woman or man icon in JFrame
, it is called a JPanel
where I enter the data as weight and height. But when I click save, I can not call another JPanel
to show the result of the calculation, since I'm already in one.
Is there a way to put a menu item inside the woman or man icon, as if it were a sub-shortcut?
JFrame main class:
public class Home extends javax.swing.JFrame {
public Home() {
initComponents();
}
private void jImcHomemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ImcHomem imcHomem = new ImcHomem();
this.setContentPane(imcHomem);
this.pack();
}
// ...
}
Class where the user informs the data (weight and height) JPanel
public class ImcHomem extends javax.swing.JPanel {
double pesoH;
double alturaH;
private void jBtnSalvarHActionPerformed(java.awt.event.ActionEvent evt){
// variável pesoH recebe o valor passado para Double do botão jTextPesoH
pesoH = Double.parseDouble(jTextPesoH.getText());
// variável alturaH recebe o valor passado para Double do botão jTextAlturaH
alturaH = Double.parseDouble(jTextAlturaH.getText());
// inseri os dados no botão Salvar só para ter certeza de que o código está correto
jBtnSalvarH.setText("Peso: "+pesoH+" kg "+" e altura: "+alturaH+" cm");
ResultHomem resuH = new ResultHomem();
}
private void jTextPesoHActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pesoH = Double.parseDouble(jTextPesoH.getText());
}
private void jTextAlturaHActionPerformed(java.awt.event.ActionEvent evt{
// TODO add your handling code here:
alturaH = Double.parseDouble(jTextAlturaH.getText());
}
// ...
}
Class that would call to show the result
public class ResultHomem extends javax.swing.JPanel {
/**
* Creates new form ResultHomem
*/
public ResultHomem() {
initComponents();
}
private void jTextResultHActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
// ...
}