Exercise Eight
import java.awt.*; public class EventExample extends Panel { public Panel displayPanel; public Button colorButton; public Color[] colors = {Color.black, Color.red, Color.yellow, Color.green}; private int counter = 0; public EventExample() { setLayout(new BorderLayout()); displayPanel = new Panel(); add("Center", displayPanel); colorButton = new Button("Change Color"); add("South", colorButton); } public static void main(String[] args) { Frame baseFrame = new Frame(); EventExample ee = new EventExample(); baseFrame.add("Center", ee); baseFrame.reshape(10,10,200,200); baseFrame.setTitle("Event Example"); baseFrame.show(); } public boolean action(Event evt, Object obj) { displayPanel.setBackground(colors[counter]); if (counter <=2) counter++; else counter =0; return super.action(evt, obj); } } ![]() Table of Contents Beans Events ![]() |
Hosted by Graphics & Media Lab
http://graphics.cs.msu.su |
![]() |
mailto: Laboratory |