weird applet bug (IE related?)

B

Blah Blah

i've been getting a strange bug when running an applet in internet explorer
on windows. i'm not sure if it's windows or internet explorer related, but
it doesn't happen on my linux box with netscape. the problem is this:

i have an applet which opens a frame. the frame has a default button
(btnOK), which opens a JOptionPane. so far so good. if, however, the user
holds down the Enter key so that it auto-repeats, after cycling through
these a couple of times IE freezes and has to be shutdown from the task
manager. i had similar behavior on the linux box until i put a simple
semaphore in, but that doesn't seem to have helped with windows. here's the
code:

package view;
import java.awt.event.*;
import javax.swing.*;
public class TestLauncher extends JApplet
{
private static boolean okSemaphore = false;
private Tester tester;

public void init() {
super.init();
tester = new Tester();
}
public void start() {
tester.show();
}
public void stop() {}
public void destroy() {}

private final class Tester extends JFrame {
public Tester() {
super("Tester");

JPanel pnlContent = (JPanel)getContentPane();
JButton btnTest = new JButton("OK");
btnTest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
doOK();
}});
pnlContent.add(btnTest);
getRootPane().setDefaultButton(btnTest);
pack();
}
private final void doOK() {
if (okSemaphore == false) {
okSemaphore = true;
int result = JOptionPane.showOptionDialog(
this,
"Message",
"Tester",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
new Object[] {"OK","Override"},
"OK");
okSemaphore = false;
}
}
}
}

any ideas?

daniel
 
D

dhek bhun kho

Hello Daniel,

i've been getting a strange bug when running an applet in internet explorer
on windows. i'm not sure if it's windows or internet explorer related, but
it doesn't happen on my linux box with netscape. the problem is this:

The thread scheduler (is this the correct term?) works differently under
Windows and Linux. I haven't got a reference for you, but under Windows
Java is allowed to modify thread priorities and such. Windows also
preempts the threads based on their priority.

Linux doesn't. For example, if you would start a number of identical threads in
consecutive order using Linux (this should be the same on the 2.2 and 2.4
kernels) they would finish in that order; irrespective of the assigned
priorities.

Windows actually assigns the threads more time slices when a thread has a
higher priority.

The point: multi-tasking is handled differently even when running the same
JRE, based on the underlying platform.

i have an applet which opens a frame. the frame has a default button
(btnOK), which opens a JOptionPane. so far so good. if, however, the user
holds down the Enter key so that it auto-repeats, after cycling through
these a couple of times IE freezes and has to be shutdown from the task
manager. i had similar behavior on the linux box until i put a simple
semaphore in, but that doesn't seem to have helped with windows. here's the
code:

(I haven't compiled your code) Just a silly question on my part : if
adding a semaphore fixes the problem, and the problem seems to be a
dead-lock, why aren't you using the synchronization facilities from Java
itself?
package view;
import java.awt.event.*;
import javax.swing.*;
public class TestLauncher extends JApplet
{
private static boolean okSemaphore = false;
private Tester tester;

public void init() {
super.init();
tester = new Tester();
}
public void start() {
tester.show();
}
public void stop() {}
public void destroy() {}

private final class Tester extends JFrame {
public Tester() {
super("Tester");

JPanel pnlContent = (JPanel)getContentPane();
JButton btnTest = new JButton("OK");
btnTest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
doOK();
}});
pnlContent.add(btnTest);
getRootPane().setDefaultButton(btnTest);
pack();
}
private final void doOK() {
if (okSemaphore == false) {
okSemaphore = true;
int result = JOptionPane.showOptionDialog(
this,
"Message",
"Tester",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
new Object[] {"OK","Override"},
"OK");
okSemaphore = false;
}
}
}
}

any ideas?

Try:

private synchronized final void doOK()
{
... (code) ...
}

Does this fix it? (it should, if it does not: blame it on Swing) You can
always trace it with the debugger.

I hope I am not writing any nonsensical gibbering.

Greets.
 
B

Blah Blah

actually, it's not a semaphore per se, it's more of a way of making sure
that subsequent calls are ignored. i tried (just now) using the code you
suggested, which unfortunately caused it to lock up on all platforms ;)

after a little more testing, my current hypothesis is that under Windows,
the JOptionPane doesn't know how to correctly deal with an auto-repeat
"enter". i guess it's time to 1) submit a bug report (how?), and 2) change
all of my JOptionPanes to JDialogs...

thanks for the help!

dhek bhun kho said:
Hello Daniel,

i've been getting a strange bug when running an applet in internet explorer
on windows. i'm not sure if it's windows or internet explorer related, but
it doesn't happen on my linux box with netscape. the problem is this:

The thread scheduler (is this the correct term?) works differently under
Windows and Linux. I haven't got a reference for you, but under Windows
Java is allowed to modify thread priorities and such. Windows also
preempts the threads based on their priority.

Linux doesn't. For example, if you would start a number of identical threads in
consecutive order using Linux (this should be the same on the 2.2 and 2.4
kernels) they would finish in that order; irrespective of the assigned
priorities.

Windows actually assigns the threads more time slices when a thread has a
higher priority.

The point: multi-tasking is handled differently even when running the same
JRE, based on the underlying platform.

i have an applet which opens a frame. the frame has a default button
(btnOK), which opens a JOptionPane. so far so good. if, however, the user
holds down the Enter key so that it auto-repeats, after cycling through
these a couple of times IE freezes and has to be shutdown from the task
manager. i had similar behavior on the linux box until i put a simple
semaphore in, but that doesn't seem to have helped with windows. here's the
code:

(I haven't compiled your code) Just a silly question on my part : if
adding a semaphore fixes the problem, and the problem seems to be a
dead-lock, why aren't you using the synchronization facilities from Java
itself?
package view;
import java.awt.event.*;
import javax.swing.*;
public class TestLauncher extends JApplet
{
private static boolean okSemaphore = false;
private Tester tester;

public void init() {
super.init();
tester = new Tester();
}
public void start() {
tester.show();
}
public void stop() {}
public void destroy() {}

private final class Tester extends JFrame {
public Tester() {
super("Tester");

JPanel pnlContent = (JPanel)getContentPane();
JButton btnTest = new JButton("OK");
btnTest.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev){
doOK();
}});
pnlContent.add(btnTest);
getRootPane().setDefaultButton(btnTest);
pack();
}
private final void doOK() {
if (okSemaphore == false) {
okSemaphore = true;
int result = JOptionPane.showOptionDialog(
this,
"Message",
"Tester",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
new Object[] {"OK","Override"},
"OK");
okSemaphore = false;
}
}
}
}

any ideas?

Try:

private synchronized final void doOK()
{
... (code) ...
}

Does this fix it? (it should, if it does not: blame it on Swing) You can
always trace it with the debugger.

I hope I am not writing any nonsensical gibbering.

Greets.
 
T

Tim Tyler

: Since all of you have been discussing about applets and IE, I have found
: something that might interest you.
: Recently, I got a new PC with Windows XP. In the past, if I made an
: update on an applet, usually I can hit "ctrl-Refresh button" or
: "shift-Refresh button" to reload the applet. However, this did not
: work on my current IE on XP.
: Any idea why?

Are you using Sun's Java plugin? Redutedly that's shipped by some OEMs
these days.

I don't believe it responds to this signal.
 
L

Liu, Chunyen

No, the applet is entirely in JDK 1.0.2 to maintain its compatibility
throughout most web browsers without any plug-ins.

Wonder how most of you do to refresh an updated applet.
Of course, I know I can use "appletviewer" to do that. Or I can
clean the cache and close the rbowser and re-open it again.
But I used to be able to do ctrl-Refresh in the past when I still had
Windows 2000 and Me.
 
T

Tim Tyler

:> : Since all of you have been discussing about applets and IE, I have
:> : found something that might interest you.
:> : Recently, I got a new PC with Windows XP. In the past, if I made
:> : an update on an applet, usually I can hit "ctrl-Refresh button" or
:> : "shift-Refresh button" to reload the applet. However, this did
:> : not work on my current IE on XP.
:> : Any idea why?
:>
:> Are you using Sun's Java plugin? Redutedly that's shipped by some
:> OEMs these days.
:>
:> I don't believe it responds to this signal.

: No, the applet is entirely in JDK 1.0.2 to maintain its compatibility
: throughout most web browsers without any plug-ins.

It doesn't matter what API your applet is written to -
what matters is which JVM IE is using to handle applets.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top