Dialog within applet hangs itself

From: Michael (mike_at_dplanet.chDELETE)
Date: 10/30/03


Date: 30 Oct 2003 18:18:39 +0100

Hello

Currently I'm migrating an applet from Java 1.1 to 1.3.

Targetplattform:
Microsoft Internet Explorer 5.x with Sun's Java VM 1.3.1

Problem:
The attached applet works fine with the Microsoft VM. But when I use
Suns' VM the applet hangs after opening the dialog. And you have to
shutdown the browser with the help of the Taskmanager.

Wenn ich das angef|gte Applet starte, funktioniert es in der M

Reason:
I was able to lead back the problem to the setVisible(true) method of
the java.awt.Dialog class. This method does not return.

Question:
Does anything changed within the AWT from Java 1.1 to 1.3?

Thank you very much
Michael

--------------------------- TestDialog.java ---------------------------
/*
 * TestDialog.java
 *
 * Created on 28. Oktober 2003, 09:04
 */

package ch.softlab.sebc;

import java.awt.*;
import java.awt.event.*;

/**
 *
 * @author herrem
 */
public class TestDialog extends Dialog implements ActionListener,
WindowListener{
    
    /** Creates a new instance of TestDialog */
    private ActionListener listeners = null;
    
    public TestDialog(Frame frame) {
        super(frame);
        System.out.println("TestDialog - constructor");
        
        addWindowListener(this);
        
        TextField text = new TextField(10);
        
        Button button = new Button("ok");
        {
            button.setActionCommand("ok");
            button.addActionListener(this);
        }
        add(text, "Center");
        add(button, "South");
        
        pack();
        
        setModal(true);
    }
    
    public void actionPerformed(java.awt.event.ActionEvent e) {
        System.out.println("TestDialog - actionPerformed()");
        fireActionEvent(new ActionEvent(this, e.getID(),
e.getActionCommand()));
    }

    public void fireActionEvent(ActionEvent e) {
        if (listeners != null) {
            listeners.actionPerformed(e);
        }
    }
    
    public void addActionListener(ActionListener actionlistener) {
        listeners = AWTEventMulticaster.add(listeners, actionlistener);
    }
    
    public void setVisible(boolean flag) {
        System.out.println("TestDialog - setVisible() -> flag=" + flag);
        if (flag) {
            Dimension screensize =
Toolkit.getDefaultToolkit().getScreenSize();
            Dimension dimension = getSize();
            setLocation( (screensize.width - dimension.width) / 2,
(screensize.height - dimension.height) / 2 );
        }
        super.setVisible(flag);
    }
    
    public void windowClosing(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(), "closing"));
    }
        
    public void windowActivated(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(), "activated"));
    }
    
    public void windowClosed(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(), "closed"));
    }
    
    public void windowDeactivated(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(),
"deactivated"));
    }
    
    public void windowDeiconified(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(),
"deiconified"));
    }
    
    public void windowIconified(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(), "iconified"));
    }
    
    public void windowOpened(WindowEvent e) {
        actionPerformed(new ActionEvent(this, e.getID(), "opened"));
    }
    
}

------------------------------------------------------------------------
--------------------------- FirstApplet.java ---------------------------
/*
 * FirstApplet.java
 *
 * Created on 9. Oktober 2003, 15:51
 */

package ch.softlab.sebc;

import java.applet.*;
import java.awt.*;

/**
 *
 * @author herrem
 */
public class FirstApplet extends Applet {
    
    /** Initialization method that will be called after the applet is
loaded
     * into the browser.
     */
    private String _msg = "Hello World";
    
    public void init() {
        System.out.println("FirstApplet - init()");
    }
    
    public void start() {
        System.out.println("FirstApplet - start()");
    }
    
    public void paint(Graphics g) {
        System.out.println("FirstApplet - paint()");
        g.drawString(_msg, 25, 50);
    }
    
    public void printEmpty() {
        System.out.println("FirstApplet - print()");
        _msg = "print";
    }
    
    public void printString(String msg) {
        System.out.println("FirstApplet - printString()");
        _msg = msg;
    }
        
    
}
------------------------------------------------------------------------


Quantcast