import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class SwingEx1 {
public static void main(String[] args) {
final int s3,s4;
JFrame f=new JFrame();
JTextField f1=new JTextField();
JTextField f2=new JTextField();
JLabel l1=new JLabel("Number1:");
JLabel l2=new JLabel("Number2:");
JButton b1=new JButton("+");
JButton b2=new JButton("=");
l1.setBounds(10,50, 100, 10);
l2.setBounds(10,100, 100, 20);
f1.setBounds(80,50, 150, 40);
f2.setBounds(80,100, 150, 40);
b1.setBounds(80, 160, 60, 30);
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String s1=f1.getText();
s3=Integer.parseInt(s1);
String s2=f2.getText();
s4=Integer.parseInt(s2);
}
} );
b2.setBounds(150, 160, 60, 30);
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(f,s3+s4);
}
});
f.add(l1);
f.add(l2);
f.add(f1);
f.add (f2);
f.add(b1);
f.add(b2);
f.setSize(400, 400);
f.setLayout(null);
f.setVisible(true);
}
}
error at s3 and s4 final local variable s3 and s4 cannot be assigned in ecplise. i am beginner to swing can someone help.