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.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
/*
* Created on 15.03.2005
*/
/**
* @author Steffen Rumpf
*/
public class BackgroundPanel extends JPanel{
private URL url = null;
private boolean viewImg = true;
public BackgroundPanel(URL url, boolean viewImg) {
super(true);
// the url to the image
this.url = url;
// a flag if true the image will be viewed
this.viewImg = viewImg;
}
/** (non-Javadoc)
* @see java.awt.Component#paint(java.awt.Graphics)
* Paint the background image
*/
public void paint(Graphics g) {
if(viewImg == true) {
BufferedImage pic = null;
// create the url for the background image
try {
pic = ImageIO.read(url);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
g.drawImage(pic, 0, 0,this);
super.paint(g);
} else {
super.paint(g);
}
}
/**
* @param viewImg The viewImg to set.
*/
public void setViewImg(boolean viewImg) {
this.viewImg = viewImg;
repaint();
}
}
/**
*
*/
package de.tutorials;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* @author Darimont
*/
public class PanelWithImage extends JFrame {
public PanelWithImage() {
super("PanelWithImage");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JLabel label = new JLabel(new ImageIcon("c:/Winter.gif"));
JPanel panel = new JPanel();
panel.add(label);
add(panel);
pack();
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
new PanelWithImage();
}
}