-2
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.

Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
  • 2
    Welcome to Stackoverflow. You'll find that a lot of common questions have already been answered: http://stackoverflow.com/q/21485590/940217 Doing a quick search might save you some time next time around. – Kyle Falconer Apr 29 '17 at 02:44

1 Answers1

0

The message is pretty clear: you declared s3 and s4 to be final, then later tried to change their values. If you need to do the latter, don't do the former.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101