F
Flip
I cannot seem to see when the stop() and start() methnods fire when using
this applet. I thought when the focus moved away from IE6, the stop would
fire and then when it got the focus again the start() would fire. Is that
not the case?
Any ideas on what I could be doing wrong? Thank you.
--------------code
snippet----------------------------------------------------------
package com.pch.webapp;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Toolkit;
public class ScrollingMessage extends Applet implements Runnable{
String message;
private int dx;
private int dy;
private boolean isStandalone = false;
private boolean running;
private Thread worker;
private int x = 25;
private int y = 25;
public ScrollingMessage(){
}
public static void main( String[] args ){
ScrollingMessage applet = new ScrollingMessage();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle( "Applet Frame" );
frame.add( applet, BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 400, 320 );
Dimension d = Toolkit.getDefaultToolkit()
.getScreenSize();
frame.setLocation(
( d.width - frame.getSize().width ) / 2,
( d.height - frame.getSize().height ) / 2
);
frame.setVisible( true );
}
// Destroy the applet
public void destroy(){
System.err.println( "destroy" );
worker = null;
}
// Get Applet information
public String getAppletInfo(){
System.err.println( "getAppletInfo" );
return "Applet Information";
}
public int getDx(){
return dx;
}
public int getDy(){
return dy;
}
public String getMessage(){
return message;
}
// Get a parameter value
public String getParameter( String key, String def ){
return isStandalone ? System.getProperty( key, def )
: ( ( getParameter( key ) != null ) ? getParameter( key ) :
def );
}
// Get parameter info
public String[][] getParameterInfo(){
System.err.println( "getParameterInfo" );
String[][] pinfo = {{"aMessage", "String", ""}
, };
return pinfo;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
// Initialize the applet
public void init(){
System.err.println( "init" );
try{
message = this.getParameter( "aMessage", "There's no place like
127.0.0.1." );
} catch( Exception e ){
e.printStackTrace();
}
try{
jbInit();
} catch( Exception e ){
e.printStackTrace();
}
}
public void paint( Graphics g ){
System.err.println( "painting" );
g.drawString( this.getMessage(), getX(), getY() );
}
public void run(){
while( isRunning() ){
setX( getX() + 1 );
setDx( getDx() );
this.repaint();
try{
System.err.println( "\tabout to sleep" );
worker.sleep( 250 );
} catch( InterruptedException ex ){
ex.printStackTrace();
}
}
System.err.println( "done" );
}
public void setDx( int dx ){
this.dx = dx;
}
public void setDy( int dy ){
this.dy = dy;
}
public void setX( int x ){
this.x = x;
}
public void setY( int y ){
this.y = y;
}
// Start the applet
public void start(){
System.err.println( "start" );
if( worker == null ){
worker = new Thread( this );
}
setRunning( true );
worker.start();
}
// Stop the applet
public void stop(){
System.err.println( "stop" );
if( worker != null ){
setRunning( false );
}
}
private boolean isRunning(){
return running;
}
// Component initialization
private void jbInit() throws Exception{
}
private synchronized void setRunning( boolean running ){
this.running = running;
}
}
this applet. I thought when the focus moved away from IE6, the stop would
fire and then when it got the focus again the start() would fire. Is that
not the case?
Any ideas on what I could be doing wrong? Thank you.
--------------code
snippet----------------------------------------------------------
package com.pch.webapp;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Toolkit;
public class ScrollingMessage extends Applet implements Runnable{
String message;
private int dx;
private int dy;
private boolean isStandalone = false;
private boolean running;
private Thread worker;
private int x = 25;
private int y = 25;
public ScrollingMessage(){
}
public static void main( String[] args ){
ScrollingMessage applet = new ScrollingMessage();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle( "Applet Frame" );
frame.add( applet, BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 400, 320 );
Dimension d = Toolkit.getDefaultToolkit()
.getScreenSize();
frame.setLocation(
( d.width - frame.getSize().width ) / 2,
( d.height - frame.getSize().height ) / 2
);
frame.setVisible( true );
}
// Destroy the applet
public void destroy(){
System.err.println( "destroy" );
worker = null;
}
// Get Applet information
public String getAppletInfo(){
System.err.println( "getAppletInfo" );
return "Applet Information";
}
public int getDx(){
return dx;
}
public int getDy(){
return dy;
}
public String getMessage(){
return message;
}
// Get a parameter value
public String getParameter( String key, String def ){
return isStandalone ? System.getProperty( key, def )
: ( ( getParameter( key ) != null ) ? getParameter( key ) :
def );
}
// Get parameter info
public String[][] getParameterInfo(){
System.err.println( "getParameterInfo" );
String[][] pinfo = {{"aMessage", "String", ""}
, };
return pinfo;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
// Initialize the applet
public void init(){
System.err.println( "init" );
try{
message = this.getParameter( "aMessage", "There's no place like
127.0.0.1." );
} catch( Exception e ){
e.printStackTrace();
}
try{
jbInit();
} catch( Exception e ){
e.printStackTrace();
}
}
public void paint( Graphics g ){
System.err.println( "painting" );
g.drawString( this.getMessage(), getX(), getY() );
}
public void run(){
while( isRunning() ){
setX( getX() + 1 );
setDx( getDx() );
this.repaint();
try{
System.err.println( "\tabout to sleep" );
worker.sleep( 250 );
} catch( InterruptedException ex ){
ex.printStackTrace();
}
}
System.err.println( "done" );
}
public void setDx( int dx ){
this.dx = dx;
}
public void setDy( int dy ){
this.dy = dy;
}
public void setX( int x ){
this.x = x;
}
public void setY( int y ){
this.y = y;
}
// Start the applet
public void start(){
System.err.println( "start" );
if( worker == null ){
worker = new Thread( this );
}
setRunning( true );
worker.start();
}
// Stop the applet
public void stop(){
System.err.println( "stop" );
if( worker != null ){
setRunning( false );
}
}
private boolean isRunning(){
return running;
}
// Component initialization
private void jbInit() throws Exception{
}
private synchronized void setRunning( boolean running ){
this.running = running;
}
}