Por que raios o programa não executa o try?? ALGUÉM PODE AJUDAR?
import java.awt.;
import java.awt.event.;
import java.awt.event.ActionListener;
public class ALPOO_EXEMP_02 extends Frame
{
Button B1;
Button B2;
TextField Tx1;
TextField Tx2;
Label L1, L2, L3;
public ALPOO_EXEMP_02()
{
setTitle("Uso de Componentes");
setResizable(false);
setSize(400,300);
setLocation(100,100);
setBackground(Color.LIGHT_GRAY);
setLayout(null);
L1 = new Label("Esta é uma classe visual!");
L1.setLocation(50,50);
L1.setSize(150,20);
L2 = new Label("RESULTADO:");
L2.setLocation(240,110);
L2.setSize(150,20);
L3 = new Label("");
L3.setLocation(260,140);
L3.setSize(150,20);
Tx1 = new TextField("Um número: ");
Tx1.setSize(150,20);
Tx1.setLocation(50,100);
Tx2 = new TextField("Outro número: ");
Tx2.setSize(150,20);
Tx2.setLocation(50,150);
B1 = new Button("Somar");
B1.setSize(60,20);
B1.setLocation(50,200);
B1.setBackground(Color.cyan);
B2 = new Button("Sair");
B2.setSize(60,20);
B2.setLocation(140,200);
B2.setBackground(Color.cyan);
// ADICIONA OS OBJETOS AO FRAME
add(L1);
add(L2);
add(L3);
add(B1);
add(B2);
add(Tx1);
add(Tx2);
ButtonHandler handler = new ButtonHandler();
B1.addActionListener(handler);
B2.addActionListener(handler);
}
public static void main(String[] args)
{
new ALPOO_EXEMP_02().setVisible(true);
}
//classe interna para ouvir e tratar o evento (botões)
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String Num1, Num2;
double Num3;
if (e.getActionCommand() == "Sair")
{
System.exit(0);
}
else
{
try
{
Num1 = Tx1.getText();
Num2 = Tx2.getText();
Num3 = Double.parseDouble(Num1) + Double.parseDouble(Num2);
L3.setText(Double.toString(Num3));
}
catch (NumberFormatException e2)
{
System.out.println("Não é possível realizar a soma!");
}
}
}
}
}