import java.applet.*; import java.awt.*; import java.awt.event.*; public class PuhverApplet extends Applet implements ComponentListener{ Image puhver; Graphics puhvriG; public PuhverApplet(){ addComponentListener(this); } public void update(Graphics g){ //System.out.println("update.."); paint(g); } public final void paint(Graphics g){ //System.out.println("paint.."); if (puhver == null){ puhver = createImage(getSize().width, getSize().height); //1.1 compatible (on ka getWidth() ja ...) puhvriG = puhver.getGraphics(); } koostaPilt(puhvriG); g.drawImage(puhver, 0, 0, this); } public void koostaPilt(Graphics g){ //Siin tehakse järglasklassides kogu joonistamine. //paint meetodit ei tohi järglased puutuda. //Et anda käsk joonistada, tuleb kutsuda repaint(); } public void componentResized(ComponentEvent e){ //Invoked when the component's size changes. System.out.println( e.paramString() ); puhver = null; //järgmise paintimisega luuakse uus puhver repaint(); } public void componentMoved(ComponentEvent e){ //Invoked when the component's position changes. } public void componentHidden(ComponentEvent e){ //Invoked when the component has been made invisible. } public void componentShown(ComponentEvent e){ //Invoked when the component has been made visible. } }