Board index » jbuilder » stopping an applet when html page is minimized

stopping an applet when html page is minimized


2004-06-26 07:40:34 AM
jbuilder6
Hello
Could somebody please look at the following code and explain why the applet
does not stop (sound continues) when the browser it is displayed looses
focus? And how the status bar message can be made to display longer?
Many thanks
J.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
public class SoundPlayer extends JApplet {
boolean isStandalone = false;
String url;
boolean loop;
String status;
URL source;
AudioClip soundFile;
//debug: StringBuffer buffer;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public SoundPlayer() {
}
//Initialize the applet
public void init() {
//debug: buffer = new StringBuffer();
addItem("initializing... ");
try {
url = this.getParameter("url", "");
}
catch(Exception e) {
e.printStackTrace();
}
try {
source = new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
soundFile = this.getAudioClip(source);
try {
loop = Boolean.valueOf(this.getParameter("loop",
"false")).booleanValue();
}
catch(Exception e) {
e.printStackTrace();
}
try {
status = this.getParameter("status", "message to display in status
bar");
}
catch(Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Start the applet
public void start() {
//debug: addItem("starting... ");
loop ? soundFile.loop() : soundFile.play();
}
public void stop() {
//debug: addItem("stopping... ");
soundFile.stop();
}
public void destroy() {
//debug: addItem("preparing for unloading...");
}
/*debug:
void addItem(String newWord) {
System.out.println(newWord);
buffer.append(newWord);
repaint();
}
public void paint(Graphics g) {
//Draw the current string inside the rectangle.
g.drawString(buffer.toString(), 5, 15);
}
*/
//Component initialization
private void jbInit() throws Exception {
this.setSize(new Dimension(400,300));
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
String[][] pinfo =
{
{"url", "String", "An absolute URL giving the location of the audio
clip"},
{"loop", "boolean", "Whether the audio clip should loop. Default is
false"},
{"status", "String", "Status bar message to be displayed"},
};
return pinfo;
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName())
;
}
catch(Exception e) {
}
}
}
 
 

Re:stopping an applet when html page is minimized

Hi,
You haven't said which browser you are using. In Internet Explorer, the stop
method is not called when the browser loses focus, but it is in Sun's Applet
viewer.
If you look at this forum on Sun's web site, the 5th reply to the link below
gives a solution. I've tested it and it works for me.
forum.java.sun.com/thread.jsp
I've no idea about the status bar message.
Arth
"Thomas J. Barnett" < XXXX@XXXXX.COM >wrote in message
Quote
Hello

Could somebody please look at the following code and explain why the
applet
does not stop (sound continues) when the browser it is displayed looses
focus? And how the status bar message can be made to display longer?

Many thanks

J.

 

Re:stopping an applet when html page is minimized

"Arthur Ore" wrote
Quote
If you look at this forum on Sun's web site, the 5th reply to the link
below
gives a solution. I've tested it and it works for me.
forum.java.sun.com/thread.jsp
Hi Arthur
Following the reasoning in the link you posted I was able to solve my
problem.
Many thanks for your time.
J.
 

{smallsort}