Probremas com Janela

3 respostas
P

Quando eu clico em ARQUIVO/CAD1 ele abre a tela CAD1 mais depois que eu fecho e tento abrir novamente a tela nao aparece alguem sabe pq ?

Desde ja muito grato :slight_smile:


package main;

import javax.swing.*;

import java.awt.event.*;
import main.cCAD1;

/**

  • @author Administrador

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments
    */
    public class cPRINCIPAL extends JFrame {

    public cPRINCIPAL () {

    JMenuBar bar = new JMenuBar();
     JMenu mnARQUIVO = new JMenu("Arquivo");
     JMenuItem miCAD1 = new JMenuItem("Cad1");
     JMenuItem miCAD2 = new JMenuItem("Cad2");
     JMenuItem miSAIR = new JMenuItem("Sair");
     
     
     mnARQUIVO.add(miCAD1);
     mnARQUIVO.add(miCAD2);
     mnARQUIVO.addSeparator();
     mnARQUIVO.add(miSAIR);
     bar.add(mnARQUIVO);
    
     setJMenuBar( bar );
    
    
     miCAD1.addActionListener(new ActionListener() {
     	public void actionPerformed( ActionEvent event) {
     		new cCAD1( );
     		getContentPane().add( cCAD1.pnCAD1 );
     	}
     }); 
    
     //setState(); 
     setVisible( true );
    

    }

    public static void main(String[] args) {
    cPRINCIPAL application = new cPRINCIPAL();

    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    

    }
    }


import java.awt.Container;

import javax.swing.JDesktopPane;

import javax.swing.JInternalFrame;
/**

  • @author Administrador

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments
    */
    public class cCAD1 {

    public static JDesktopPane pnCAD1;
    public static JInternalFrame frame;

    public cCAD1 () {

    pnCAD1 = new JDesktopPane();
     
     frame = new JInternalFrame("Cadastro 1", true, true, true, true );
     Container container = frame.getContentPane();
     frame.pack();
     frame.setVisible( true );
     pnCAD1.add( frame );
    

    }

}

3 Respostas

P

ola,

vc tentou colocar o JDesktopPane em cPrincipal,
em vez de ficar na classe cCAD1?

falow;

P

poderia me mostrar como fazer … sou iniciante to tentando fazer isso ja uns 2 dias to perdido perdido poderia me dar um exemplo ?

“pablodrumond”:
ola,

vc tentou colocar o JDesktopPane em cPrincipal,
em vez de ficar na classe cCAD1?

falow;

P

Ola,

tenta assim:

public class cPRINCIPAL extends JFrame { 
  public static JDesktopPane dp; 
  public cPRINCIPAL () {
  ...
  }

  miCAD1.addActionListener(new ActionListener() { 
  public void actionPerformed( ActionEvent event) { 
    dp.add(cCAD1);
  }
}

public class cCAD1 extends JInternalFrame { 
...
}

mais ou menos assim. entendeu?

falow;

Criado 4 de abril de 2005
Ultima resposta 5 de abr. de 2005
Respostas 3
Participantes 2