import java.applet.Applet; import java.awt.*; import java.awt.event.*; /*Applet 4 is the same as Applet 2, except that it accepts imput from the mouse. One programs this, in general, by importing the MouseListener. When you import the MouseListener, you must specify what happens for all 5 mouse events, even if nothing happens. See below. */ public class test1 extends Applet implements MouseListener { Color col; //color of triangle public void init() { addMouseListener(this); setBackground(Color.black); col=Color.red; //initialize color } public void paint(Graphics g) { g.setFont(new Font("Helvetica",Font.PLAIN,40)); g.setColor(Color.yellow); g.drawString("Rich: Applet 4",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); /**draw triangle**/ g.setColor(col); int x[]={100,100,200}; int y[]={100,200,200}; g.fillPolygon(x,y,3); } /**mouse event methods**/ 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(); //register event if((e.getX()>100)&&(e.getY()<200)&&(e.getX()