I'm having trouble putting functions for buttons in java. Can anyone help?
Follow the code:
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Painel extends JPanel{
private static final Color COR_FUNDO = Color.RED;
private int largura;
private int altura;
JFrame frame = new JFrame();
public Painel(int altura, int largura){
this.altura = altura;
this.largura = largura;
botaoAdicionar();
botaoRemover();
botaoConsultar();
botaoPesquisar();
}
public void botaoAdicionar(){
Botao adicionar = new Botao();
adicionar.setText("Adicionar ator");
adicionar.setForeground(Color.BLUE);
adicionar.setMargin(new Insets(2, 10, 2, 14));
adicionar.setFont(new Font("Linux libertine G", Font.BOLD, 14));
add(adicionar);
}
public void botaoRemover(){
Botao remover = new Botao();
remover.setText("Remover Ator");
remover.setForeground(Color.BLUE);
remover.setFont(new Font("Linux libertine G", Font.BOLD, 14));
remover.setLocation(200, 200);
remover.setEnabled(true);
add(remover);
}
public void botaoConsultar(){
Botao consultar = new Botao();
consultar.setText("Consultar elenco");
consultar.setForeground(Color.BLUE);
consultar.setFont(new Font("Linux libertine G", Font.BOLD, 14));
add(consultar);
}
public void botaoPesquisar(){
JButton pesquisar = new JButton("Pesquisar Ator");
pesquisar.setForeground(Color.BLUE);
pesquisar.setFont(new Font("Linux libertine G", Font.BOLD, 14));
add(pesquisar);
}
@Override
public void paint (Graphics g){
super.paint(g);
g.setColor(COR_FUNDO);
g.fillRect(0, 0, largura, altura);
}