Que evento hace que al hacer click sobre un día, me aparezca datos sobre el campo de texto. Por ejemplo, es un sistema de un gimnasio, si le dará click sobre un día, me tendría que aparecer un monto en el campo de texto.
-
puedes usar el OnClickListener()– Gustavo HernándezCommented el 9 jul. 2020 a las 20:06
-
Hola Luis, agrega lo que realizaste, revisa Cómo preguntar y edita tu pregunta, saludos.– Jorgesys ♦Commented el 9 jul. 2020 a las 21:20
-
Ese evento creo que solo esta para Android, yo uso NetBeans no Eclipse...– LuisCommented el 9 jul. 2020 a las 21:24
Añade un comentario
|
1 respuesta
Puedes usar un PropertyChangeListener de la siguiente manera:
jCalendar1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jCalendar1PropertyChange(evt); // o el nombde de método que quiera para manejarlo
}
});
Es decir, que cada que una propiedad de tu bean de calendario cambie se lanzará el evento.
Por ejemplo para mostrar la fecha seleccionada en el JCalendar puedes hacerlo de la siguiente manera:
package com.github.javatlacati.deleteme;
public class NewJFrame extends javax.swing.JFrame {
// Variables declaration - do not modify
private com.toedter.calendar.JCalendar jCalendar1;
private javax.swing.JTextField txtMonto;
// End of variables declaration
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
txtMonto = new javax.swing.JTextField();
jCalendar1 = new com.toedter.calendar.JCalendar();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jCalendar1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
jCalendar1PropertyChange(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(70, 70, 70)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtMonto)
.addGroup(layout.createSequentialGroup()
.addComponent(jCalendar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 108, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(48, 48, 48)
.addComponent(jCalendar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(57, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jCalendar1PropertyChange(java.beans.PropertyChangeEvent evt) {
txtMonto.setText(jCalendar1.getDate().toLocaleString());
}
/**
* @param args the command line arguments
*/
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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.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() {
new NewJFrame().setVisible(true);
}
});
}
}