Programación General > Java

 Problema En Manejo De Varios Jframe

<< < (2/2)

darkness_twilight:
Pucha, gracias por las respuestas, pero aun no logro realizar la comunicacion entre frame( parece k soy medio burro  :blink: ), si pudieran colocar un codigo ejemplo de comunicacion entre clases ( da lo mismo si no extienden JFrame ) se los agredeceria mucho. Nuevamente espero k me puedan ayudar.  :(

jupezoa:
hola: soy nuevo  en esto pero tengo una solucion.

 private class ManejadorBoton implements ActionListener
  {
    public void actionPerformed( ActionEvent evento )
    {
      if ( evento.getSource() == btnVolver )
      {
                              setVisible( false );

    *************         MenuPrincipal frame = new MenuPrincipal();
    ********************    frame.setVisible( true );
                             
                       }
    }
  }

agrega estas lineas (*) y alomejor se soluciona tu problema(enJFrameIngreso)
espero q te sirva.xao

jupezoa:
sorry por lo atrasao :P

silverfox:
Aquí te doy mi opción: Los botones que aparecen hacen aparecer y desaparecer la otra ventana. Espero que te sirva como ejemplo.



--- Código: Text ---//Archivo Test_Java1. Primer Frame import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import javax.swing.*; public class Test_Java1 extends JFrame {   JButton btnTest1= null;   JFrame otro_frame= null;   public Test_Java1() {    this.btnTest1= new JButton(&#34;Boton1&#34;);        this.btnTest1.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {            otro_frame.setVisible(!otro_frame.isVisible());      }    });            this.getContentPane().add(this.btnTest1);    this.setBounds(0,0,100,100);    this.setVisible(true);          }    public void setComunicacionConFrame(JFrame otro_frame){    this.otro_frame= otro_frame;  }    public static void main (String args[]){    Test_Java1 frame1= new Test_Java1();    Test_Java2 frame2= new Test_Java2();    frame1.setComunicacionConFrame((JFrame) frame2);    frame2.setComunicacionConFrame((JFrame) frame1);  } } 


--- Código: Text ---//Archivo Test_Java2. Segundo Frame import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import javax.swing.*; public class Test_Java2 extends JFrame {   JButton btnTest2= null;   JFrame otro_frame= null;   public Test_Java2() {    this.btnTest2= new JButton(&#34;Boton2&#34;);        this.btnTest2.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {            otro_frame.setVisible(!otro_frame.isVisible());      }    });            this.getContentPane().add(this.btnTest2);    this.setBounds(0,110,100,100);    this.setVisible(true);          }    public void setComunicacionConFrame(JFrame otro_frame){    this.otro_frame= otro_frame;  }  } 
Espero que te sirva.


Edit: jupezoa... tu solución tiene la pega de tener que reconstruir el frame principal cada vez, además, de llamar a un tipo de Frame específico, por lo que no es portable. Si te fijas, quiere hacerlo visible de nuevo, lo que significa que tiene que tener el Frame ya construido.

Un saludo.



Silverfox

Navegación

[0] Índice de Mensajes

[*] Página Anterior

Ir a la versión completa