import java.applet.*; import java.awt.*; import java.awt.event.*; public class ImgColEvCy extends Applet implements ActionListener { private Button tester1, tester2, tester3; private int count = 0; private int Buttn1Count = 0; private int Buttn2Count = 0; private int Buttn3Count = 0; private int TotCycles, CyclesInit = 0, CyclesStart = 0, CyclesStop, CyclesDestroy = 0; private boolean b; private Image image1, image2; public void init() { TotCycles = 1; CyclesInit++; tester1 = new Button("Red"); add(tester1); tester1.addActionListener(this); tester2 = new Button("Yellow"); add(tester2); tester2.addActionListener(this); tester3 = new Button("Green"); add(tester3); tester3.addActionListener(this); setBackground(Color.cyan); image1 = getImage(getDocumentBase(), "stopsign.gif"); image2 = getImage(getDocumentBase(), "walksign.gif"); } public void start() { TotCycles++; CyclesStart++; } public void actionPerformed(ActionEvent event) { if (event.getSource() == tester1) { Buttn1Count = 1; Buttn2Count = 0; Buttn3Count = 0; } if (event.getSource() == tester2) { Buttn1Count = 0; Buttn2Count = 1; Buttn3Count = 0; } if (event.getSource() == tester3) { Buttn1Count = 0; Buttn2Count = 0; Buttn3Count = 1; } repaint(); } public void paint(Graphics g) { if ( Buttn1Count == 1 ) { g.setColor(Color.red); g.fillOval(50, 50, 40, 40); g.setColor(Color.green); g.fillOval(150, 150, 40, 40); g.setColor(Color.lightGray); g.fillOval(50, 100, 40, 40); g.fillOval(150, 50, 40, 40); g.fillOval(50, 150, 40, 40); g.fillOval(150, 100, 40, 40); b = g.drawImage(image1, 200, 75, 100, 100, this); } if ( Buttn2Count == 1 ) { g.setColor(Color.yellow); g.fillOval(50, 100, 40, 40); g.fillOval(150, 100, 40, 40); g.setColor(Color.lightGray); g.fillOval(50, 50, 40, 40); g.fillOval(150, 50, 40, 40); g.fillOval(50, 150, 40, 40); g.fillOval(150, 150, 40, 40); } if ( Buttn3Count == 1 ) { g.setColor(Color.green); g.fillOval(50, 150, 40, 40); g.setColor(Color.red); g.fillOval(150, 50, 40, 40); g.setColor(Color.lightGray); g.fillOval(50, 100, 40, 40); g.fillOval(150, 150, 40, 40); g.fillOval(50, 50, 40, 40); g.fillOval(150, 100, 40, 40); b = g.drawImage(image2, 200, 75, 100, 100, this); } g.setColor(Color.red); g.drawString("Init : "+CyclesInit, 320, 60); g.drawString("Start : "+CyclesStart, 320, 80); g.drawString("Stop : "+CyclesStop, 320, 100); g.drawString("Destroy : "+CyclesDestroy, 320, 120); g.drawString("Total : "+TotCycles, 320, 150); } public void stop() { TotCycles++; CyclesStop++; } public void destroy() { TotCycles++; CyclesDestroy++; } }