Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

306
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda