0% found this document useful (0 votes)
21 views14 pages

Pract 19

The document describes a Java program that allows a user to enter a date and displays it in words. It includes a class called Fecha with methods to initialize GUI components like labels, text fields, and buttons. It also contains code to validate the date entered, convert the month number to its name, and display the full date in words.

Uploaded by

Jade Reyes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views14 pages

Pract 19

The document describes a Java program that allows a user to enter a date and displays it in words. It includes a class called Fecha with methods to initialize GUI components like labels, text fields, and buttons. It also contains code to validate the date entered, convert the month number to its name, and display the full date in words.

Uploaded by

Jade Reyes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

ENUNCIADO:

Diagrama de clases

FECHA

jPanel1
lblAnio
lblDia
lblLetras
lblMes
btnAceptar
btnLimpiar
btnSalir
Txtf
Txtf1
Txtf2
initComponents
Código fuente

//Fecha,Java

package newpackage;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

public class Fecha extends javax.swing.JFrame


public Fecha() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();


lblDia = new javax.swing.JLabel();
lblMes = new javax.swing.JLabel();
lblAnio = new javax.swing.JLabel();
txtf = new javax.swing.JTextField();
txtf1 = new javax.swing.JTextField();
txtf2 = new javax.swing.JTextField();
btnAceptar = new javax.swing.JButton();
btnLimpiar = new javax.swing.JButton();
btnSalir = new javax.swing.JButton();
lblLetras = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

lblDia.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


lblDia.setText("Dia");

lblMes.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


lblMes.setText("Mes");

lblAnio.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


lblAnio.setText("Anio");

txtf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtfActionPerformed(evt);
}
});

txtf1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtf1ActionPerformed(evt);
}
});

txtf2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtf2ActionPerformed(evt);
}
});

btnAceptar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});

btnLimpiar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


btnLimpiar.setText("Limpiar");
btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLimpiarActionPerformed(evt);
}
});

btnSalir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


btnSalir.setText("Salir");
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(evt);
}
});

lblLetras.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

lblLetras.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBor
der.RAISED));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);


jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.TRAILING)
.addComponent(lblAnio)
.addComponent(lblMes)
.addComponent(lblDia))
.addGap(35, 35, 35)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING, false)
.addComponent(txtf2, javax.swing.GroupLayout.DEFAULT_SIZE, 69,
Short.MAX_VALUE)
.addComponent(txtf1)
.addComponent(txtf))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignme
nt.LEADING, false)
.addComponent(btnAceptar, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnLimpiar, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnSalir, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(50, 50, 50))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lblLetras, javax.swing.GroupLayout.PREFERRED_SIZE, 252,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(70, Short.MAX_VALUE))))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(lblDia)
.addComponent(txtf, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnAceptar))
.addGap(29, 29, 29)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(lblMes)
.addComponent(txtf1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnLimpiar))
.addGap(36, 36, 36)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BA
SELINE)
.addComponent(lblAnio)
.addComponent(txtf2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSalir))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45,
Short.MAX_VALUE)
.addComponent(lblLetras, javax.swing.GroupLayout.PREFERRED_SIZE, 63,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

private void txtfActionPerformed(java.awt.event.ActionEvent evt) {


}

private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {

int dia = Integer.parseInt(txtf.getText());


int mes = Integer.parseInt(txtf1.getText());
int anio = Integer.parseInt(txtf2.getText());
if (mes == 2){
if (dia<0 || dia >29){
JOptionPane.showMessageDialog(null, "ERROR", "Dia erroneo",
JOptionPane.ERROR_MESSAGE);}
txtf.setText("");
}
else { if (mes<0 || mes > 12)
JOptionPane.showMessageDialog(null, "ERROR", "Mes erroneo",
JOptionPane.ERROR_MESSAGE);
if (dia<0 || dia >31){
JOptionPane.showMessageDialog(null, "ERROR", "Dia erroneo",
JOptionPane.ERROR_MESSAGE);
}
}

//String fecha = obtenerFechaEnLetras(dia, mes, anio);


String mmes = "";
switch(mes){
case 1: mmes ="Enero";
break;
case 2: mmes ="Febrero";
break;
case 3: mmes ="Marzo";
break;
case 4: mmes ="Abril";
break;
case 5: mmes ="Mayo";
break;
case 6: mmes ="Junio";
break;
case 7: mmes ="Julio";
break;
case 8: mmes ="Agosto";
break;
case 9: mmes ="Septiembre";
break;
case 10: mmes ="Octubre";
break;
case 11: mmes ="Noviembre";
break;
case 12: mmes ="Diciembre";
break;

}
lblLetras.setText("En letras es: " + dia + " de " + mmes + " del " + anio);
lblLetras.setVisible(true);

private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {

txtf.setText("");
txtf1.setText("");
txtf2.setText("");
lblLetras.setText("");
}

private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {


int codigo=JOptionPane.showConfirmDialog(null, "¿Quieres continuar?", "Confirmación",
JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
if (codigo==JOptionPane.YES_OPTION){
System.out.println("Has pulsado en SI");
}else if(codigo==JOptionPane.NO_OPTION){
//System.out.println("Has pulsado en NO");
System.exit(0);
}
}

private void txtf1ActionPerformed(java.awt.event.ActionEvent evt) {

private void txtf2ActionPerformed(java.awt.event.ActionEvent evt) {

// private String obtenerFechaEnLetras(int dia, int mes, int anio) {

// return ""; // Retorna la fecha en letras


//}

public static void main(String args[]) {


/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Fecha.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Fecha.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Fecha.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Fecha.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {

try {
Fecha frame = new Fecha();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}

});
}
// Variables declaration - do not modify
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnLimpiar;
private javax.swing.JButton btnSalir;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblAnio;
private javax.swing.JLabel lblDia;
private javax.swing.JLabel lblLetras;
private javax.swing.JLabel lblMes;
private javax.swing.JTextField txtf;
private javax.swing.JTextField txtf1;
private javax.swing.JTextField txtf2;
// End of variables declaration

Ventana de ejecución

Lista de controles utilizados


 Etiqueta (jLabel): un área de visualización de una cadena de texto o una imagen, o ambas. Control
swing
 Botón (jButton): un botón "oprimir". Control swing
 Campo de texto (jTextField): un componente ligero que permite editar una línea idividual de texto.
Control swing

You might also like