Reloj digital con Swing
Java
(5)
Publicado el 22 de Enero del 2019 por Administrador (718 códigos)
20.557 visualizaciones desde el 22 de Enero del 2019
Ejemplo, del uso de un reloj digital utilizando Swing
/**
* Place the JFrame with the parameters by moving the component relative to the center of the screen.
* Colocamos el JFrame con los parámetros desplazando el componente respecto al centro de la pantalla.
* @param moveWidth int positive or negative offset width (desplazamiente de width positivo o negativo).
* @param moveHeight int Positive or negative offset height (desplazamiento de height positivo o negativo).
*/
public void setLocationMove(int moveWidth, int moveHeight) {
// Obtenemos el tamaño de la pantalla.
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Obtenemos el tamaño de nuestro frame.
Dimension frameSize = this.getSize();
frameSize.width = frameSize.width > screenSize.width?screenSize.width:frameSize.width;
frameSize.height = frameSize.height > screenSize.height?screenSize.height:frameSize.height;
// We define the location. Definimos la localización.
setLocation((screenSize.width - frameSize.width) / 2 + moveWidth, (screenSize.height - frameSize.height) / 2 + moveHeight);
}
/**
* Set the JFrame in the center of the screen.
* Colocamos nuestro JFrame en el centro de la pantalla.
*/
public void setLocationCenter(){
setLocationMove(0, 0);
}
new JFrameCenterSimple(100, 200).setVisible(true);
new JFrameCenterSimple(-100, -200).setVisible(true);
new JFrameCenterSimple().setVisible(true);