1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| package com.ddd.schema.applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseListener;
import java.awt.font.TextLayout;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
//Divers imports
class PanelGrapheLineaire extends JPanel {
private static final long serialVersionUID = 1L;
protected BufferedImage graphe;
protected Graphics2D bufferGraphe;
protected boolean grapheGenere;
//Constructeur et autres méthodes
protected void genereGraphe() {
this.graphe = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
this.bufferGraphe = this.graphe.createGraphics();
// Dessin dans this.bufferGraphe
this.grapheGenere = true;
}
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
System.out.println("ImageUpdate : PanelGrapheLineaire");
boolean ret = super.imageUpdate(img, infoflags, x, y, w, h);
if (ret && this.grapheGenere) {
// Invocation souhaitée en cas d'image complètement affichée
}
return ret;
}
protected void paintComponent(Graphics g) {
System.out.println("PaintComponent : PanelGrapheLineaire, l=" + this.getWidth() + ", h=" + this.getHeight());
if (!this.grapheGenere) {// Si première génération, on crée l'image
this.genereGraphe();
}
((Graphics2D) g).setBackground(this.getBackground());
g.clearRect(0, 0, this.getWidth(), this.getHeight());
this.prepareImage(this.graphe, this.getWidth(), this.getHeight(), this);
g.drawImage(this.graphe, 0, 0, this);
System.out.println("PaintComponent : PanelGrapheLineaire DONE");
}
} |
Partager