Como fechar um JInternalFrame

4 respostas
D

tenho uma aplicação q esta utilizando o JInternalFrame, como faço p fechar esta tela.

4 Respostas

R

use o dispose…

H

ds311072:
tenho uma aplicação q esta utilizando o JInternalFrame, como faço p fechar esta tela.

Pô… Tambem estou com o mesmo problema ou não estou fazendo a coisa certa…
Quando coloco apenas a Internal, fecha resize e tudo mais… Quando coloco uns campinhos… Babau… Bica.

package comum.screen;

import comum.service.utilitarios.UtilitariosValidacao;

import javax.swing.JInternalFrame;

import java.awt.event.<em>;

import java.awt.</em>;

import javax.swing.JOptionPane;

import javax.swing.event.InternalFrameAdapter;

import javax.swing.event.InternalFrameEvent;

public class InternaWindowsBasica extends JInternalFrame {

static int openFrameCount = 0;

static final int xOffset = 30, yOffset = 30;
public InternaWindowsBasica() {
    
    super(UtilitariosValidacao.parametroProperties("configuracoesAplicacao", "Aplicacao.Nome"),false,false,false,false );
    setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);   
    addInternalFrameListener(new InternalFrameAdapter(){   
    setOpaque(true);
}
public InternaWindowsBasica(String titulo) {
    super(titulo, false,true, false, false );
    setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);  
    addInternalFrameListener(new InternalFrameAdapter(){   
    setOpaque(true);   
}

}

/*

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

package aplicacao.screen;

import comum.businessObject.ResultSetObject;

import comum.controle.AplicacaoControle;

import comum.entidade.Aplicacao;

import comum.screen.InternaWindowsBasica;

import comum.service.utilitarios.DateComboBox;

import comum.service.utilitarios.NumeroMaximoCaracteres;

import comum.service.utilitarios.UtilitariosValidacao;

import comum.valueobject.AplicacaoVO;

import java.awt.Component;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.sql.SQLException;

import java.text.ParseException;

import javax.swing.JTable;

import javax.swing.event.InternalFrameEvent;

import javax.swing.table.TableCellRenderer;

import javax.swing.table.TableColumn;

import java.util.Date;

import javax.swing.GroupLayout;

import javax.swing.GroupLayout.Alignment;

import javax.swing.JInternalFrame;

import javax.swing.JOptionPane;

import javax.swing.LayoutStyle.ComponentPlacement;

import javax.swing.ListSelectionModel;

import javax.swing.event.InternalFrameAdapter;

import static javax.swing.GroupLayout.Alignment.*;

/**
*

  • @author HORACIO JInternalFrame
    */
    public class AplicacaoScreen
    extends InternaWindowsBasica
    implements ActionListener {
    private ResultSetObject tabelaModelo;
    private javax.swing.JTable masterTable;
    JInternalFrame displayWindows;
    // Composição dos Botões
    private javax.swing.JButton jBtnApagar;
    private javax.swing.JButton jBtnNovo;
    private javax.swing.JButton jBtnRefresh;
    private javax.swing.JButton jBtnSalvar;
    private javax.swing.JButton jBtnCancelar;
    // Composição dos Labels a serem criados
    private javax.swing.JLabel jLblCodigo;
    private javax.swing.JLabel jLblCodigoAplicacao;
    private javax.swing.JLabel jLblDescricao;
    private javax.swing.JLabel jLblInicioVigencia;
    private javax.swing.JLabel jLblTerminoVigencia;
    // Composição dos Paineis
    private javax.swing.JPanel jPanelButao;
    private javax.swing.JPanel jPanelDados;
    private javax.swing.JScrollPane jScpTabela;
private javax.swing.JTextField       jTxtCodigo;

private javax.swing.JTextField       jTxtDescricao;

private DateComboBox                 jDateComBoxInicioVigencia;

private DateComboBox                 jDateComBoxTerminoVigencia;
private GroupLayout                  jPanelButaoLayout;

private GroupLayout                  jPanelDadosLayout;

private GroupLayout                  displayTelalayout;
public AplicacaoScreen() {

super(Aplicação);

setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);

initComponents();

}

private void initComponents() {

refreshTabela();

masterTable.addMouseListener(new MouseAdapter() {

<a class="mention" href="/u/override">@Override</a>

public void mouseClicked(MouseEvent e) {

if (e.getClickCount() == 2) {

JTable target = (JTable)e.getSource();

int row = target.getSelectedRow();

int column = target.getSelectedColumn();

preencheCamposDoFormulario (row);

alteraStatusButao(“Novo”);

}

}

}

);

jScpTabela  = new javax.swing.JScrollPane(masterTable);

jScpTabela.setViewportView(masterTable);

add(jScpTabela );

jPanelButao                = new javax.swing.JPanel();

jBtnNovo                   = new javax.swing.JButton();

jBtnApagar                 = new javax.swing.JButton();

jBtnCancelar               = new javax.swing.JButton();

jBtnSalvar                 = new javax.swing.JButton();

jBtnRefresh                = new javax.swing.JButton();

// Fim Butões

jPanelDados                = new javax.swing.JPanel();

jLblCodigo                 = new javax.swing.JLabel();

jTxtCodigo                 = new javax.swing.JTextField(5);

jLblDescricao              = new javax.swing.JLabel();

jTxtDescricao              = new javax.swing.JTextField(50);

jLblInicioVigencia         = new javax.swing.JLabel();

jDateComBoxInicioVigencia  = new DateComboBox(new Date());

jDateComBoxTerminoVigencia = new DateComboBox(new Date());

jLblTerminoVigencia        = new javax.swing.JLabel();

jLblCodigo.setText(“Código:”);

jTxtCodigo.setToolTipText(UtilitariosValidacao.parametroProperties(“configuracoesMensagens”,“Aplicacao.Codigo”));

jTxtCodigo.setDocument(new NumeroMaximoCaracteres(5));

<a href="//jTxtCodigo.addFocusListener">//jTxtCodigo.addFocusListener</a>(new validaCodigo());

jLblDescricao.setText(Descrição:);

jTxtDescricao.setToolTipText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.Descricao));

jTxtDescricao.setDocument(new NumeroMaximoCaracteres(50));

jLblInicioVigencia.setText(Início Vigencia:);

jDateComBoxInicioVigencia.setToolTipText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.InicioVigencia));

jLblTerminoVigencia.setText(Término Vigencia:);

jDateComBoxTerminoVigencia.setToolTipText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.TerminoVigencia));

criaLayoutCampos();

FormListener formListener = new FormListener();

jBtnNovo.setText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.BtnNovo));

jBtnNovo.addActionListener(formListener);

jBtnApagar.setText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.BtnApagar));

jBtnApagar.addActionListener(formListener);

jBtnSalvar.setText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.BtnSalvar));

jBtnSalvar.addActionListener(formListener);

jBtnCancelar.setText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.BtnCancelar));

jBtnCancelar.addActionListener(formListener);

jBtnRefresh.setText(UtilitariosValidacao.parametroProperties(configuracoesMensagens,Aplicacao.BtnRefresh));

jBtnRefresh.addActionListener(formListener);

alteraStatusButao(Inicio);

criaLayoutButao();

unificaLayout();

pack();

}

public void actionPerformed(ActionEvent event) {

String command = event.getActionCommand();

}
private void criaLayoutButao () {

jPanelButaoLayout = new GroupLayout(jPanelButao);

jPanelButao.setLayout(jPanelButaoLayout);

jPanelButaoLayout.setHorizontalGroup(

jPanelButaoLayout.createParallelGroup(Alignment.CENTER)

.addGroup(jPanelButaoLayout.createSequentialGroup()

.addGap(130, 130, 130)

.addComponent(jBtnRefresh,100,100,100)

.addPreferredGap(ComponentPlacement.RELATED)

.addComponent(jBtnNovo,100,100,100)

.addPreferredGap(ComponentPlacement.RELATED)

.addComponent(jBtnApagar,100,100,100)

.addPreferredGap(ComponentPlacement.RELATED)

.addComponent(jBtnSalvar,100,100,100)

.addPreferredGap(ComponentPlacement.RELATED)

.addComponent(jBtnCancelar,100,100,100)

.addPreferredGap(ComponentPlacement.RELATED)

.addContainerGap(206, Short.MAX_VALUE)

)

);

jPanelButaoLayout.setVerticalGroup(

jPanelButaoLayout.createParallelGroup(Alignment.LEADING)

.addGroup(jPanelButaoLayout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanelButaoLayout.createParallelGroup(Alignment.LEADING)

.addComponent(jBtnRefresh , Alignment.CENTER)

.addComponent(jBtnNovo    , Alignment.CENTER)

.addComponent(jBtnApagar  , Alignment.CENTER)

.addComponent(jBtnSalvar  , Alignment.CENTER)

.addComponent(jBtnCancelar, Alignment.CENTER)

)

.addContainerGap(20, Short.MAX_VALUE)

)

);
}

private void criaLayoutCampos() {

jPanelDadosLayout = new GroupLayout(jPanelDados);

jPanelDados.setLayout(jPanelDadosLayout);

jPanelDadosLayout.setAutoCreateGaps(true);

jPanelDadosLayout.setAutoCreateContainerGaps(true);

jPanelDadosLayout.setHorizontalGroup(

jPanelDadosLayout.createParallelGroup(Alignment.LEADING)

.addGroup(jPanelDadosLayout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanelDadosLayout.createParallelGroup(Alignment.LEADING)

.addComponent(jLblCodigo   , Alignment.TRAILING)

.addComponent(jLblDescricao, Alignment.TRAILING)

.addComponent(jLblInicioVigencia, Alignment.TRAILING)

.addComponent(jLblTerminoVigencia, Alignment.TRAILING)

)

.addPreferredGap(ComponentPlacement.RELATED)

.addGroup(jPanelDadosLayout.createParallelGroup(Alignment.LEADING)

.addGroup(jPanelDadosLayout.createSequentialGroup()

.addGroup(jPanelDadosLayout.createParallelGroup(Alignment.LEADING)

.addComponent(jTxtCodigo   ,030,030,050)

.addComponent(jTxtDescricao,300,400,500)

.addComponent(jDateComBoxInicioVigencia,100,100,100)

.addComponent(jDateComBoxTerminoVigencia, 100,100,100)

)

)

)

.addContainerGap()

)

);

jPanelDadosLayout.setVerticalGroup(

jPanelDadosLayout.createParallelGroup(Alignment.LEADING)

.addGroup(jPanelDadosLayout.createSequentialGroup()

.addContainerGap()
.addGroup(jPanelDadosLayout.createParallelGroup(Alignment.BASELINE)
      .addComponent(jLblCodigo)
    .addComponent(jTxtCodigo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(ComponentPlacement.UNRELATED)

  .addGroup(jPanelDadosLayout.createParallelGroup(Alignment.BASELINE)
      .addComponent(jLblDescricao)
    .addComponent(jTxtDescricao, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
)
  .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
       .addComponent(jLblInicioVigencia)
      .addComponent(jDateComBoxInicioVigencia ))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLblTerminoVigencia)
      .addComponent(jDateComBoxTerminoVigencia))

.addPreferredGap(ComponentPlacement.UNRELATED)
)
);
}

private class FormListener implements java.awt.event.ActionListener {

FormListener() {}

public void actionPerformed(java.awt.event.ActionEvent evt) {

System.out.println("O Evento " + evt);

if (evt.getSource() == jBtnSalvar) {

salvarButtonActionPerformed(evt);

}

else if (evt.getSource() == jBtnNovo) {

novoButtonActionPerformed(evt);

}

else if (evt.getSource() == jBtnCancelar) {

cancelarButtonActionPerformed();

}

else if (evt.getSource() == jBtnApagar ) {

apagarButtonActionPerformed(evt);

}     else if (evt.getSource() == jBtnRefresh ) {

refreshButtonActionPerformed(evt);

}

}

}

private void unificaLayout() {

displayTelalayout = new GroupLayout(getContentPane());

getContentPane().setLayout(displayTelalayout);

displayTelalayout.setHorizontalGroup(

displayTelalayout.createParallelGroup(Alignment.LEADING)

.addComponent(jScpTabela, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)

.addComponent(jPanelButao,GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jPanelDados,GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

displayTelalayout.setVerticalGroup(

displayTelalayout.createParallelGroup(Alignment.LEADING)

.addGroup(displayTelalayout.createSequentialGroup()

.addGap(21, 21, 21)

.addComponent(jScpTabela, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.UNRELATED)

.addComponent(jPanelDados, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

.addPreferredGap(ComponentPlacement.RELATED, 31, Short.MAX_VALUE)

.addComponent(jPanelButao, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)

)

);
}

private void alteraStatusButao(String opcao) {

if (opcao.equals(Novo)) {

jBtnApagar.setEnabled(true);

jBtnNovo.setEnabled(false);

jBtnRefresh.setEnabled(false);

jBtnSalvar.setEnabled(true);

jBtnCancelar.setEnabled(true);

}

else if (opcao.equals(Apagar)) {

jBtnApagar.setEnabled(true);

jBtnNovo.setEnabled(false);

jBtnRefresh.setEnabled(false);

jBtnSalvar.setEnabled(true);

jBtnCancelar.setEnabled(true);
}   else if (opcao.equals("Inicio")) {
    jBtnApagar.setEnabled(false);
    jBtnNovo.setEnabled(true);
    jBtnRefresh.setEnabled(true);
    jBtnSalvar.setEnabled(false);
    jBtnCancelar.setEnabled(false);
}
}

private void tamanhoColunas(JTable table) {

ResultSetObject            model = (ResultSetObject)table.getModel();

TableColumn               column = null;

int[]              longValues = {67,900,150,150};

Component                   comp = null;

int headerWidth                  = 0;

int cellWidth                    = 0;

TableCellRenderer headerRenderer =  table.getTableHeader().getDefaultRenderer();

for (int i = 0; i < masterTable.getColumnCount(); i++) {

column      = table.getColumnModel().getColumn(i);

comp        = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(),false, false, 0, 0);

headerWidth = comp.getPreferredSize().width;

comp        = table.getDefaultRenderer(model.getColumnClass(i)).getTableCellRendererComponent(table, longValues[i],false, false, 0, i);

cellWidth   = comp.getPreferredSize().width;

column.setPreferredWidth(longValues[i]);

column.setMaxWidth(longValues[i]);

column.setMinWidth(longValues[i]);

}

}
private void inicializaCamposDoFormulario () {

jTxtCodigo.setText("");

jTxtDescricao.setText("");

jDateComBoxInicioVigencia.setDate(new Date());

jDateComBoxTerminoVigencia.setDate(new Date());

}

private void preencheCamposDoFormulario (int selectedRow) {

jTxtCodigo.setText(masterTable.getModel().getValueAt (selectedRow, 0).toString());

jTxtDescricao.setText(masterTable.getModel().getValueAt (selectedRow, 1).toString());

String dInicioVigencia = “”;

try {

dInicioVigencia = masterTable.getModel().getValueAt (selectedRow, 2).toString();

} catch (Exception e) {}
if (dInicioVigencia.equals("")) {
    dInicioVigencia = UtilitariosValidacao.parseDateToString(new Date(),"dd/MM/yyyy");
}
String dTerminoVigencia = "";
try {
    dTerminoVigencia = masterTable.getModel().getValueAt (selectedRow, 3).toString();
} catch (Exception e) {}
if (dTerminoVigencia.equals("")) {
    dTerminoVigencia = UtilitariosValidacao.parseDateToString(new Date(),"dd/MM/yyyy");
}
try {
    jDateComBoxInicioVigencia.setDate(UtilitariosValidacao.parseStringToDate(dInicioVigencia, "dd/MM/yyyy"));
    jDateComBoxTerminoVigencia.setDate(UtilitariosValidacao.parseStringToDate(dInicioVigencia, "dd/MM/yyyy"));
} catch (ParseException e) {
    e.printStackTrace();
}
}

private void cancelarButtonActionPerformed() {

inicializaCamposDoFormulario ();

alteraStatusButao(Inicio);

}

private void salvarButtonActionPerformed(java.awt.event.ActionEvent evt)  {

if ( jTxtDescricao.getText().equals("") ) {

JOptionPane.showMessageDialog( null, UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.TodosCamposObrigatorios), UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.Informacao), JOptionPane.INFORMATION_MESSAGE );

}

else {

AplicacaoVO dado = new AplicacaoVO();

dado             = preencheObjectoComCampos(dado);

try {

if ( jTxtCodigo.getText().equals("")) {

AplicacaoControle.inserir(dado);

} else {

System.out.println(" CARAMBA Codigo " + dado.getCodigo());

AplicacaoControle.alterar(dado);

}

inicializaCamposDoFormulario ();

refreshTabela();

jScpTabela.setViewportView(masterTable);

} catch (SQLException e) {

JOptionPane.showMessageDialog( null, UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.ProblemaInsercao), UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.Informacao), JOptionPane.INFORMATION_MESSAGE );

}

alteraStatusButao(Inicio);

}

}

private void apagarButtonActionPerformed(java.awt.event.ActionEvent evt) {

if ( jTxtCodigo.getText().equals("") ) {

JOptionPane.showMessageDialog( null, UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.TodosCamposObrigatorios), UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.Informacao), JOptionPane.INFORMATION_MESSAGE );

} else {

int codigo = Integer.parseInt(jTxtCodigo.getText());

try {

AplicacaoControle.excluir(codigo);

} catch (SQLException e) {

JOptionPane.showMessageDialog( null, UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.ProblemaInsercao), UtilitariosValidacao.parametroProperties(configuracoesErros,Erro.Informacao), JOptionPane.INFORMATION_MESSAGE );

}

}

}

private void novoButtonActionPerformed(java.awt.event.ActionEvent evt) {

jTxtCodigo.setEnabled(false);

jTxtDescricao.setFocusable(true);

alteraStatusButao(Novo);

}

private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {

refreshTabela ();

jScpTabela.setViewportView(masterTable);

}

private AplicacaoVO preencheObjectoComCampos(AplicacaoVO dado) {

int    codigo    = 0;

if (! jTxtCodigo.getText().equals("")) {

codigo = Integer.parseInt(jTxtCodigo.getText());

System.out.println("Preenchi o campo com " + codigo);

}

String shortName = jTxtDescricao.getText();

Date   startDate = jDateComBoxInicioVigencia.getDate();

Date   endDate   = jDateComBoxTerminoVigencia.getDate();

dado.setCodigo(codigo);

dado.setShortName(shortName);

dado.setStartDate(startDate);

dado.setEndDate(endDate);

return dado;

}

private void refreshTabela (){

tabelaModelo = Aplicacao.geracaoTabela(SELECT application_id as CODIGO , application_short_name AS DESCRICAO, to_char(start_date,dd/mm/yyyy) Inicio, to_char(end_date,dd/mm/yyyy) Termino   FROM aucdaplicacao ORDER BY 1);

masterTable  = new JTable(tabelaModelo);

masterTable.setPreferredScrollableViewportSize(new Dimension(500, 70));

masterTable.setFillsViewportHeight(true);

masterTable.setAutoCreateRowSorter(true);

masterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

tamanhoColunas(masterTable);

}

public static void main(String[] args) {

AplicacaoScreen  frame = new AplicacaoScreen();
frame.setVisible(true);

try {

frame.setSelected(true);

} catch (java.beans.PropertyVetoException evento) {}

frame.show();

}
public void internalFrameOpened(InternalFrameEvent e) {
    System.out.println("internalFrameClosing");
}

public void internalFrameClosing(InternalFrameEvent e) {
    System.out.println("internalFrameClosing");
}

public void internalFrameClosed(InternalFrameEvent e) {
    System.out.println("internalFrameClosed");
}

public void internalFrameIconified(InternalFrameEvent e) {
    System.out.println("internalFrameIconified");
}

public void internalFrameDeiconified(InternalFrameEvent e) {
    System.out.println("internalFrameDeiconified");
}

public void internalFrameActivated(InternalFrameEvent e) {
   System.out.println("internalFrameActivated");
}

public void internalFrameDeactivated(InternalFrameEvent e) {
   System.out.println("internalFrameDeactivated");
}

}

JamesBond

só usar o dispose() :wink:

D

Ok amigos ja esta resolvido … valeu pela ajuda

Criado 5 de março de 2008
Ultima resposta 7 de mar. de 2008
Respostas 4
Participantes 4