+ 1

How can i fix this?

package prueba2.pkg1; import javax.swing.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /** * * @author msigl */ public class Prueba21 { private int X; private int Y; private String name; public class Pestañas extends JFrame{ public Pestañas(){ super("new windows"); setLayout(null); setSize(1920,1080); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } public class Botones extends JButton { public Botones(int X,int Y, String name ){ super(name); setLayout(null); setBounds(X,Y,100,30); setVisible(true); } } /** * {} */ public static void main(String[] args) { int X = 0; /* i want to use the local variable X here but it says that it have to be final, but it woundn't work for this program, what can i do? */ ActionListener out1; out1 = new ActionListener(){ public void actionPerformed(ActionEvent e){ X = 10; } }; Prueba21 pr = new Prueba21(); Pestañas W1 = pr.new Pestañas(); Botones B1 = pr.new Botones(X,250,"start"); /* here i use that variable */ Botones B2 = pr.new Botones(400,250,"end"); W1.setVisible(true); W1.add(B1); W1.add(B2); } }

5th Apr 2020, 5:05 PM
jared mijail
jared mijail - avatar
1 Respuesta
0
Remove the int from int X = 0; private int X; -> already declared So you only need to assign a value to it. X = 0;
6th Apr 2020, 12:08 PM
Denise Roßberg
Denise Roßberg - avatar