Java - boton

 
Vista:
sin imagen de perfil

boton

Publicado por undertaker (61 intervenciones) el 10/04/2014 08:49:48
Buenas haber si me ayudan
Tengo dos frame uno de ellos con boton

frame 1 y frame2( con boton)

Lo que quiero que al cargar el frame1 en el frame 2 cuando lo abra se bloque el boton

He probado desde el frame1

Frame2 f = new Frame2();
f.boton1.setEnabled(false);

pero por más que intento no se bloquea desde el frame1


pd: el boton esta publico y estatico
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

boton

Publicado por Mario (26 intervenciones) el 21/04/2014 20:39:07
Me funcionó sin problema:

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
30
31
32
33
34
35
import javax.swing.*;
import java.awt.event.*;
public class PruebaFrames extends JFrame {
	public static JButton boton = new JButton("Botón");
	private PruebaFrames() {
		setTitle("PruebaFrames");
		setBounds(100, 100, 200, 200);
		getContentPane().add(boton);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
 
		boton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent evetn) {
				Frame2 f2 = new Frame2();
				f2.setVisible(true);
			}
		});
	}
	public static void main(String args[]) {
		PruebaFrames pf = new PruebaFrames();
		pf.setVisible(true);
	}
}
 
class Frame2 extends JFrame {
	public Frame2 () {
		setTitle("SegundoFrame");
		setBounds(200, 200, 100, 100);
		PruebaFrames.boton.setEnabled(false);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				PruebaFrames.boton.setEnabled(true);
			}
		});
	}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar