1
When I click on the woman or man icon on JFrame
, is called a JPanel
where I enter the data such as weight and height. But by clicking save, I cannot call another JPanel
to show the result of the calculation, as I am already in a.
Is there any way to put a menu item inside the woman or man icon, as if it were a sub-shortcut?
Main class Jframe:
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 user reports 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:
}
// ...
}
Ester, I had already answered, have you tried the solution below? That’s basically the answer;
– user28595