Eventos no Eclipse

2 respostas
J

Comecei a aprender java há pouco tempo. Iniciei no NetBeans.
Agora estou usando a IDE Eclipse, mas estou com um problema. Minhas aplicações gráficas não executam nenhum evento.
Por exemplo, neste código:

import javax.swing.JFrame; 
import javax.swing.JButton; 
import javax.swing.JOptionPane; 
/* 
 * Created on 18/05/2005 
 * 
 * TODO To change the template for this generated file go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 

/** 
 * @author Administrador 
 * 
 * TODO To change the template for this generated type comment go to 
 * Window - Preferences - Java - Code Style - Code Templates 
 */ 
public class TesteVisualClass extends JFrame { 

   private javax.swing.JPanel jContentPane = null; 
   private JButton jButton = null; 
   /** 
    * This method initializes jButton    
    *     
    * @return javax.swing.JButton    
    */    
   private JButton getJButton() { 
      if (jButton == null) { 
         jButton = new JButton(); 
         jButton.setBounds(71, 40, 94, 34); 
         jButton.addActionListener(new java.awt.event.ActionListener() { 
            public void actionPerformed(java.awt.event.ActionEvent e) {    
               System.out.println("actionPerformed()"); 
               // TODO Auto-generated Event stub actionPerformed() 
               JOptionPane.showMessageDialog(null,"Apertei"); 
            } 
         }); 
      } 
      return jButton; 
   } 
    public static void main(String[] args) { 
   } 
   /** 
    * This is the default constructor 
    */ 
   public TesteVisualClass() { 
      super(); 
      initialize(); 
   } 
   /** 
    * This method initializes this 
    * 
    * @return void 
    */ 
   private void initialize() { 
      this.setSize(300,200); 
      this.setContentPane(getJContentPane()); 
      this.setTitle("Título"); 
      this.setVisible(true); 
   } 
   /** 
    * This method initializes jContentPane 
    * 
    * @return javax.swing.JPanel 
    */ 
   private javax.swing.JPanel getJContentPane() { 
      if(jContentPane == null) { 
         jContentPane = new javax.swing.JPanel(); 
         jContentPane.setLayout(null); 
         jContentPane.add(getJButton(), null); 
      } 
      return jContentPane; 
   } 
}

Ao apertar no botão “JButton”, deveria me retornar uma mensagem, porém isso não acontece. O evento WindowClosing tb naum funciona. O q pode estar errado?

Grato

Julio Romano

2 Respostas

Ricardo_Neves

Cara nao o bicho em java, mas pelo que vi voce copiou este codigo do netbeans neh, percebi pelos comentarios. Tente declarar todos os pacotes da classe Swing

import javax.swing.*;

se funcionar favor me avise

C

Cara, num sei se o Jforum jah corrigi código, mas compilei aki e o botão abre um messagedialog. :lol:

Criado 18 de maio de 2005
Ultima resposta 19 de mai. de 2005
Respostas 2
Participantes 3