/* * @(#)Example_000.java * * Copyright (c) 2005 by Geekscape Pty Ltd. Some Rights Reserved. * * This software is the proprietary information of Geekscape Pty. Ltd. * Use is subject to license terms. * See http://www.geekscape.org/applet/example_000/index.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ /* ToDo: * - None, yet. */ /** *

* Simple example of using Swing within a Java Applet. *

*

* Note: Implementation thread safe = Yes (2005-08-19) *

* @author Andy Gelme * @version 1.1 */ import java.awt.Color; import java.awt.event.*; import javax.swing.*; public class Example_000 extends JApplet implements ActionListener { private JButton jButton = new JButton("Press me"); private int currentColour = 0; private static Color[] colours = { Color.CYAN, Color.GREEN, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.WHITE, Color.YELLOW, Color.RED }; public void init() { jButton.addActionListener(this); jButton.setToolTipText("I'll change colour for you !"); getContentPane().add(jButton); } public void actionPerformed( ActionEvent e) { jButton.setBackground(colours[currentColour]); currentColour = (currentColour + 1) % colours.length; } } /* ---------------------------------------------------------------------------- * * * Creative Commons License * *
* This work is licensed under a * * Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License * . * * ------------------------------------------------------------------------- */