Hola, estoy trabajando en un proyecto nuevo y quiero organizar la estructura de esta forma:
1. Dejar un MDI, para que cuando presione en una opción del menú se abra dentro de la misma ventana y no me cree otra aparte.
2. Dejar una barra de herramientas estándar para todo el proyecto; No quiero crear la misma barra o dar copiar y pegar en cada forma nueva que cree.
3. Utilizar una interface que me obligue a implementar todos los botones que irían en el Toolbar.
Estas son las clases donde tengo el problema:
Código Java:
Ver originalpackage prueba1.Principal;
import javax.swing.JButton;
import javax.swing.JToolBar;
public class principal_barra_menu
extends javax.
swing.
JInternalFrame {
public principal_barra_menu() {
initComponents();
}
return barPrincipal;
}
protected JButton getBotonSalvar
() { return btnGuardar;
}
protected JButton getBotonNuevo
() { return btnNuevo;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
barPrincipal
= new javax.
swing.
JToolBar(); btnGuardar
= new javax.
swing.
JButton(); btnNuevo
= new javax.
swing.
JButton();
barPrincipal.setRollover(true);
btnGuardar.setText("Guardar");
btnGuardar.setFocusable(false);
btnGuardar.
setHorizontalTextPosition(javax.
swing.
SwingConstants.
CENTER); btnGuardar.
setVerticalTextPosition(javax.
swing.
SwingConstants.
BOTTOM); public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { btnGuardarActionPerformed(evt);
}
});
barPrincipal.add(btnGuardar);
btnNuevo.setText("Nuevo");
btnNuevo.setFocusable(false);
btnNuevo.
setHorizontalTextPosition(javax.
swing.
SwingConstants.
CENTER); public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { btnNuevoActionPerformed(evt);
}
});
barPrincipal.add(btnNuevo);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(barPrincipal, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
394,
Short.
MAX_VALUE) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(barPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addGap(0,
253,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
private void btnGuardarActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
}
private void btnNuevoActionPerformed
(java.
awt.
event.
ActionEvent evt
) { // TODO add your handling code here:
}
// Variables declaration - do not modify
private javax.
swing.
JToolBar barPrincipal
; private javax.
swing.
JButton btnGuardar
; private javax.
swing.
JButton btnNuevo
; // End of variables declaration
}
Código Java:
Ver originalpackage prueba1.Principal;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class principal_crear_menu_principal extends principal_barra_menu implements principal_barra_herramientas_interface {
public principal_crear_menu_principal() {
initComponents();
this.barPrincipal.add(super.get_toolbar());
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
barPrincipal
= new javax.
swing.
JToolBar(); panelPrincipal
= new javax.
swing.
JPanel(); lblDescripcion
= new javax.
swing.
JLabel();
setClosable(true);
setMaximizable(true);
setResizable(true);
setTitle("Crear menú");
setToolTipText("");
setAutoscrolls(true);
}
}
}
}
}
}
formInternalFrameOpened(evt);
}
});
barPrincipal.setFloatable(false);
barPrincipal.setRollover(true);
lblDescripcion.
setHorizontalAlignment(javax.
swing.
SwingConstants.
CENTER); lblDescripcion.setText("Descripción:");
lblDescripcion.setToolTipText("");
javax.swing.GroupLayout panelPrincipalLayout = new javax.swing.GroupLayout(panelPrincipal);
panelPrincipal.setLayout(panelPrincipalLayout);
panelPrincipalLayout.setHorizontalGroup(
panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelPrincipalLayout.createSequentialGroup()
.addContainerGap()
.
addComponent(lblDescripcion, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
73,
Short.
MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.
addComponent(txtDescripcion, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
124,
Short.
MAX_VALUE) .addGap(183, 183, 183))
);
panelPrincipalLayout.setVerticalGroup(
panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelPrincipalLayout.createSequentialGroup()
.addContainerGap()
.addGroup(panelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblDescripcion)
.addComponent(txtDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.
addContainerGap(217,
Short.
MAX_VALUE)) );
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.
addComponent(barPrincipal, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE) .
addComponent(panelPrincipal, javax.
swing.
GroupLayout.
Alignment.
TRAILING, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(barPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.
addComponent(panelPrincipal, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
try {
//Dejamos la ventana maximizada por defecto
this.setMaximum(true);
Logger.getLogger(principal_crear_menu_principal.class.getName()).log(Level.SEVERE, null, ex);
}
}
private javax.
swing.
JToolBar barPrincipal
; private javax.
swing.
JLabel lblDescripcion
; private javax.
swing.
JPanel panelPrincipal
;
@Override
public void fnGuardarCambios() {
}
}
El problema es que todas las nuevas formas se extienden de la barra que estoy creando, pero como el evento ocurre en la forma padre (un click por ejemplo) este no se ve reflejada en la forma hija, y en la forma hija es donde necesito implementar los metodos de guardar, actualizar y borrar. ¿Alguna idea? Gracias.