weird applet bug (IE related?)

Discussion in 'Java' started by Blah Blah, Jul 2, 2003.

  1. Blah Blah

    Blah Blah Guest

    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
     
    Blah Blah, Jul 2, 2003
    #1
    1. Advertising

  2. Hello Daniel,

    "Blah Blah" <>, Wed, 02 Jul 2003 15:14:42 -0400:

    > 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.

    >
    > daniel


    I hope I am not writing any nonsensical gibbering.

    Greets.
     
    dhek bhun kho, Jul 2, 2003
    #2
    1. Advertising

  3. Blah Blah

    Blah Blah Guest

    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" <> wrote in message
    news:p...
    > Hello Daniel,
    >
    > "Blah Blah" <>, Wed, 02 Jul 2003 15:14:42 -0400:
    >
    > > 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.
    >
    > >
    > > daniel

    >
    > I hope I am not writing any nonsensical gibbering.
    >
    > Greets.
     
    Blah Blah, Jul 3, 2003
    #3
  4. Blah Blah

    Tim Tyler Guest

    Re: applet and IE on XP

    Liu, Chunyen <> wrote:

    : 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.
    --
    __________
    |im |yler http://timtyler.org/
     
    Tim Tyler, Jul 5, 2003
    #4
  5. Blah Blah

    Liu, Chunyen Guest

    Re: applet and IE on XP

    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.

    > -----Original Message-----
    > From: (Address not verified)
    > [SMTP:] On Behalf Of Tim Tyler
    > Posted At: Saturday, July 05, 2003 6:27 AM
    > Posted To: comp.lang.java.programmer
    > Conversation: weird applet bug (IE related?)
    > Subject: Re: applet and IE on XP
    >
    > Liu, Chunyen <> wrote:
    >
    > : 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.
    > --
    > __________
    > |im |yler http://timtyler.org/
     
    Liu, Chunyen, Jul 7, 2003
    #5
  6. Blah Blah

    Tim Tyler Guest

    Re: applet and IE on XP

    Liu, Chunyen <> wrote or quoted:
    :> Liu, Chunyen <> wrote:

    :> : 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.
    --
    __________
    |im |yler http://timtyler.org/
     
    Tim Tyler, Jul 8, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hans De Schrijver

    Weird error related to User class

    Hans De Schrijver, Jun 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,627
  2. Karl Core
    Replies:
    5
    Views:
    433
    Toby Inkster
    Jan 29, 2005
  3. Maxwell Hammer
    Replies:
    7
    Views:
    658
    Peter Hansen
    Jun 18, 2005
  4. dorayme
    Replies:
    1
    Views:
    640
    richard
    Jan 21, 2011
  5. richard
    Replies:
    0
    Views:
    601
    richard
    Jan 21, 2011
Loading...

Share This Page