Quando vou rodar o codigo abaixo, o Netbeans acusa o seguinte erro:
[color=red]Exception in thread “main” java.lang.ExceptionInInitializerError
at exercicio3a.Exercicio3A.main(Exercicio3A.java:20)
Caused by: java.lang.RuntimeException: Uncompilable source code - exercicio3a.Interface3A.ButtonHandler is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
at exercicio3a.Interface3A.(Interface3A.java:58)
… 1 more
Java Result: 1[/color]
Porque o código não compila?
[size=18]MAIN:[/size]
[code]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package exercicio3a;
import javax.swing.JFrame;
/**
*
-
@author Usuario
*/
public class Exercicio3A {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Interface3A calculos = new Interface3A();
calculos.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calculos.setSize(210,160);
calculos.setVisible(true);
}
}[/code]
-
@param args the command line arguments
[size=18]CLASSE:[/size]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exercicio3a;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
/**
*
* @author Usuario
*/
public class Interface3A extends JFrame {
private JTextField entrada1;
private JTextField entrada2;
private JPanel painel1;
private JLabel texto1;
private JLabel texto2;
private JLabel texto3;
private JLabel texto4;
private JButton calcular;
private double base, altura, area, perimetro;
public Interface3A() {
super("Retangulo");
super.setLayout(new FlowLayout());
entrada1 = new JTextField();
entrada2 = new JTextField();
texto1 = new JLabel("Valor da base:");
texto2 = new JLabel("Valor da altura:");
texto3 = new JLabel();
texto4 = new JLabel();
calcular = new JButton("Calcular");
painel1 = new JPanel();
painel1.add(texto1);
painel1.add(entrada1);
painel1.add(texto2);
painel1.add(entrada2);
painel1.add(texto3);
painel1.add(texto4);
painel1.add(calcular);
painel1.setLayout(new GridLayout(4,2,1,1));
super.add(painel1);
ButtonHandler registro = new ButtonHandler();
calcular.addActionListener(registro);
}
private class ButtonHandler implements ActionListener {
public void actionerformed(ActionEvent event) {
base = Double.parseDouble(entrada1.getText());
altura = Double.parseDouble(entrada2.getText());
area = base * altura;
perimetro = (2 * base) + (2 * altura);
texto3.setText(String.format("Area = %2.f", area));
texto4.setText(String.format("Perimetro = %2.f", perimetro));
}
}
}