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

304
Views
La variable local final s3 y s4 no se puede asignar, ya que está definida en un tipo adjunto
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 en s3 y s4 La variable local final s3 y s4 no se puede asignar en ecplise. Soy principiante en swing, ¿alguien puede ayudarme?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El mensaje es bastante claro: declaró que s3 y s4 eran final y luego intentó cambiar sus valores. Si necesitas hacer lo último, no hagas lo primero.

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!