★ wanayoo — archive 1999 http://www.wdvl.com/Authoring/Scripting/Tutorial/exercise9.htmlNouvelle recherche | Portail wanayoo
Click Here! logo
internet.com
Join the free
WDVL newsletter!

home

Exercise Nine

Exercise Nine

  • Okay, let's make our simple example from last exercise handle events using the 1.1 methodology:

    [Example]

    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:

Beans Event Listeners
Table of Contents
Adapters

Up to => Home / Authoring / Scripting / Tutorial


internet.com
e-commerce


Click Here!

Copyright 1999-2000 internet.com Corp. Legal Notices. Privacy Policy.

www.internet.com