Taller 5

215 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
215
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Taller 5

  1. 1. import java.awt.BorderLayout;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.*;import java.text.DecimalFormat;import java.text.NumberFormat;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.*;import javax.swing.border.CompoundBorder;import javax.swing.border.EmptyBorder;import javax.swing.border.TitledBorder;public class InterfazEmpleado extends JFrame{private PanelDatos panelDatos;private PanelSalario panelSalario;private PanelConsultas panelConsultas;private PanelExtensiones panelExtensiones;
  2. 2. public InterfazEmpleado( ){setTitle( "Sistema de Empleados" );JPanel panelCentral = new JPanel( );panelDatos = new PanelDatos( );panelSalario = new PanelSalario( );panelConsultas = new PanelConsultas( );panelExtensiones = new PanelExtensiones( );getContentPane( ).add( panelDatos, BorderLayout.NORTH );getContentPane( ).add( panelCentral, BorderLayout.CENTER );getContentPane( ).add( panelExtensiones, BorderLayout.SOUTH );panelCentral.setLayout( new BorderLayout( ) );panelCentral.add( panelSalario, BorderLayout.NORTH );panelCentral.add( panelConsultas, BorderLayout.CENTER );setSize( 530, 530 );setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );}public static void main( String[] args ){InterfazEmpleado femp = new InterfazEmpleado( );femp.setVisible( true );}}
  3. 3. class PanelConsultas extends JPanel implements ActionListener{private final static String CALCULAR_EDAD = "CALCULAR EDAD";private final static String CALCULAR_ANTIGUEDAD = "CALCULAR ANTIGUEDAD";private final static String CALCULAR_PRESTACIONES = "CALCULAR PRESTACIONES";private JTextField txtEdad;private JTextField txtAntiguedad;private JTextField txtPrestaciones;private JButton butEdad;private JButton butAntiguedad;private JButton butPrestaciones;public PanelConsultas( ){GridBagLayout gridbag = new GridBagLayout( );setLayout( gridbag );setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new TitledBorder( "Cálculos" ) ));butEdad = new JButton( );GridBagConstraints gbc = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER,GridBagConstraints.BOTH, newInsets( 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,
  4. 4. 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 );
  5. 5. butEdad.addActionListener( this);butAntiguedad.setText( "Calcular Antigüedad" );butAntiguedad.setActionCommand( PanelConsultas.CALCULAR_ANTIGUEDAD );butPrestaciones.setText( "Calcular Prestaciones" );butPrestaciones.setActionCommand( PanelConsultas.CALCULAR_PRESTACIONES );}public void actionPerformed( ActionEvent evento ){String cadena = "";if ( evento.getSource().equals("Calcular Edad"))cadena = "campoTexto1: " + evento.getActionCommand();JOptionPane.showMessageDialog(null, cadena);}}class PanelDatos extends JPanel{private JLabel labNombre;private JLabel labApellido;private JLabel labFIngreso;private JLabel labFNacimiento;private JLabel labSexo;private JTextField txtNombre;private JTextField txtApellido;private JTextField txtFIngreso;private JTextField txtFNacimiento;private JTextField txtSexo;
  6. 6. private JLabel labImagen;public PanelDatos( ){GridBagLayout gridbag = new GridBagLayout( );setLayout( gridbag );setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new TitledBorder( "DatosPersonales" ) ) );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: " );
  7. 7. 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 );
  8. 8. 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 );}}class PanelSalario extends JPanel{private final static String BUT_MODIFICAR_SALARIO = "MODIFICAR SALARIO";private JLabel labSalario;private JTextField txtSalario;private JButton botonModificarSalario;
  9. 9. public PanelSalario( ){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_SALARIO );add( botonModificarSalario );setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new TitledBorder( "Salario" ) ) );txtSalario.setEnabled( false );}}class PanelExtensiones extends JPanel{private final String OPCION_1 = "opcion1";private final String OPCION_2 = "opcion2";private JButton butOpcion1;private JButton butOpcion2;public PanelExtensiones( ){setBorder( new CompoundBorder( new EmptyBorder( 0, 0, 5, 0 ), new TitledBorder( "Puntos deExtensión" ) ) );
  10. 10. setLayout( new FlowLayout( ) );butOpcion1 = new JButton( "Opción 1" );butOpcion1.setActionCommand( OPCION_1 );butOpcion2 = new JButton( "Opción 2" );butOpcion2.setActionCommand( OPCION_2 );add( butOpcion1 );add( butOpcion2 );}}

×