home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-04 | 3.4 KB | 115 lines |
- /*
- This class is a basic extension of the Applet class. It would generally be
- used as the main class with a Java browser or the AppletViewer. But, an instance
- can be added to a subclass of Container. To use this applet with a browser or
- the AppletViewer, create an html file with the following code:
-
- <HTML>
- <HEAD>
- <TITLE>ThreadX window</TITLE>
- </HEAD>
- <BODY>
-
- <APPLET CODE="ThreadX.class" WIDTH=380 HEIGHT=180></APPLET>
-
- </BODY>
-
- </HTML>
-
- You can add controls to ThreadX with Cafe Studio, but not menus. (Menus
- can only be added to subclasses of Frame.)
- */
-
- import java.awt.*;
-
- public class ThreadX extends java.applet.Applet {
-
- AnimationPanel panelOne, panelTwo, panelThree;
-
- public void init() {
-
- //{{INIT_CONTROLS
- setLayout(new BorderLayout(0,0));
- addNotify();
- resize(500,280);
- animationArea = new java.awt.Panel();
- animationArea.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
- animationArea.resize(animationArea.preferredSize());
- animationArea.move(28, 6);
- add("Center", animationArea);
- mainButtonPanel = new java.awt.Panel();
- mainButtonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,5,5));
- mainButtonPanel.resize(mainButtonPanel.preferredSize());
- mainButtonPanel.move(28, 172);
- add("South", mainButtonPanel);
- aStartButton = new java.awt.Button("All Start");
- aStartButton.resize(aStartButton.preferredSize());
- aStartButton.move(76, 200);
- mainButtonPanel.add(aStartButton);
- aStopButton = new java.awt.Button("All Stop");
- aStopButton.resize(aStopButton.preferredSize());
- aStopButton.move(198, 200);
- mainButtonPanel.add(aStopButton);
- resetButton = new java.awt.Button("Reset");
- resetButton.resize(resetButton.preferredSize());
- resetButton.move(318, 200);
- mainButtonPanel.add(resetButton);
- //}}
-
- animationArea.setLayout(new GridLayout(1,3));
-
- //Add three new AnimationPanels with the specified color and delay
- //to the animationArea.
- animationArea.add(panelOne = new AnimationPanel(Color.red, 75));
- animationArea.add(panelTwo = new AnimationPanel(Color.white, 100));
- animationArea.add(panelThree = new AnimationPanel(Color.blue, 125));
-
- super.init();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == Event.ACTION_EVENT && event.target == resetButton) {
- Reset();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == aStopButton) {
- AllStop();
- return true;
- }
- else
- if (event.id == Event.ACTION_EVENT && event.target == aStartButton) {
- AllStart();
- return true;
- }
-
- return super.handleEvent(event);
- }
-
- //{{DECLARE_CONTROLS
- java.awt.Panel animationArea;
- java.awt.Panel mainButtonPanel;
- java.awt.Button aStartButton;
- java.awt.Button aStopButton;
- java.awt.Button resetButton;
- //}}
-
- public void AllStart() {
- panelOne.StartAnimation();
- panelTwo.StartAnimation();
- panelThree.StartAnimation();
- }
- public void AllStop() {
- panelOne.StopAnimation();
- panelTwo.StopAnimation();
- panelThree.StopAnimation();
- }
- public void Reset() {
- panelOne.ResetAnimation();
- panelTwo.ResetAnimation();
- panelThree.ResetAnimation();
- }
- }
-
-
-