Como iniciante estou recorrendo
novamente a lista ...
Quero fazer o seguinte: estou
usando awt, quero que dependendo do button pressionado imprima determinada
mensagem, usando somente um button não tive problemas, mas preciso
implementar controle de fluxo, o melhor que consegui foi isso que está ai
embaixo, agradeço antecipadamente a atenção.
import java.awt.*;
import java.awt.event.*; class Exer7 extends Frame implements ActionListener { String x; public void paint(Graphics
g)
{ if(x != null) g.drawString(x,100,100); } public void actionPerformed(ActionEvent
e)
{ if(e.getSource().equals(B)) { x = "Botão 1 pressionado"; } // O que devo fazer para funcionar ??? if(e.getSource().equals(C)) { x = "Botão 2 pressionado"; } repaint(); } public static void main (String
arg[])
{ Exer7 f = new Exer7(); Button B = new Button(); Button C = new Button(); f.setLayout(new FlowLayout()); f.add(B); f.add(C); B.addActionListener(f); C.addActionListener(f); f.setSize(300,300); f.show(); } } - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
- Re: [java-list] Aprendendo a lidar com eventos no awt Roberto A. Metz