Vous êtes sur la page 1sur 21

/** INTERFAZ EMPLEADO**/

/**
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $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;
/**

* Es el panel que contiene los elementos para ver y modificar el salario


del empleado
*/
private PanelSalario panelSalario;
/**
* Es el panel que contiene los elementos para realizar consultas sobre el
empleado
*/
private PanelConsultas panelConsultas;
/**
* Es el panel que contiene los elementos para ejecutar las extensiones a
la aplicacin
*/
private PanelExtensiones panelExtensiones;
//----------------------------------------------------------------// Constructores
//----------------------------------------------------------------/**
* Construye una nueva interfaz inicializada con los datos de una empleado
particular. <br>
* <b>post: </b> El objeto InterfazEmpleado est inicializado y empleado
== e.
* @param e Empleado con el que se inicializa la interfaz. e != null.
*/
public InterfazEmpleado( Empleado e )
{
setTitle( "Sistema de Empleados" );
// construir los paneles
JPanel panelCentral = new JPanel( );
panelDatos = new PanelDatos( );
panelSalario = new PanelSalario( this );
panelConsultas = new PanelConsultas( );
panelExtensiones = new PanelExtensiones( this );
// organizar el
getContentPane(
getContentPane(
getContentPane(
getContentPane(

panel principal
).setLayout( new BorderLayout( ) );
).add( panelDatos, BorderLayout.NORTH );
).add( panelCentral, BorderLayout.CENTER );
).add( panelExtensiones, BorderLayout.SOUTH );

// organizar el panel central


panelCentral.setLayout( new BorderLayout( ) );
panelCentral.add( panelSalario, BorderLayout.NORTH );
panelCentral.add( panelConsultas, BorderLayout.CENTER );
setSize( 530, 530 );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

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 );

Fecha fechaIngreso = new Fecha( );


fechaIngreso.inicializar( 5, 4, 2000 );
Empleado e = new Empleado( );
e.inicializar( "Pedro", "Matallana", 1, fechaNacimiento, fechaIngreso,
1500000 );
e.cambiarImagen( "data/pm.jpg" );
InterfazEmpleado femp = new InterfazEmpleado( e );
femp.actualizarEmpleado( );
femp.setVisible( true );
}
}

//**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 );

butAntiguedad.setText( "Calcular Antigedad" );


butAntiguedad.setActionCommand( PanelConsultas.CALCULAR_ANTIGUEDAD );
butAntiguedad.addActionListener( this );
butPrestaciones.setText( "Calcular Prestaciones" );
butPrestaciones.setActionCommand( PanelConsultas.CALCULAR_PRESTACIONES );
butPrestaciones.addActionListener( this );
}
//----------------------------------------------------------------// Mtodos
//----------------------------------------------------------------/**
* Modifica el empleado que se utiliza para realizar los clculos. <br>
* <b>post: </b> empleado == unEmpleado. <br>
* @param unEmpleado Nuevo empleado que se usar para los clculos.
unEmpleado != null.
*/
public void cambiarEmpleado( Empleado unEmpleado )
{
empleado = unEmpleado;
}
/**
* Limpia los campos. <br>
* <b>post: </b> Todos los campos del panel estn limpios. <br>
*/
public void limpiarCampos( )
{
txtEdad.setText( "" );
txtAntiguedad.setText( "" );
txtPrestaciones.setText( "" );
}
/**
* 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( CALCULAR_EDAD ) )
{
int edad = empleado.darEdad( );
txtEdad.setText( "" + edad );
}
else if( command.equals( CALCULAR_ANTIGUEDAD ) )
{
int antiguedad = empleado.darAntiguedad( );

txtAntiguedad.setText( "" + antiguedad );


}
else if( command.equals( CALCULAR_PRESTACIONES ) )
{
double prestaciones = empleado.darPrestaciones( );
DecimalFormat df = ( DecimalFormat )NumberFormat.getInstance( );
df.applyPattern( "$###,###.##" );
txtPrestaciones.setText( df.format( prestaciones ) );
}
}
}

//** PANEL DE DATOS**//

/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* $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
*/

private JLabel labApellido;


/**
* Etiqueta de la fecha de ingreso
*/
private JLabel labFIngreso;
/**
* Etiqueta de la fecha de nacimiento
*/
private JLabel labFNacimiento;
/**
* Etiqueta del sexo
*/
private JLabel labSexo;
/**
* Campo de texto para el nombre
*/
private JTextField txtNombre;
/**
* Campo de texto para el apellido
*/
private JTextField txtApellido;
/**
* Campo de texto para la fecha de Ingreso
*/
private JTextField txtFIngreso;
/**
* Campo de texto para la fecha de nacimiento
*/
private JTextField txtFNacimiento;
/**
* Campo de texto para el sexo
*/
private JTextField txtSexo;
/**
* Etiqueta donde se muestra la imagen
*/
private JLabel labImagen;
//----------------------------------------------------------------// Constructores
//----------------------------------------------------------------/**
* Construye el de Datos del empleado.

*/
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 );

txtFNacimiento = new JTextField( 10 );


gbc = new GridBagConstraints( 1, 3, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtFNacimiento, gbc );
txtFNacimiento.setEnabled( false );
txtFIngreso = new JTextField( 10 );
gbc = new GridBagConstraints( 1, 4, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets( 5, 5, 5, 5 ), 0, 0 );
add( txtFIngreso, gbc );
txtFIngreso.setEnabled( false );
labImagen = new JLabel( );
gbc = new GridBagConstraints( 2, 0, 1, 5, 1, 1,
GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 5, 5, 5,
5 ), 0, 0 );
add( labImagen, gbc );
}
//----------------------------------------------------------------// Mtodos
//----------------------------------------------------------------/**
* Actualiza los campos del panel con la informacin del empleado. <br>
* <b>post: </b>Los campos muestran la nueva informacin. <br>
* @param nombre Nombre. nombre != null.
* @param apellido Apellido. apellido != null.
* @param sexo Sexo del empleado. sexo pertenece a {"m","f"}.
* @param fechaI Fecha de Ingreso. fechaI != null.
* @param fechaN Fecha de Nacimiento. fechaN != null.
* @param imagen Ruta donde se encuentra la imagen. imagen != null.
*/
public void actualizarCampos( String nombre, String apellido, String
sexo, String fechaI, String fechaN, String imagen )
{
txtNombre.setText( nombre );
txtApellido.setText( apellido );
txtSexo.setText( sexo );
txtFIngreso.setText( fechaI );
txtFNacimiento.setText( fechaN );
try
{
remove( labImagen );
labImagen = new JLabel( new ImageIcon( cargarImagen( imagen ) ) );
GridBagConstraints gbc = new GridBagConstraints( 2, 0, 1, 5, 0, 0,
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets( 5, 5, 5,
5 ), 0, 0 );
add( labImagen, gbc );
}
catch( IOException e )
{

JOptionPane.showMessageDialog( this, "La imagen no se pudo cargar: " +


e.getMessage( ) );
e.printStackTrace( );
}
}
/**
* Este mtodo se usa para cargar la informacin de la imagen. Si no se
leen los bytes de la imagen, entonces se depende del MediaTracker.
* @param imagen Ruta donde se encuentra la imagen. imagen!=null y imagen
corresponde a la ruta de una imagen.
* @return Retorna la imagen.
* @throws IOException Se lanza esta excepcin si no se puede leer la
imagen.
*/
private byte[] cargarImagen( String imagen ) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream( );
FileInputStream fin = new FileInputStream( imagen );
int data = 0;
while( data != -1 )
{
data = fin.read( );
baos.write( data );
}
return baos.toByteArray( );
}
}

//**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;

//----------------------------------------------------------------// Atributos de la Interfaz


//----------------------------------------------------------------/**
* Es el botn 1
*/
private JButton butOpcion1;
/**
* Es el botn 2
*/
private JButton butOpcion2;
//----------------------------------------------------------------// Constructores
//----------------------------------------------------------------/**
* Construye el panel de extensiones con una referencia a la ventana
principal de la aplicacin. <br>
* <b>post: </b> Construy el panel e interfazEmpleado == interfaz. <br>
* @param interfaz Referencia a la ventana principal. interfaz != null.
*/
public PanelExtensiones( InterfazEmpleado interfaz )
{
interfazEmpleado = interfaz;
setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new
TitledBorder( "Puntos de Extensin" ) ) );
setLayout( new FlowLayout( ) );
butOpcion1 = new JButton( "Opcin 1" );
butOpcion1.setActionCommand( OPCION_1 );
butOpcion1.addActionListener( this );
butOpcion2 = new JButton( "Opcin 2" );
butOpcion2.setActionCommand( OPCION_2 );
butOpcion2.addActionListener( this );
add( butOpcion1 );
add( butOpcion2 );
}
//----------------------------------------------------------------// 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 comando = evento.getActionCommand( );
if( OPCION_1.equals( comando ) )
{
interfazEmpleado.reqFuncOpcion1( );
}
else if( OPCION_2.equals( comando ) )
{
interfazEmpleado.reqFuncOpcion2( );
}
}
}

//**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
*/

private InterfazEmpleado interfazEmpleado;


//----------------------------------------------------------------// Atributos de la Interfaz
//----------------------------------------------------------------/**
* Etiqueta para el salario
*/
private JLabel labSalario;
/**
* Es el campo de texto para el salario
*/
private JTextField txtSalario;
/**
* Es el botn para modificar el salario
*/
private JButton botonModificarSalario;
//----------------------------------------------------------------// Constructores
//----------------------------------------------------------------/**
* Construye el panel con una referencia a la ventana principal de la
aplicacin <br>
* <b>post: </b> Construy el panel e interfazEmpleado == interfaz. <br>
* @param interfaz - Referencia a la ventana principal. interfaz != null.
*/
public PanelSalario( InterfazEmpleado interfaz )
{
interfazEmpleado = interfaz;
setLayout( new FlowLayout( ) );
labSalario = new JLabel( "Salario: " );
add( labSalario );
txtSalario = new JTextField( 10 );
add( txtSalario );
botonModificarSalario = new JButton( );
botonModificarSalario.setText( "Modificar" );
botonModificarSalario.setActionCommand( PanelSalario.BUT_MODIFICAR_SALARI
O );
botonModificarSalario.addActionListener( this );
add( botonModificarSalario );
setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new
TitledBorder( "Salario" ) ) );

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 ) );
}
}

Vous aimerez peut-être aussi