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 javax.swing.JFrame;
public class JWindow extends JFrame
{
private final JDisplay display;
public JWindow(String title, JDisplay display) {
super(title);
this.display = display;
}
/**
* @return the display
*/
public JDisplay getDisplay() {
return display;
}
}
import java.awt.Window;
import java.util.HashMap;
import java.util.Map;
public class JDisplay
{
private static Map<Thread, JDisplay> displays = new HashMap<Thread, JDisplay>();
public JDisplay() {
displays.put(Thread.currentThread(), this);
}
/**
* @return
*/
public static JDisplay getCurrent() {
return displays.get(Thread.currentThread());
}
/**
* @return
*/
public JWindow getActiveWindow() {
final Thread thread = Thread.currentThread();
final JDisplay display = displays.get(thread);
Window[] windows = JWindow.getWindows();
if(windows == null) {
return null;
}
for(int i = 0; i < windows.length; i++) {
JWindow window = (JWindow) windows[i];
if(window.getDisplay().equals(display)) {
return window;
}
}
return null;
}
}
public class JDisplayTest
{
/**
* @param args
*/
public static void main(String[] args) {
JDisplay display = new JDisplay();
JWindow window = new JWindow("Demo", display);
window.setTitle("Demo");
window.setSize(400, 400);
window.setDefaultCloseOperation(JWindow.EXIT_ON_CLOSE);
window.setVisible(true);
System.out.println("ActiveWindow="+JDisplay.getCurrent().getActiveWindow().getTitle());
}
}
public class JDisplayTest
{
/**
* @param args
*/
public static void main(String[] args) {
JDisplay display = new JDisplay();
JWindow window = new JWindow("Demo", display);
window.setTitle("Demo");
window.setSize(400, 400);
window.setDefaultCloseOperation(JWindow.EXIT_ON_CLOSE);
window.setVisible(true);
Xyz xyz = new Xyz();
}
}
public class Xyz()
{
public xyz()
{
Hier möchte ich das mainFrame haben
}
}
JDisplay.getCurrent().getActiveWindow()