import java.applet.Applet; import java.awt.event.*; import java.awt.*; /*Applet 5 is the same as Applet 4 except that it implements double buffering. For complicated graphical pictures, double makes for much better plotting. For the simple pictures drawn in this applet, it doesn't make much difference. However, it seems reasonable to introduce it now, in a simple setting, since it is extremely useful in more complicated applets. Another new feature of this applet is the introduction of an auxilliary class in which the graphics are drawn*/ public class test1 extends Applet { PictureCanvas P; //the auxilliary graphics class public void init() { setBackground(Color.black); P=new PictureCanvas(); P.resize(300,320); add(P); } } /*This is the class which implements the double buffering. The idea is to override the update command, so as to have the new picture drawn all at once. */ class DBCanvas extends Canvas { public void update(Graphics g) { Graphics g2; Image offscreen = null; offscreen = createImage(size().width, size().height); g2 = offscreen.getGraphics(); paint(g2); g.drawImage(offscreen, 0, 0, this); g2.dispose(); offscreen.flush(); } } class PictureCanvas extends DBCanvas implements MouseListener { Color col; PictureCanvas() { addMouseListener(this); setBackground(Color.black); col=Color.red; } public void paint(Graphics g) { g.setFont(new Font("Helvetica",Font.PLAIN,40)); g.setColor(Color.yellow); g.drawString("Rich: Applet 5",10,40); g.setFont(new Font("Helvetica",Font.PLAIN,20)); g.drawString("Click on the triangle",10,255); g.drawString("to change its color.",10,280); g.setColor(col); int x[]={100,100,200}; int y[]={100,200,200}; g.fillPolygon(x,y,3); } public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseClicked(MouseEvent e) { e.consume(); if((e.getX()>100)&&(e.getY()<200)&&(e.getX()