Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
The final local variable s3 and s4 cannot be assigned, since it is defined in an enclosing type
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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!