Pessoal to tentando terminar meu trabalho da faculdade mas encontro esse erro ai, vou selecionar no combo box a escolha ai clico e da erro ... tem como alguém me dar uma luz que eu não to conseguindo entender.
package guj;
import java.awt.EventQueue;
import javax.swing.JFrame;
import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class CalculoAreasEVolumesFrame extends JFrame {
private JLabel lblEntidadeGeomtrica;
private JComboBox comboBox;
private JLabel lblMedida_1;
private JLabel lblMedida_2;
private JLabel lblMedida_3;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JButton btnCalcular;
private JButton btnLimpar;
private JLabel lblResultado;
private JLabel lblValor;
private Calculo c = new Calculo();
double base, altura, comprimento;
String result;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CalculoAreasEVolumesFrame frame = new CalculoAreasEVolumesFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CalculoAreasEVolumesFrame() {
setTitle("Calcular \u00C1reas e Volumes");
setBounds(100, 100, 450, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(
new MigLayout("", "[][grow]", "[][][][][][]"));
getContentPane().add(getLblEntidadeGeomtrica(),
"cell 0 0,alignx trailing");
getContentPane().add(getComboBox(), "cell 1 0,growx");
getContentPane().add(getLblMedida_1(), "cell 0 1,alignx trailing");
getContentPane().add(getTextField_1(), "cell 1 1,growx");
getContentPane().add(getLblMedida_2(), "cell 0 2,alignx trailing");
getContentPane().add(getTextField_2(), "cell 1 2,growx");
getContentPane().add(getLblMedida_3(), "cell 0 3,alignx trailing");
getContentPane().add(getTextField_3(), "cell 1 3,growx");
getContentPane().add(getBtnCalcular(), "flowx,cell 0 4,span 2,center");
getContentPane().add(getBtnLimpar(), "cell 0 4");
getContentPane().add(getLblResultado(), "cell 0 5,alignx trailing");
getContentPane().add(getLblValor(), "cell 1 5");
}
private JLabel getLblEntidadeGeomtrica() {
if (lblEntidadeGeomtrica == null) {
lblEntidadeGeomtrica = new JLabel("Entidade geom\u00E9trica:");
}
return lblEntidadeGeomtrica;
}
private JComboBox getComboBox() {
if (comboBox == null) {
comboBox = new JComboBox();
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (comboBox.getSelectedItem().equals("Tri\u00E2ngulo")) {
lblMedida_1.setText("Base");
lblMedida_2.setText("Altura");
lblMedida_3.setText("");
lblMedida_3.setVisible(false);
textField_1.setEnabled(true);
textField_2.setEnabled(true);
textField_3.setEnabled(false);
textField_3.setVisible(false);
base = Double.valueOf(lblMedida_1.getText());
altura = Double.valueOf(lblMedida_2.getText());
result = String.valueOf(c.areaTrinagulo(base, altura));
lblResultado.setText("Área = "+result);
} else if (comboBox.getSelectedItem().equals("Quadrado")) {
lblMedida_1.setText("Lado");
lblMedida_2.setText("");
lblMedida_3.setText("");
textField_1.setEnabled(true);
textField_2.setEnabled(false);
textField_3.setEnabled(false);
textField_2.setVisible(false);
textField_3.setVisible(false);
lblResultado.setText("Área = ");
} else if (comboBox.getSelectedItem().equals(
"Paralelepipedo")) {
lblMedida_1.setText("Largura");
lblMedida_2.setText("Altura");
lblMedida_3.setText("Comprimento");
textField_1.setEnabled(true);
textField_2.setEnabled(true);
textField_3.setEnabled(true);
lblResultado.setText("Volume = ");
} else if (comboBox.getSelectedItem().equals("Cilindro")) {
lblMedida_1.setText("Base");
lblMedida_2.setText("Altura");
lblMedida_3.setText("");
textField_1.setEnabled(true);
textField_2.setEnabled(false);
textField_3.setEnabled(false);
textField_3.setVisible(false);
lblResultado.setText("Volume = ");
} else if (comboBox.getSelectedItem().equals("Prisma")) {
lblMedida_1.setText("Base");
lblMedida_2.setText("Altura");
lblMedida_3.setText("");
textField_1.setEnabled(true);
textField_2.setEnabled(false);
textField_3.setEnabled(false);
textField_3.setVisible(false);
lblResultado.setText("Volume = ");
}
}
});
comboBox.setModel(new DefaultComboBoxModel(new String[] {
"Escolha...", "Tri\u00E2ngulo", "Paralelepipedo",
"Cilindro", "Prisma", "Cilindro", "Prisma" }));
}
return comboBox;
}
private JLabel getLblMedida_1() {
if (lblMedida_1 == null) {
lblMedida_1 = new JLabel("Medida 1");
}
return lblMedida_1;
}
private JLabel getLblMedida_2() {
if (lblMedida_2 == null) {
lblMedida_2 = new JLabel("Medida 2");
}
return lblMedida_2;
}
private JLabel getLblMedida_3() {
if (lblMedida_3 == null) {
lblMedida_3 = new JLabel("Medida 3");
}
return lblMedida_3;
}
private JTextField getTextField_1() {
if (textField_1 == null) {
textField_1 = new JTextField();
textField_1.setColumns(10);
}
return textField_1;
}
private JTextField getTextField_2() {
if (textField_2 == null) {
textField_2 = new JTextField();
textField_2.setColumns(10);
}
return textField_2;
}
private JTextField getTextField_3() {
if (textField_3 == null) {
textField_3 = new JTextField();
textField_3.setColumns(10);
}
return textField_3;
}
private JButton getBtnCalcular() {
if (btnCalcular == null) {
btnCalcular = new JButton("Calcular!");
}
return btnCalcular;
}
private JButton getBtnLimpar() {
if (btnLimpar == null) {
btnLimpar = new JButton("Limpar");
}
return btnLimpar;
}
private JLabel getLblResultado() {
if (lblResultado == null) {
lblResultado = new JLabel("Resultado:");
}
return lblResultado;
}
private JLabel getLblValor() {
if (lblValor == null) {
lblValor = new JLabel("valor");
}
return lblValor;
}
}
package guj;
public class Calculo {
public static double areaTrinagulo(double base, double altura) {
return base * altura;
}
public static double volumeQuadrado(double l) {
return l * l * l;
}
public static double volumePara(double l, double h, double c) {
return l * h * c;
}
public static double volumeCili(double base, double altura) {
return 3.14 * ((base * base) * altura);
}
public static double volumePrisma(double base, double altura) {
return base* altura;
}
}
tenso demais, o resto dos trabalhos eu fiz só que toda hora da esse erro, já refiz e nada … só quero entender o pq desse erro como vcs estão me dizendo não to conseguindo entender …
já arrumei ele