Senhores forenses,
Estou tentando fazer um exercício que é o seguinte: Tenho duas caixas de texto para a entrada de dois números e uma terceira caixa que vai mostrar a soma desses números (não editável). Simplesmente não estou ocnseguindo fazer… Segue o código:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class dados extends JFrame
{
JLabel L1,L2,L3;
JTextField T1,T2,T3;
JButton B1, B2;
public dados()
{
setTitle("Pegar dados");
setBounds(150,100,500,400);
setResizable(false);
L1 = new JLabel("Numero A");
L1.setBounds(10,10,60,30);
L2 = new JLabel("Numero B");
L2.setBounds(10,30,60,30);
L3 = new JLabel("A + B");
L3.setBounds(10,50,60,30);
T1 = new JTextField("");
T1.setBounds(75,10,40,20);
T2 = new JTextField("");
T2.setBounds(75,30,40,20);
T3 = new JTextField("");
T3.setBounds(75,50,40,20);
T3.setEnabled(false);
B1 = new JButton("Calcula");
B1.setBounds(10,80,80,20);
B2 = new JButton("Sair");
B2.setBounds(90,80,80,20);
getContentPane().setLayout(null);
getContentPane().add(L1);
getContentPane().add(L2);
getContentPane().add(L3);
getContentPane().add(T1);
getContentPane().add(T2);
getContentPane().add(T3);
getContentPane().add(B1);
getContentPane().add(B2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//addWindowListener(new FechandoJanela());
}
public class calcula() //L48
{
String A = T1.getText();
A = A.replace(',','.');
a = Double.parseDouble(A);
String B = T2.getText();
B = B.replace(',','.');
b = Double.parseDouble(B);
Double s = a+b;
T3.setText = s;
}
public static actionPerformed(ActionEvent e)
{
if (e.getSource()==B1)
{
dados.calcula();
}
else
{
JOptionPane.showMessagedialog(null,"Algo errado","Erro",-1);
return;
}
if (e.getSource)==B2)
{
System.exit(0);
}
}
public static void main (String arg[])
{
new dados().show();
}
}//L79
Quando tento compilar, ocorre o seguinte erro:
dados.java:48: ´{´ expected
public calcula()
…^
dados.java:79: ´}´ expected
}
…^
2 errors
P.S.: Estou usando o j2sdk 1.4.2_09 e o Notepad
Agradeço antecipadamente
