Java - COMO REUTILIZAR CLASES EN JAVA (BOTONES)

 
Vista:

COMO REUTILIZAR CLASES EN JAVA (BOTONES)

Publicado por Luis Leon (15 intervenciones) el 29/01/2008 16:36:10
HOLA AMIGOS, TENGO UN INCONVENIENTE Y ESPERO QUE ME PUEDAN AYUDAR. DESEO HACER VENTANAS DE MANTENIMIENTO DE DIFERENTES TABLAS EN UN SISTEMA, PERO QUIERO VER LA POSIBILIDAD DE REUTILIZAR EL CODIGO Y APROVECHAR ESE POTENCIAL DE JAVA. LA IDEA ES UTILIZAR POR EJEMPLO LOS MISMOS BOTONES DE MANTENIMIENTO PARA TODAS LAS VENTANAS.

PARA ESTO, CREE UN JPANEL CON TODOS LOS BOTONES CORRESPONDIENTES Y EN EL CONSTRUCTOT DE ESTE JPANEL, RECIBO COMO PARAMETROS LAS ACCIONES CORRESPONDIENTES A CADA BOTON DE LA SIGUIENTE MANERA:

=======================================================================================

public Botones(
Action actionPrimero,
Action actionAnterior,
Action actionSiguiente,
Action actionUltimo,
Action actionNuevo,
Action actionModificar,
Action actionEliminar,
Action actionBuscar,
Action actionGuardar,
Action actionCancelar,
Action actionSalir){
this.actionPrimero=actionPrimero;
this.actionAnterior=actionAnterior;
this.actionSiguiente=actionSiguiente;
this.actionUltimo=actionUltimo;
this.actionNuevo=actionNuevo;
this.actionModificar=actionModificar;
this.actionEliminar=actionEliminar;
this.actionBuscar=actionBuscar;
this.actionGuardar=actionGuardar;
this.actionCancelar=actionCancelar;
this.actionSalir=actionSalir;
initComponents();
}

=======================================================================================

Y LUEGO EN EL initComponents(), COLOQUE EL SIGUIENTE CODIGO:

=======================================================================================

jButton1 = new javax.swing.JButton(actionPrimero);
jButton2 = new javax.swing.JButton(actionAnterior);
jButton3 = new javax.swing.JButton(actionSiguiente);
jButton4 = new javax.swing.JButton(actionUltimo);
jButton5 = new javax.swing.JButton(actionNuevo);
jButton6 = new javax.swing.JButton(actionModificar);
jButton7 = new javax.swing.JButton(actionEliminar);
jButton8 = new javax.swing.JButton(actionBuscar);
jButton9 = new javax.swing.JButton(actionGuardar);
jButton10 = new javax.swing.JButton(actionCancelar);
jButton11 = new javax.swing.JButton(actionSalir);

=======================================================================================

EN LA VENTANA DESDE DONDE VOY A UTILIZAR LOS BOTONES INSERTO EL JPANEL Y EN EL CONSTRUCTOR COLOCO EL SIGUIENTE CODIGO PARA ARMAR LAS ACCIONES QUE LUEGO ENVIARE AL RESPECTIVO JPANEL:

=======================================================================================

conexion = FrmPrincipal.getConexionPrincipal().Consulta("SELECT * FROM MAEPAIS ORDER BY CODPAIS");
//*** Iniciar valores de variables para enviar como Parametros a Botones ***
actionPrimero=new ActionPrimero ("<<", null, "Ir al Primer Registro", null, this, conexion);
actionAnterior=new ActionAnterior ("<", null, "Ir al Anterior Registro", null, this, conexion);
actionSiguiente=new ActionSiguiente (">", null, "Ir al Siguiente Registro", null, this, conexion);
actionUltimo=new ActionUltimo (">>", null, "Ir al Ultimo Registro", null, this, conexion);
actionNuevo=new ActionNuevo ("Nuevo", null, "Crear Nuevo Registro", new Integer(KeyEvent.VK_N), this);
actionModificar=new ActionModificar ("Modificar", null, "Modificar Registro", new Integer(KeyEvent.VK_M), this);
actionEliminar=new ActionEliminar ("Eliminar", null, "Eliminar Registro", new Integer(KeyEvent.VK_E), this);
actionBuscar=new ActionBuscar ("Buscar", null, "Buscar Registros", new Integer(KeyEvent.VK_B), this);
actionGuardar=new ActionGuardar ("Guardar", null, "Guardar Registro", new Integer(KeyEvent.VK_G), this);
actionCancelar=new ActionCancelar ("Cancelar", null, "Cancela Registro", new Integer(KeyEvent.VK_C), this);
actionSalir=new ActionSalir("Salir", null, "Salir de la Ventana", new Integer(KeyEvent.VK_S), this);
//**************************************************************************

===========================================================================================

botones1 = new com.automundial.utilidades.Botones(
actionPrimero,
actionAnterior,
actionSiguiente,
actionUltimo,
actionNuevo,
actionModificar,
actionEliminar,
actionBuscar,
actionGuardar,
actionCancelar,
actionSalir);

===========================================================================================

PREVIAMENTE DEFINI UNA CLASE QUE TENDRA LAS ACCIONES POR CADA BOTON DE LA SIGUIENTE MANERA:

===========================================================================================

public class ActionPrimero extends AbstractAction {

private Clase009 frame;
private ResultSet conexion;

/** Creates a new instance of ActionPrimero */
public ActionPrimero(
String text,
ImageIcon icon,
String desc,
Integer mnemonic,
JInternalFrame frame,
ResultSet conexion) {
super (text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
this.frame=(Clase009) frame;
this.conexion=conexion;
}

public void actionPerformed(ActionEvent e) {
try {
conexion.first();
System.out.println("Fui al Primero");
frame.getDatos11().getJTextField1().setText(conexion.getString(1));
frame.getDatos11().getJTextField1().setText(conexion.getString(2));
// frame.MostrarDatos();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}

=======================================================================================

EL PROBLEMA ES QUE COMO VOY A TRABAJAR CON DATOS, COMO PUEDO HACER EL MANEJO DE LOS CAMPOS EN CADA JInternalFrame PARA ASIGNARLE EL VALOR DEL RESULTADO DE LA CONEXION ... ? .. SI EN LA ACCION COLOCO EL FRAME LOCAL DE TIPO Clase009 (QUE ES UNA DE TANTAS VENTANAS) ME FUNCIONA, PERO SOLO DESDE ESA VENTANA Y SE SUPONE QUE ESTA ACCION SE DEBERIA PODER EJECUTAR DESDE CUALQUIER JInternalFrame ... AGRADECERIA SI ALGUIEN TIENE ALGUNA IDEA DE COMO SOLUCIONAR ESTE PROBLEMITA

MUCHAS GRACIAS DE ANTEMANO,

LUIS LEON
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:COMO REUTILIZAR CLASES EN JAVA (BOTONES)

Publicado por Milton (1 intervención) el 15/01/2011 05:39:44
TENGO LA MISMA DUDA... ALGUIEN SABE COMO SOLUCIONARLO?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar