Java Reference
In-Depth Information
Thread fThread = null;
Drop2DPanel fDropPanel;
JButton fDropButton;
/** Build the interface. **/
public void init () {
Container content - pane = getContentPane ();
Content - pane.setLayout (new BorderLayout ());
// Create an instance of DropPanel
fDropPanel = new Drop2DPanel ();
// Add the Drop2DPanel to the content pane.
Content - pane.add (BorderLayout.CENTER, fDropPanel);
// Create a button and add it
fDropButton = new JButton ("Drop");
fDropButton.addActionListener (this);
Content - pane.add (BorderLayout.SOUTH, fDropButton);
} // init
/** Start when browser is loaded or button pushed. **/
public void start () {
// If the thread reference not null then a
// thread is already running. Otherwise, create
// a thread and start it.
if (fTthread == null) {
fThread = new Thread (this);
fThread.start();
}
} // start
/** Applet's stop method used to stop thread. **/
public void stop () {
// Setting thread to null will cause loop in
// run() to finish and kill the thread.
fThread = null;
} // stop
/** Button command, **/
public void actionPerformed (ActionEvent ae) {
if (fDropPanel.isDone ()) start ();
}
/** The thread loops to draw each frame of drop. **/
public void run () {
// Disable button during drop
fDropButton.setEnabled (false);
 
Search WWH ::




Custom Search