Re: opening a window from an applet..



Thomas Hawtin wrote:
Frances wrote:

when you open a window from an applet (I mean JApplet) does that window also have to be an applet? if not then what? JFrame? (public class [class] extends JFrame?) if it's a JFrame instead of an applet does it still have to have init() method? or does it have to have main() method instead? I'm confused about this... can u pls point to where I can read up on this in java.sun.. (a lot of things they explain about applets is very different for JApplets.. and sometimes when they're explaining something about applets I don't know if what they're talking about also applies to JApplets..)
(can I open a swing window from an applet? or does it have to be from a JApplet?)


You have a few choices:

o Open a new browser window with AppletContext.showDocument (which might or might not work). In that case you would have a another applet embedded in the HTML page.

o Open a Frame/JFrame. Which is a frame like any other. Because you have a security manager installed, it'll have a little banner to notify the user that it is not to be trusted. There is no init or main methods in JFrame, and there doesn't need to be. Just create it and call setVisible(true) on it (from the Event Dispatch Thread). You don't even need to extend JFrame except in specialist cases. A problem with this is that you don't know where that applet is and nor do you have much control over z-order.

 o Use JInternalFrames to create an MDI within the applet.

Tom Hawtin

thank you very much.. other problem I have is I don't know what Event-Dispatch Thread is (I saw this for the first time in java.sun, here..
http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html


and well, still tyring to figure it out..

(I'm tyring to open a new window from a JApplet, and, depending on content in the new window, the JApplet that's sup. to open the window can't find the class..

this is class I need to open in a new window from an applet..
http://www.francesdelrio.com/java/IM.java
(also, is window-opening code the same for a JApplet as it is for an applet?)


I changed "extends JApplet" to "extends JFrame" in window I need to open, but the file that opens the window can't find this class.. and if I run class from command-line I get this error:
Exception in thread "main" java.lang.NoSuchMethodError: main
(which is why I asked if you have to have a main method if yr swing window is not an applet..)


to open window:

 JFrame window;
window = new IM("New Window");

public void actionPerformed(ActionEvent ae) {
	if (!window.isVisible()) {
	window.setVisible(true);
	}
	return;
     }

is this right?

(if not I guess I need to figure out event-dispatch thread.. oh brother... another two hours until I figure that one out..
I don't always find explanations in java.sun very clear..)
I have done the usu. implements Runnable stuff w/no problems, but this is different, right? (javax.swing.SwingUtilities..)
again, thank you very much for yr help...


.



Relevant Pages

  • Re: opening a window from an applet..
    ... (public class extends JFrame?) ... if it's a JFrame instead of an applet does it still have to have initmethod? ... (can I open a swing window from an applet? ... a new window from an applet this is simply for a chat app applet, chat window opens in a new window (new window doesn't mean a separate app.. ...
    (comp.lang.java.gui)
  • Re: Force New Window to Open Instead of Taking Over Existing One
    ... > have something open in another window, it always opens in that window ... > litte applet window! ... IE picks the first window open in the task bar to use in both ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Force New Window to Open Instead of Taking Over Existing One
    ... >> have something open in another window, it always opens in that window ... >> litte applet window! ... IE picks the first window open in the task bar to use in both ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Please...Applet frame resize problem
    ... > All I'm trying to do is open a window that displays my applet and lets me ... You say you want to display your applet ... Having something 'pop-up' is also considered ... launch applications* ...
    (comp.lang.java.programmer)
  • Force New Window to Open Instead of Taking Over Existing One
    ... have something open in another window, it always opens in that window ... if you click on a web link somewhere, it opens it in the litte applet ... IE picks the first window open in the task bar to use in both ...
    (microsoft.public.windows.inetexplorer.ie6.browser)