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.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.PrintStream;
import javax.swing.*;
public class EscapeShortcutExample extends JFrame {
private PrintStream o = System.out;
private JTextArea tArea = new JTextArea();
private JButton b1 = new JButton("Insert time");
private JButton b2 = new JButton("Insert date");
private JButton b3 = new JButton("Add text");
private JTextField t1 = new JTextField(20);
private JPanel p1 = new JPanel();
private JPanel p2 = new JPanel();
public EscapeShortcutExample() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(400, 500);
this.setLocationByPlatform(true);
p1.add(t1);
p1.add(b3);
p2.add(b1);
p2.add(b2);
this.add(p1, BorderLayout.NORTH);
this.add(new JScrollPane(tArea), BorderLayout.CENTER);
this.add(p2, BorderLayout.SOUTH);
registerShortcutAll(this.getContentPane().getComponents());
this.setVisible(true);
}
public static void main(String[] args) {
new EscapeShortcutExample();
}
public void registerShortcutAll(Component[] coms) {
try {
for (int i = 0; i < coms.length; i++) {
registerShortcut((JComponent) coms[i]);
}
for (int i = 0; i < coms.length; i++) {
registerShortcutAll(((JComponent) coms[i]).getComponents());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void registerShortcut(JComponent c) {
c.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "actionName");
c.getActionMap().put("actionName", new AbstractAction("actionName") {
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
});
}
}
/**
*
*/
package de.tutorials;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
* @author Tom
*
*/
public class HotKeyExample extends JFrame {
private JTextArea tArea = new JTextArea();
private JButton b1 = new JButton("Insert time");
private JButton b2 = new JButton("Insert date");
private JButton b3 = new JButton("Add text");
private JTextField t1 = new JTextField(20);
private JPanel p1 = new JPanel();
private JPanel p2 = new JPanel();
public HotKeyExample() {
super("HotKeyExample");
setDefaultCloseOperation(EXIT_ON_CLOSE);
p1.add(t1);
p1.add(b3);
p2.add(b1);
p2.add(b2);
this.add(p1, BorderLayout.NORTH);
this.add(new JScrollPane(tArea), BorderLayout.CENTER);
this.add(p2, BorderLayout.SOUTH);
pack();
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
Toolkit.getDefaultToolkit().getSystemEventQueue().push(
new EventQueue() {
protected void dispatchEvent(AWTEvent event) {
if (event instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent) event;
if (keyEvent.getID() == KeyEvent.KEY_PRESSED
&& (keyEvent).getKeyCode() == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
}
super.dispatchEvent(event);
}
});
new HotKeyExample();
}
}