Ver Mensaje Individual
  #4 (permalink)  
Antiguo 11/03/2013, 20:33
argume
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Como modificar componentes de un JFrame desde otro??

Cita:
Iniciado por alvaroLima42 Ver Mensaje
tomando un poco de teoria del concepto de chuidiang mas lo planteado lo hice asi
en el primer formulario iria algo asi
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
*
* @author root
*/
public class framea extends JFrame{
private JButton a,b;
metodos metodos;
public framea(){
super("Formulario 1");
JPanel panel=new JPanel();
metodos=new metodos();
a=new JButton("llamar Formulario 2");
a.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

new frameb(new JButton("boton"));

}
});
//valor=objetos{imagenes,textos,dimensiones,etc}
b=new JButton("cambiar valor de boton de Formulario 2");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
metodos.b();

}});
panel.add(a);
panel.add(b);
getContentPane().add(panel);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//getContentPane().add(a);

//getContentPane(this);
setVisible(true);
setSize(400, 200);
}
public static void main(String[] arg){
new framea();
}
}


en el segundo formulario seria como lo siguiente

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
*
* @author root
*/
public class frameb extends JFrame{
metodos metodos;
static JButton b;
public frameb(){

}
public frameb(JButton aux){
super("Formulario 2");
metodos=new metodos();
JPanel panel=new JPanel();
b=aux;
//valor={objetos,textos,clases,etc}
b.setText("aki va valor original");
b.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

metodos.a();
}
});
panel.add(b);
getContentPane().add(panel);
setSize(400, 300);
setVisible(true);
}
}


luego en la clase este codigo

import javax.swing.Icon;
import javax.swing.JButton;

/**
*
* @author root
*/
public class metodos {
frameb frameb=new frameb();
public metodos(){
}


public void a(){

}
public void b(){

frameb.b.setText("CAMBIADO EN METODO DESDE UNA CLASE");

// aux.setText("evento ejecutado desde framea");

}
}

Suerte
alvaroLima42....


segun me doy cuenta, el constructor del segundo JFrame debe recibir como parametro un JButton, cierto???

muchas gracias..!!