Re: opening a window from an applet..



Frances wrote:
when you open a window from an applet (I mean JApplet) does that window also have to be an applet?
No, usually not. Applets are mainly used embedded in browers, because they are the only thing, which you can embed in a browser.
if not then what? JFrame? (public class [class] extends JFrame?)
Yes, for example (try the example below).
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?
No, there is no need for these methods, because your applet decides what method of the frame to call.
Remember: Applets have an init() method, because the browser calls init(). Frames usually have a main(String[]) method, because you usually want it to be startable from command-line, for example:
java com.mycompany.MyFrame
I'm confused about this...
Yes, I noticed ;-)
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..
What many things do you mean? I thought, the only differences between Applet and JApplet are described in the javadoc of JApplet.
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..)
JApplet is a special case of Applet. So anything specified for Applet is implicitly true also for JApplet, if not explicitly specified different.
(can I open a swing window from an applet?
I would think yes. But why should you want this?
or does it have to be from a JApplet?)

thank you..

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TestApplet extends JApplet {
    public void init() {
        JButton button = new JButton("Push me");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JFrame frame = new JFrame("Title");
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(new JTree());
                frame.pack();
                frame.setVisible(true);
            }
        });
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(button);
    }
}

--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

.


Quantcast