
jadex.bdi.examples.alarmclock.TimeSpinner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The newest version!
package jadex.bdi.examples.alarmclock;
import java.text.SimpleDateFormat;
import javax.swing.JFormattedTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.DefaultFormatterFactory;
/**
* A spinner for presenting and inputing time values.
*/
public class TimeSpinner extends JSpinner
{
//-------- attributes --------
/** The textfield. */
JFormattedTextField tf;
//-------- constructors --------
/**
* Create a new time spinner with default format.
*/
public TimeSpinner()
{
this("HH:mm:ss");
}
/**
* Create a new time spinner.
* @param format
*/
public TimeSpinner(String format)
{
SpinnerDateModel model = new SpinnerDateModel();
setModel(model);
DateEditor editor = new DateEditor(this, format);
setEditor(editor);
tf = ((DateEditor)this.getEditor()).getTextField();
tf.setEditable(true);
DefaultFormatterFactory factory = (DefaultFormatterFactory)tf.getFormatterFactory();
DateFormatter formatter = (DateFormatter)factory.getDefaultFormatter();
formatter.setAllowsInvalid(false);
}
//-------- methods --------
/**
* Set the format of the spinner.
* @param format The format string.
*/
public void setFormat(String format)
{
((DateFormatter)tf.getFormatter()).setFormat(new SimpleDateFormat(format));
tf.setValue(tf.getValue()); // Force a repaint.
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy