Aplicação de Iniciante

1 resposta
G

Galera, fiz uma aplicação pra tentar aprender java, mas quando rodo os eventos não acontecem. vejam:

import java.util.*;
import java.awt.*;

public class  Simple extends Frame {
	Button botao1, botao2;
	Label texto1;
	public Simple()
	{
		//super("GUJ - JList");
		botao1 = new Button();
		add(botao1);
		botao1.setLabel("botao1");
		botao2 = new Button();
		add(botao2);
		botao2.setLabel("botao2");
		texto1 = new Label();
		add(texto1);
		texto1.setText("Nada até agora");
		
		pack();
        setVisible(true); 
	}
	public boolean handleEvent (Event e)
	{
		if(e.id == Event.ACTION_EVENT)
		{
			if(e.target == botao1)
			{
				texto1.setText("Vc apertou o botao1");
				return true;
			}
			if(e.target == botao2)
			{
				texto1.setText("Vc apertou o botao2");
				return true;
			}
		}
		if(e.id == Event.MOUSE_MOVE)
		{
			texto1.setText("Aperte um botao");
			return true;
		}
		return false;
	}
	
	public static void main(String[] args) 
	{
		   
		Simple s = new Simple();
				
	}
}

o que tenho que mudar?

1 Resposta

danieldestro

Voce não registrou os eventos (listener) nos botões.

Criado 15 de julho de 2004
Ultima resposta 15 de jul. de 2004
Respostas 1
Participantes 2