import javax.swing.*;
import java.awt.GridLayout;
import java.awt.event.*;
import java.text.*;
public class TFE extends JFrame implements ActionListener
{
public TFE()
{
str txtfNum1,txtfNum2,lblAnswer;
setLayout(new GridLayout(3,2,5,5));
add(new JLabel("First Number:"));
add(txtfNum1);
add(new JTextField(10));
add(new JLabel("Second Number:"));
add(txtfNum2);
add(new JTextField(10));
add(new JLabel("Total Summation:"));
add(lblAnswer);
txtfNum1.addActionListener(this);
txtfNum2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String str;
int val1,val2,total;
str=txtfNum1.getText();
if(str.equals(""))
val1=0;
else
val1=Integer.parseInt(str);
str=txtfNum2.getText();
if(str.equals(""))
val2=0;
else
val2=Integer.parseInt(str);
total=val1+val2;
lblAnswer.setText(""+total);
}
public static void main(String[]args){
TFE frame=new TFE();
frame.setTitle("TextField Event");
frame.setSize(300,350);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
i am confused with the use of parsing...please help me to correct the program...i am new in java...
the errors generated are
--------------------Configuration: <Default>--------------------
C:\Documents and Settings\Administrator\Desktop\TFE.java:14: cannot find symbol
symbol : class str
location: class TFE
str txtfNum1,txtfNum2,lblAnswer;
^
C:\Documents and Settings\Administrator\Desktop\TFE.java:33: cannot find symbol
symbol : variable txtfNum1
location: class TFE
str=txtfNum1.getText();
^
C:\Documents and Settings\Administrator\Desktop\TFE.java:39: cannot find symbol
symbol : variable txtfNum2
location: class TFE
str=txtfNum2.getText();
^
C:\Documents and Settings\Administrator\Desktop\TFE.java:46: cannot find symbol
symbol : variable lblAnswer
location: class TFE
lblAnswer.setText(""+total);
^
4 errors
Process completed.