Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class DateLabel {
public static void main(String []args) {
JFrame testframe=new JFrame("Date Label Test");
JLabel testlabel=new JLabel("Datum: "+(new Date()).toString());
testframe.add(testlabel);
testframe.setSize(400, 500);
testframe.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Date;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.Timer;
import javax.swing.border.BevelBorder;
/**
* The Class <code>DateTimeLabel</code>.
*/
public class DateTimeLabel extends JLabel {
/** The date formatter. */
private final DateFormat formatter;
/** The update interval. */
private final int updateInterval;
/**
* Instantiates a new date time label.
*
* @param format the format
* @param updateInterval the update interval in milliseconds
*/
public DateTimeLabel(final DateFormat format, final int updateInterval) {
super();
this.formatter = format;
this.updateInterval = updateInterval;
setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
updateTime();
startTimer();
}
/**
* Start timer.
*/
private void startTimer() {
final Timer timer = new Timer(updateInterval, new ActionListener() {
/** {@inheritDoc} */
public void actionPerformed(final ActionEvent e) {
updateTime();
}
});
timer.start();
}
/**
* Update time.
*/
private void updateTime() {
setText(" " + formatter.format(new Date()) + " ");
}
}
import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* The Class <code>DateLabelTest</code>.
*/
public class DateLabelTest extends JFrame {
/**
* Create a new instance of <code>DateLabelTest</code>.
*/
public DateLabelTest() {
super("DateLabelTest");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
final JLabel currentTime = new JLabel("Current Time:");
final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
final JLabel dateTimeLabel = new DateTimeLabel(formatter, 1000);
final JPanel panel = new JPanel();
panel.add(currentTime);
panel.add(dateTimeLabel);
getContentPane().add(panel);
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
final JFrame frame = new DateLabelTest();
final Dimension frameSize = new Dimension(600, 400);
frame.setSize(frameSize);
final Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
final int frameX = (screenSize.width - frameSize.width) / 2;
final int frameY = (screenSize.height - frameSize.height) / 2;
frame.setLocation(frameX, frameY);
frame.setVisible(true);
}
}