Exercise Nine
import java.awt.*; import java.awt.event.*; public class Event11Example extends Panel implements ActionListener { public Panel displayPanel; public Button colorButton; public Color[] colors = {Color.black, Color.red, Color.yellow, Color.green}; private int counter = 0; public Event11Example() { setLayout(new BorderLayout()); displayPanel = new Panel(); add("Center", displayPanel); colorButton = new Button("Change Color"); colorButton.addActionListener(this); add("South", colorButton); } public static void main(String[] args) { Frame baseFrame = new Frame(); Event11Example ee = new Event11Example(); baseFrame.add("Center", ee); baseFrame.reshape(10,10,200,200); baseFrame.setTitle("Event Example"); baseFrame.show(); } public void actionPerformed(ActionEvent evt) { displayPanel.setBackground(colors[counter]); if (counter <=2) counter++; else counter =0; } } Additional Resources:
![]() Table of Contents Adapters ![]() |
Hosted by Graphics & Media Lab
http://graphics.cs.msu.su |
![]() |
mailto: Laboratory |