
Metodo Static en JFrame
Publicado por Matias (5 intervenciones) el 22/10/2016 05:20:03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public static void menuataque(){
try{
JTextField x1=new JTextField();
JTextField y1=new JTextField();
texto2.setBounds(50, 450, 190, 30);
texto2.setText("Coordenada de Ataque:");
x1.setBounds(240, 450, 30, 30);
y1.setBounds(280, 450, 30, 30);
btnAtacar.setText("Atacar");
btnAtacar.setBounds(330, 520, 75, 30);
add(x1);
SwingUtilities.updateComponentTreeUI(x1);
add(y1);
SwingUtilities.updateComponentTreeUI(y1);
add(btnAtacar);
SwingUtilities.updateComponentTreeUI(btnAtacar);
btnAtacar.addActionListener(this);
}
catch(Exception e){
// System.out.println("Error al atacar");
}
}
El metodo esta creado en una clase JFrame, al querer crear este metodo static me sale un error con el metodo add por ser no estatico y error en el this de btnAtacar.addActionListener(this);
Error del add: Cannot make a static reference to the non-static method
Error del this: Cannot use this in a static context
Valora esta pregunta


0