hola compañeros que tal tengo un problema con jdialog es que cuamdo doy guardar este no me permite llamar a mis objetos que tengo en una clase me da error si me podrian ayudar con esto haaaaaa Ho de no si me podrían decir como hago modales a los jinternal frame con todo les dejo el codigo
package proyectomdi2;
import javax.swing.*; import java.awt.*; import org.jdesktop.application.Action; import java.sql.*; import javax.swing.table.*;
/** * * @author jorge */ public class FrmListadoGrupo extends javax.swing.JInternalFrame {
DefaultTableModel myModel;
/** Creates new form FrmListadoGrupo */
public FrmListadoGrupo() {
super("Listado de Grupos",true,true,true,true); initComponents(); LlenarGrilla();
} private void LlenarGrilla() { myModel = new DefaultTableModel();
myModel.addColumn("Id"); myModel.addColumn("Codigo"); myModel.addColumn("Nombre");
ClsGrupo ObjGrupo=new ClsGrupo(); ResultSet rs=ObjGrupo.Listar(); try{
while(rs.next()) { Object[] Obj=new Object[3]; Obj[0]=rs.getInt(1); Obj[1]=rs.getString(2); Obj[2]=rs.getString(3); myModel.addRow(Obj);
} } catch(Exception ex) { String ex1=ex.getMessage(); String ex2=""; } Grd.setModel(myModel); //Ocultar una columna TableColumn Modelo=Grd.getColumnModel().getColumn(0);// o es la columa que quiero ocultar Modelo.setMaxWidth(0);// 0 es el tamaño de la columna no se oculta pero se hace muy delgada Modelo.setMinWidth(0);// 0 es el tamaño de la columna no se oculta pero se hace muy delgada Modelo.setPreferredWidth(0);// 0 es el tamaño de la columna no se oculta pero se hace muy delgada Grd.doLayout();//refrescar la Tabla //jScrollPane1.setViewportView(Grd);
} /** 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") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {
jToolBar1 = new javax.swing.JToolBar(); BtnNuevo = new javax.swing.JButton(); BtnModificar = new javax.swing.JButton(); BtnEliminar = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); Grd = new javax.swing.JTable();
jToolBar1.setRollover(true); jToolBar1.setName("jToolBar1"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(FrmListadoGrupo.class, this); BtnNuevo.setAction(actionMap.get("btnNuevoa")); // NOI18N BtnNuevo.setText("Nuevo"); BtnNuevo.setFocusable(false); BtnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); BtnNuevo.setName("BtnNuevo"); // NOI18N BtnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); BtnNuevo.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { BtnNuevoMouseClicked(evt); } }); jToolBar1.add(BtnNuevo);
BtnModificar.setText("Modificar"); BtnModificar.setFocusable(false); BtnModificar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); BtnModificar.setName("BtnModificar"); // NOI18N BtnModificar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); BtnModificar.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { BtnModificarMouseClicked(evt); } }); jToolBar1.add(BtnModificar);
BtnEliminar.setText("Eliminar"); BtnEliminar.setFocusable(false); BtnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); BtnEliminar.setName("BtnEliminar"); // NOI18N BtnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); BtnEliminar.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { BtnEliminarMouseClicked(evt); } }); jToolBar1.add(BtnEliminar);
jScrollPane1.setName("jScrollPane1"); // NOI18N
Grd.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); Grd.setName("Grd"); // NOI18N jScrollPane1.setViewportView(Grd);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 368, Short.MAX_VALUE) .addGap(19, 19, 19)) );
pack(); }// </editor-fold>
private void BtnNuevoMouseClicked(java.awt.event.MouseEvent evt) { FrmG2 Frm=new FrmG2(null, closable); Frm.Nuevo(); Grd.doLayout(); LlenarGrilla(); }
private void BtnEliminarMouseClicked(java.awt.event.MouseEvent evt) { String vidS=Grd.getValueAt(Grd.getSelectedRow(), 0).toString(); int vid=Integer.parseInt(vidS); ClsGrupo Frm1=new ClsGrupo(); Frm1.Eliminar(vid); FrmG2 Frm=new FrmG2(null, closable); Frm.show(); // TODO add your handling code here: }
private void BtnModificarMouseClicked(java.awt.event.MouseEvent evt) { String vidS=Grd.getValueAt(Grd.getSelectedRow(),0).toString(); int vid=Integer.parseInt(vidS); ClsGrupo Frm1=new ClsGrupo(); Frm1.Grabar(); FrmGrupo2 Frm=new FrmGrupo2(); Frm.show(); // TODO add your handling code here: }
// Variables declaration - do not modify private javax.swing.JButton BtnEliminar; private javax.swing.JButton BtnModificar; private javax.swing.JButton BtnNuevo; private javax.swing.JTable Grd; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JToolBar jToolBar1; // End of variables declaration
}
package proyectomdi2; import javax.swing.JOptionPane; /** * * @author user */ public class FrmG2 extends javax.swing.JDialog { private ClsGrupo ObjGrupo;
/** Creates new form FrmG2 */ public FrmG2(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); } private void VisualizaObj() { TxtCodigo.setText(ObjGrupo.Codigo); TxtNombre.setText(ObjGrupo.Nombre);
} public void Nuevo() { ObjGrupo=new ClsGrupo(); FrmG2 Frm1=new FrmG2(null, rootPaneCheckingEnabled); Frm1.setVisible(true); VisualizaObj();
} public void Modificar(int Id) { ObjGrupo=new ClsGrupo(); ObjGrupo.Recuperar(Id); VisualizaObj(); this.setVisible(true);
} public void Eliminar(int Id) { ObjGrupo=new ClsGrupo(); ObjGrupo.Recuperar(Id); int confirmado = JOptionPane.showConfirmDialog(this, "¿Lo confirmas?");
if (JOptionPane.OK_OPTION == confirmado) ObjGrupo.Eliminar(Id);
}
/** 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") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {
LblCodigo = new javax.swing.JLabel(); BtnGuardar = new javax.swing.JButton(); TxtCodigo = new javax.swing.JTextField(); LblNombre = new javax.swing.JLabel(); BtnCancelar = new javax.swing.JButton(); TxtNombre = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
LblCodigo.setText("Codigo"); LblCodigo.setName("LblCodigo"); // NOI18N
BtnGuardar.setText("Guardar"); BtnGuardar.setName("BtnGuardar"); // NOI18N BtnGuardar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BtnGuardarActionPerformed(evt); } });
TxtCodigo.setName("TxtCodigo"); // NOI18N TxtCodigo.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { TxtCodigoFocusLost(evt); } }); TxtCodigo.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { TxtCodigoPropertyChange(evt); } });
LblNombre.setText("Nombre"); LblNombre.setName("LblNombre"); // NOI18N
BtnCancelar.setText("Cancelar"); BtnCancelar.setName("BtnCancelar"); // NOI18N BtnCancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { BtnCancelarActionPerformed(evt); } });
TxtNombre.setName("TxtNombre"); // NOI18N TxtNombre.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { TxtNombreFocusLost(evt); } });
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) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(LblNombre) .addComponent(LblCodigo)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(TxtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(TxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addGap(43, 43, 43) .addComponent(BtnGuardar) .addGap(47, 47, 47) .addComponent(BtnCancelar))) .addContainerGap(30, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(LblCodigo) .addComponent(TxtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(LblNombre) .addComponent(TxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(BtnGuardar) .addComponent(BtnCancelar)) .addGap(107, 107, 107)) );
pack(); }// </editor-fold>
private void BtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { ObjGrupo.Grabar();// graba los datos del objeto FrmListadoGrupo Frm=new FrmListadoGrupo(); FrmG2 Frm1=new FrmG2(null, rootPaneCheckingEnabled); Frm1.setVisible(false); Frm.show(); // TODO add your handling code here: }
private void TxtCodigoFocusLost(java.awt.event.FocusEvent evt) { ObjGrupo.Codigo= TxtCodigo.getText();// pasa de el text al objeto cuando pierde el enfoque // TODO add your handling code here: }
private void TxtCodigoPropertyChange(java.beans.PropertyChangeEvent evt) { // TODO add your handling code here: }
private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false);// cierra el formulario // TODO add your handling code here: }
private void TxtNombreFocusLost(java.awt.event.FocusEvent evt) { ObjGrupo.Nombre=TxtNombre.getText();;// pasa de el text al objeto cuando pierde el enfoque
// TODO add your handling code here: }
/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { FrmG2 dialog = new FrmG2(new javax.swing.JFrame(), true); dialog.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); } }); dialog.setVisible(true); } }); }
// Variables declaration - do not modify private javax.swing.JButton BtnCancelar; private javax.swing.JButton BtnGuardar; private javax.swing.JLabel LblCodigo; private javax.swing.JLabel LblNombre; private javax.swing.JTextField TxtCodigo; private javax.swing.JTextField TxtNombre; // End of variables declaration
}
|