Académique Documents
Professionnel Documents
Culture Documents
/**
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $Id$
* Universidad de los Andes (Bogot - Colombia)
* Departamento de Ingeniera de Sistemas y Computacin
* Licenciado bajo el esquema Academic Free License version 2.1
*
* Proyecto Cupi2
* Ejercicio: n1_empleado
* Autor: Mario Snchez - 13/06/2005
* Autor: Mario Snchez - 02/2005
* Autor: Pablo Barvo - 22/08/2005
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package uniandes.cupi2.empleado.interfaz;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import uniandes.cupi2.empleado.mundo.Empleado;
import uniandes.cupi2.empleado.mundo.Fecha;
/**
* Esta es la ventana principal de la aplicacin. Contiene a los paneles
que tienen los botones y muestran la informacin del empleado.
*/
public class InterfazEmpleado extends JFrame
{
//----------------------------------------------------------------// Atributos
//----------------------------------------------------------------/**
* El empleado que se est mostrando
*/
private Empleado empleado;
//----------------------------------------------------------------// Atributos de la interfaz
//----------------------------------------------------------------/**
* Es el panel que contiene los elementos para mostrar los datos del
empleado
*/
private PanelDatos panelDatos;
/**
panel principal
).setLayout( new BorderLayout( ) );
).add( panelDatos, BorderLayout.NORTH );
).add( panelCentral, BorderLayout.CENTER );
).add( panelExtensiones, BorderLayout.SOUTH );
empleado = e;
panelConsultas.cambiarEmpleado( e );
}
//----------------------------------------------------------------// Mtodos
//----------------------------------------------------------------/**
* Este mtodo sirve para actualizar los campos de la forma con los datos
actuales del empleado. <br>
* <b>post: </b>Los campos de la ventana contienen la informacin del
empleado. <br>
*/
public void actualizarEmpleado( )
{
String nombre, apellido, sexo, fechaI, fechaN, imagen;
int salario;
nombre = empleado.darNombre( );
apellido = empleado.darApellido( );
int iSexo = empleado.darSexo( );
if( iSexo == 1 )
sexo = "m";
else
sexo = "f";
fechaI = empleado.darFechaIngreso( );
fechaN = empleado.darFechaNacimiento( );
salario = empleado.darSalario( );
imagen = empleado.darImagen( );
panelDatos.actualizarCampos( nombre, apellido, sexo, fechaI, fechaN,
imagen );
panelSalario.actualizarSalario( salario );
panelConsultas.limpiarCampos( );
validate( );
}
/**
* En este mtodo se solicita al usuario que ingrese el nuevo salario del
empleado y se actualiza su informacin. <br>
* <b>post: </b> Se actualiz el salario del empleado y se present la
informacin actualizada. <br>
*/
public void modificarSalario( )
{
String strSalario = JOptionPane.showInputDialog( this, "Introduzca el
nuevo salario" );
if( strSalario != null )
{
try
{
int nuevoSalario = Integer.parseInt( strSalario );
empleado.cambiarSalario( nuevoSalario );
panelSalario.actualizarSalario( empleado.darSalario( ) );
}
catch( NumberFormatException nfe )
{
JOptionPane.showMessageDialog( this, "El salario indicado no es vlido."
);
}
}
}
//----------------------------------------------------------------// Puntos de Extensin
//----------------------------------------------------------------/**
* Mtodo 1 de extensin del ejemplo
*/
public void reqFuncOpcion1( )
{
String respuesta = empleado.metodo1( );
JOptionPane.showMessageDialog( this, respuesta, "Respuesta",
JOptionPane.INFORMATION_MESSAGE );
}
/**
* Mtodo 2 de extensin del ejemplo
*/
public void reqFuncOpcion2( )
{
String respuesta = empleado.metodo2( );
JOptionPane.showMessageDialog( this, respuesta, "Respuesta",
JOptionPane.INFORMATION_MESSAGE );
}
//----------------------------------------------------------------// Main
//----------------------------------------------------------------/**
* Este mtodo ejecuta la aplicacin, creando una nueva interfaz e
inicializndola con un empleado.
* @param args Los argumentos no son utilizados.
*/
public static void main( String[] args )
{
Fecha fechaNacimiento = new Fecha( );
fechaNacimiento.inicializar( 16, 6, 1982 );
//**PANEL CONSULTA**//
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $Id$
* Universidad de los Andes (Bogot - Colombia)
* Departamento de Ingeniera de Sistemas y Computacin
* Licenciado bajo el esquema Academic Free License version 2.1
*
* Proyecto Cupi2 (http://cupi2.uniandes.edu.co)
* Ejercicio: n1_empleado
* Autor: Mario Snchez - Jun 13, 2005
* Autor: Mario Snchez - Jun 13, 2005
* Autor: Pablo Barvo - 22/08/2005
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package uniandes.cupi2.empleado.interfaz;
import
import
import
import
import
import
import
import
import
import
import
import
import
java.awt.GridBagConstraints;
java.awt.GridBagLayout;
java.awt.Insets;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
java.text.DecimalFormat;
java.text.NumberFormat;
javax.swing.JButton;
javax.swing.JPanel;
javax.swing.JTextField;
javax.swing.border.CompoundBorder;
javax.swing.border.EmptyBorder;
javax.swing.border.TitledBorder;
import uniandes.cupi2.empleado.mundo.Empleado;
/**
* En este panel se muestran los campos y botones necesarios para realizar
las consultas
*/
public class PanelConsultas extends JPanel implements ActionListener
{
//----------------------------------------------------------------// Constantes
//----------------------------------------------------------------/**
* El comando para el botn de calcular la edad del empleado
*/
private final static String CALCULAR_EDAD = "CALCULAR EDAD";
/**
* El comando para el botn de calcular la antigedad del empleado
*/
private final static String CALCULAR_ANTIGUEDAD = "CALCULAR ANTIGUEDAD";
/**
* El comando para el botn de calcular las prestaciones del empleado
*/
private final static String CALCULAR_PRESTACIONES = "CALCULAR
PRESTACIONES";
//----------------------------------------------------------------// Atributos
//----------------------------------------------------------------/**
* El empleado sobre el que se realizan los clculos
*/
private Empleado empleado;
//----------------------------------------------------------------// Atributos de la interfaz
//----------------------------------------------------------------/**
* El campo donde se muestra la edad
*/
private JTextField txtEdad;
/**
* El campo donde se muestra la antigedad
*/
private JTextField txtAntiguedad;
/**
* El campo donde se muestran las prestaciones
*/
private JTextField txtPrestaciones;
/**
* El botn para calcular la edad
*/
private JButton butEdad;
/**
* El botn para calcular la antigedad
*/
private JButton butAntiguedad;
/**
* El botn para calcular las prestaciones
*/
private JButton butPrestaciones;
//-----------------------------------------------------------------
// Constructores
//----------------------------------------------------------------/**
* Construye el panel de datos a consultar.
*/
public PanelConsultas( )
{
GridBagLayout gridbag = new GridBagLayout( );
setLayout( gridbag );
setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new
TitledBorder( "Clculos" ) ) );
butEdad = new JButton( );
GridBagConstraints gbc = new GridBagConstraints( 0, 0, 1, 1, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 5, 5, 5,
5 ), 0, 0 );
add( butEdad, gbc );
butAntiguedad = new JButton( );
gbc = new GridBagConstraints( 0, 1, 1, 1, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 5, 5, 5,
5 ), 0, 0 );
add( butAntiguedad, gbc );
butPrestaciones = new JButton( );
gbc = new GridBagConstraints( 0, 2, 1, 1, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 5, 5, 5,
5 ), 0, 0 );
add( butPrestaciones, gbc );
txtEdad = new JTextField( 10 );
gbc = new GridBagConstraints( 1, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtEdad, gbc );
txtEdad.setEnabled( false );
txtAntiguedad = new JTextField( 10 );
gbc = new GridBagConstraints( 1, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtAntiguedad, gbc );
txtAntiguedad.setEnabled( false );
txtPrestaciones = new JTextField( 10 );
gbc = new GridBagConstraints( 1, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtPrestaciones, gbc );
txtPrestaciones.setEnabled( false );
butEdad.setText( "Calcular Edad" );
butEdad.setActionCommand( PanelConsultas.CALCULAR_EDAD );
butEdad.addActionListener( this );
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $Id$
* Universidad de los Andes (Bogot - Colombia)
* Departamento de Ingeniera de Sistemas y Computacin
* Licenciado bajo el esquema Academic Free License version 2.1
*
* Proyecto Cupi2 (http://cupi2.uniandes.edu.co)
* Ejercicio: n1_empleado
* Autor: Mario Snchez - Jun 13, 2005
* Autor: Mario Snchez - Jun 13, 2005
* Autor: Pablo Barvo - 22/08/2005
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package uniandes.cupi2.empleado.interfaz;
import
import
import
import
import
import
java.awt.GridBagConstraints;
java.awt.GridBagLayout;
java.awt.Insets;
java.io.ByteArrayOutputStream;
java.io.FileInputStream;
java.io.IOException;
import
import
import
import
import
import
import
import
javax.swing.ImageIcon;
javax.swing.JLabel;
javax.swing.JOptionPane;
javax.swing.JPanel;
javax.swing.JTextField;
javax.swing.border.CompoundBorder;
javax.swing.border.EmptyBorder;
javax.swing.border.TitledBorder;
/**
* En este panel se muestran los datos del empleado
*/
public class PanelDatos extends JPanel
{
//----------------------------------------------------------------// Atributos de la Interfaz
//----------------------------------------------------------------/**
* Etiqueta del nombre
*/
private JLabel labNombre;
/**
* Etiqueta del apellido
*/
*/
public PanelDatos( )
{
GridBagLayout gridbag = new GridBagLayout( );
setLayout( gridbag );
setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new
TitledBorder( "Datos Personales" ) ) );
GridBagConstraints gbc;
labNombre = new JLabel( "Nombre: " );
gbc = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( labNombre, gbc );
labApellido = new JLabel( "Apellido: " );
gbc = new GridBagConstraints( 0, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( labApellido, gbc );
labSexo = new JLabel( "Sexo: " );
gbc = new GridBagConstraints( 0, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( labSexo, gbc );
labFNacimiento = new JLabel( "Fecha de Nacimiento: " );
gbc = new GridBagConstraints( 0, 3, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( labFNacimiento, gbc );
labFIngreso = new JLabel( "Fecha de Ingreso: " );
gbc = new GridBagConstraints( 0, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( labFIngreso, gbc );
txtNombre = new JTextField( 15 );
gbc = new GridBagConstraints( 1, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtNombre, gbc );
txtNombre.setEnabled( false );
txtApellido = new JTextField( 15 );
gbc = new GridBagConstraints( 1, 1, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtApellido, gbc );
txtApellido.setEnabled( false );
txtSexo = new JTextField( 2 );
gbc = new GridBagConstraints( 1, 2, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtSexo, gbc );
txtSexo.setEnabled( false );
//**PANEL EXTENSIONES**//
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $Id$
* Universidad de los Andes (Bogot - Colombia)
* Departamento de Ingeniera de Sistemas y Computacin
* Licenciado bajo el esquema Academic Free License version 2.1
*
* Proyecto Cupi2 (http://cupi2.uniandes.edu.co)
* Ejercicio: n1_empleado
* Autor: Mario Snchez - 14/06/2005
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package uniandes.cupi2.empleado.interfaz;
import
import
import
import
import
import
import
import
java.awt.FlowLayout;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
javax.swing.JButton;
javax.swing.JPanel;
javax.swing.border.CompoundBorder;
javax.swing.border.EmptyBorder;
javax.swing.border.TitledBorder;
/**
* Es el panel para las extensiones del ejemplo
*/
public class PanelExtensiones extends JPanel implements ActionListener
{
//----------------------------------------------------------------// Constantes
//----------------------------------------------------------------/**
* El comando para el botn 1
*/
private final String OPCION_1 = "opcion1";
/**
* El comando para el botn 2
*/
private final String OPCION_2 = "opcion2";
//----------------------------------------------------------------// Atributos
//----------------------------------------------------------------/**
* Es la referencia a la interfaz de la aplicacin
*/
private InterfazEmpleado interfazEmpleado;
//**PANEL SALARIO**//
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $Id$
* Universidad de los Andes (Bogot - Colombia)
* Departamento de Ingeniera de Sistemas y Computacin
* Licenciado bajo el esquema Academic Free License version 2.1
*
* Proyecto Cupi2 (http://cupi2.uniandes.edu.co)
* Ejercicio: n1_empleado
* Autor: Mario Snchez - Jun 13, 2005
* Autor: Mario Snchez - Jun 13, 2005
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
package uniandes.cupi2.empleado.interfaz;
import
import
import
import
import
java.awt.FlowLayout;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
java.text.DecimalFormat;
java.text.NumberFormat;
import
import
import
import
import
import
import
javax.swing.JButton;
javax.swing.JLabel;
javax.swing.JPanel;
javax.swing.JTextField;
javax.swing.border.CompoundBorder;
javax.swing.border.EmptyBorder;
javax.swing.border.TitledBorder;
/**
* Es el panel en el que se muestra y se modifica el salario del empleado
*/
public class PanelSalario extends JPanel implements ActionListener
{
//----------------------------------------------------------------// Constantes
//----------------------------------------------------------------/**
* Es el comando para el botn de modificar el salario
*/
private final static String BUT_MODIFICAR_SALARIO = "MODIFICAR SALARIO";
//----------------------------------------------------------------// Atributos
//----------------------------------------------------------------/**
* Es una referencia a la interfaz de la aplicacin
*/
txtSalario.setEnabled( false );
}
//----------------------------------------------------------------// Mtodos
//----------------------------------------------------------------/**
* Este mtodo se llama cuando se presiona uno de los botones. <br>
* <b>post: </b> Se ejecut la accin correspondiente al botn presionado.
<br>
* @param evento El evento del click en el botn. evento != null.
*/
public void actionPerformed( ActionEvent evento )
{
String command = evento.getActionCommand( );
if( command.equals( BUT_MODIFICAR_SALARIO ) )
{
interfazEmpleado.modificarSalario( );
}
}
/**
* Actualiza el salario que se muestra. <br>
* <b>post: </b> Se cambi el salario mostrado. <br>
* @param salario.
*/
public void actualizarSalario( int salario )
{
DecimalFormat df = ( DecimalFormat )NumberFormat.getInstance( );
df.applyPattern( "$###,###.##" );
txtSalario.setText( df.format( salario ) );
}
}