Desabilitar janela anterior enquanto janela x estiver sendo utilizando no swing

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */

/*

  • jFprincipal.java
  • Created on 01/09/2011, 20:03:45
    */
    package projetofunasa.visual;

/**
*

  • @author rafaelfq
    */
    public class jFprincipal extends javax.swing.JFrame {

    /** Creates new form jFprincipal */
    public jFprincipal() {
    initComponents();
    }

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      jPanel1 = new javax.swing.JPanel();
      jBcriarOS = new javax.swing.JButton();
      jBeditarOS = new javax.swing.JButton();
      jMenuBar1 = new javax.swing.JMenuBar();
      jMenuOpcoes = new javax.swing.JMenu();
      jMcriaOS = new javax.swing.JMenuItem();
      jMeditaos = new javax.swing.JMenuItem();
      jMsair = new javax.swing.JMenuItem();
      JMenuAdministrador = new javax.swing.JMenu();
      jMopcoesadm = new javax.swing.JMenuItem();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle(“Sistema de Ordem de Serviços - INFO FUNASA”);

      jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(“OPÇÔES”));

      jBcriarOS.setText(“CRIAR OS”);
      jBcriarOS.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jBcriarOSActionPerformed(evt);
      }
      });

      jBeditarOS.setText(“EDITAR OS”);

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jBcriarOS, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(jBeditarOS, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBcriarOS, jBeditarOS});

      jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jBcriarOS, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jBeditarOS, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      jMenuOpcoes.setText(“Opções”);

      jMcriaOS.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetofunasa/visual/icon.png"))); // NOI18N
      jMcriaOS.setText(“CRIAR ORDEM DE SERVIÇO”);
      jMcriaOS.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jMcriaOSActionPerformed(evt);
      }
      });
      jMenuOpcoes.add(jMcriaOS);

      jMeditaos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetofunasa/visual/ICON2.PNG"))); // NOI18N
      jMeditaos.setText(“EDITAR ORDEM DE SERVIÇO”);
      jMenuOpcoes.add(jMeditaos);

      jMsair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetofunasa/visual/exit.png"))); // NOI18N
      jMsair.setText(“SAIR”);
      jMenuOpcoes.add(jMsair);

      jMenuBar1.add(jMenuOpcoes);

      JMenuAdministrador.setText(“Administrador”);

      jMopcoesadm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projetofunasa/visual/ferramentas.png"))); // NOI18N
      jMopcoesadm.setText(“OPÇÕES”);
      JMenuAdministrador.add(jMopcoesadm);

      jMenuBar1.add(JMenuAdministrador);

      setJMenuBar(jMenuBar1);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      pack();
      }//

    private void jMcriaOSActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void jBcriarOSActionPerformed(java.awt.event.ActionEvent evt) {
    jFcriaos criaOS = new jFcriaos();
    criaOS.setVisible(true);
    }

    /**

    • @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {

       public void run() {
           new jFprincipal().setVisible(true);
       }
      

      });
      }
      // Variables declaration - do not modify
      private javax.swing.JMenu JMenuAdministrador;
      private javax.swing.JButton jBcriarOS;
      private javax.swing.JButton jBeditarOS;
      private javax.swing.JMenuItem jMcriaOS;
      private javax.swing.JMenuItem jMeditaos;
      private javax.swing.JMenuBar jMenuBar1;
      private javax.swing.JMenu jMenuOpcoes;
      private javax.swing.JMenuItem jMopcoesadm;
      private javax.swing.JMenuItem jMsair;
      private javax.swing.JPanel jPanel1;
      // End of variables declaration
      }
      [/code]

outro frame…

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */

/*

  • jFcriaos.java
  • Created on 02/09/2011, 17:15:58
    */
    package projetofunasa.visual;

/**
*

  • @author rafaelfq
    */
    public class jFcriaos extends javax.swing.JFrame {

    /** Creates new form jFcriaos */
    public jFcriaos() {
    initComponents();
    }

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle(“ASSISTENTE DE CRIAÇÃO”);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 400, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 300, Short.MAX_VALUE)
      );

      pack();
      }//

    /**

    • @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {

       public void run() {
           new jFcriaos().setVisible(true);
       }
      

      });
      }
      // Variables declaration - do not modify
      // End of variables declaration
      }
      [/code]

como seria??? :slight_smile:

pessoal esse e o meu primeiro projeto gui… logo se eu estiver fazendo merda me avisem…

pessoal eu tinha feito outro topico… exatamente igual a esse mas ele sumiu oO :shock:
desculpem se eu fiz alguma besteira rs

abs []'s

Não sei se fez besteira, não li o seu código.

Mas pelo assunto:

this.dispose(); na janela que voce quer fechar.

ou this.setVisible(false);

**atenção pra primeiro chamar alguma outra janela antes de fechar essa.

faeldix,
Se você quiser fechar e abrir a outra janela através de um JButton é só colocar como está abaixo
private void JButtonActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
new janelaQueVoceQuerAbrir().show();
}

Espero tenha podido ajudar.