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.
Okay. Cool, Danke!
Kannst du mir auch beim Ersetzen des Graphics-Objektes helfen?
protected void paintChildren(){
if(showChildren)
super.paintChildren();
}
protected void paintChildren(){
if(showChildren)
super.paintChildren();
else{
BufferedImage img = new BufferedImage(this.getWidth(), this.getHeight(),
BufferedImage.TYPE_INT_ARGB);
this.paintComponent(img.getGraphics());
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.opacity));
g2d.drawImage(img, null, 0, 0);
}
}
import java.util.Timer;
import java.util.TimerTask;
...
new Timer().schedule(new TimerTask(){
@Override
public void run(){
comp.fade(duration, toOpacity);
}
}, 2000);
class FadingComponent extends Component{
BufferedImage fade;
boolean fading = false;
float opacity = 1f;
public void fade(final int duration, final float opacity){
fade = new BufferedImage(getWidth(), getHeight(),
BufferedImage.TYPE_INT_ARGB);
paintComponent(fade.getGraphics());
fading = true;
final int fps = 25;
new Timer().schedule(new TimerTask(){
Component comp = FadingComponent.this;
//Anzahl der Fading-Schritte
int i = (int) ((float) duration/1000*fps);
//Veränderung des Transparenz-Wertes pro Schritt
float step = (opacity - comp.opacity) / i;
@Override
public void run(){
i--;
//setzen des Transparenz-Werts und neuzeichnen der Komponente
comp.setOpaque(comp.opacity + step);
if(i <= 0){
this.cancel();
comp.fading = false;
}
}
}, 0, duration/fps);
}
@Override
public void paint(Graphics g){
if(!this.fading)
super.paint(g);
else{
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.opacity));
g2d.drawImage((Image) this.fade, 0, 0, null);
}
}
@Override
protected void paintChildren(Graphics g){
if(!this.fading)
super.paintChildren(g);
}
}
class FadingComponent extends Component{
private float opacity = 1f;
public FadingComponent(){
this.setOpaque(false);
}
public void setOpaque(float opacity){
//Transparenz-Wert setzen & repaint()
}
public void fade(final int duration, final float opacity){
final int fps = 25;
new Timer().schedule(new TimerTask(){
FadingComponent comp = FadingComponent.this;
//Anzahl der Fadingschritte
int i = (int) ((float) duration/1000*fps);
//Veränderung des Tranparenzwertes pro Schritt
float step = (opacity - comp.opacity) / i;
@Override
public void run(){
i--;
comp.setOpaque(this.opacity + step);
if(i <= 0){
this.cancel();
}
}
}, 0, duration/fps);
}
@Override
public void paint(Graphics g){
if(this.opacity < 1){
BufferedImage img = new BufferedImage(this.getWidth(), this.getHeight(),
BufferedImage.TYPE_INT_ARGB);
super.paint(img.getGraphics());
Graphics2D g2d = (Graphics2D) g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.opacity));
g2d.drawImage(img, null, 0, 0);
}else{
super.paint(g);
}
}
}