Bom dia galera !!!
Estou utilizando o NetBeans e faço a criação do JPanel. E de teste faço a criação de alguns JButton, porém o método de action performed não funciona. Depois de compilado e com a visualização da GUI o botão não funciona no click.
Um exemplo de linha de código se um dos botões de teste.
private void botaoActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Olá Mundo");
}
Onde você está chamando o método botaoActionPerformed
?
Posta o código completo da tela.
Código gerado pela IDE do Netbeans:
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package apsj;
import javax.swing.JOptionPane;
/**
*
-
@author AlucardHell
*/
public class Painel extends javax.swing.JPanel {
/**
- Creates new form Painel
*/
public Painel() {
initComponents();
}
/**
-
This method is called from within the constructor to initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is always
-
regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
textoarea = new javax.swing.JTextArea();
botao = new javax.swing.JButton();
textoarea.setColumns(20);
textoarea.setFont(new java.awt.Font(“Serif”, 0, 18)); // NOI18N
textoarea.setRows(5);
textoarea.setToolTipText("");
jScrollPane1.setViewportView(textoarea);
botao.setText(“jButton1”);
botao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
botaoActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(115, 115, 115)
.addComponent(botao, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 588, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(51, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(51, 51, 51)
.addComponent(botao, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(52, Short.MAX_VALUE))
);
}//
private void botaoActionPerformed(java.awt.event.ActionEvent evt) {
JOptionPane.showMessageDialog(null, "Olá Mundo");
}
// Variables declaration - do not modify
private javax.swing.JButton botao;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea textoarea;
// End of variables declaration
}