By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

Dialog within applet hangs itself

P: n/a
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;
}
}
------------------------------------------------------------------------
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Michael wrote:
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?


Michael,

My first instinct is that the dialog is somehow sized too small or
placed off the screen or is in some other way impossible to detect.
Since it is a modal dialog this might create the issue you are seeing.
Based on your code, it looks like you are OK in setting the size (via
pack()) and in setting the location (assuming the screen size is
reported properly). I recommend printing out what the dialog says its
size and location are before showing it (also, you may want to make it
non-modal, at least for debugging purposes).

Ray

Jul 17 '05 #2

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael wrote:
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.


Hello,
I'm not absolutely sure about setVisible(true), but I know that show()
on a modal dialogue doesn't return until the dialogue is disposed.
setVisible(true) may operate the same way. Maybe you need to display
the dialogue in a new thread, or maybe you need to reorganize your
code to take this into account.

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/pDSZwxczzJRavJYRAhjuAKCCqXkW/TAuYVcLxZl4/4/fq0d9SgCg7NS9
HtSK6b3hHddX/qrjvVrQ/6E=
=YC/E
-----END PGP SIGNATURE-----
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.