2

Is there a possibility to add an Applet (JBufferedApplet to be specific) to a JFrame (or an AWT Frame).

I've allready tried this, but it looks like the Applet simply doesn't run. It makes the background color of the JFrame gray (the same color of the Applet), but nothing more.

There is no possibility of changing the JApplet to a JPanel (I don't have access to the code).

All that has to be done for the moment is add the Applet to a JFrame/AWT Frame

This is the code I have so far:

import javax.swing.JFrame;

public class FormFrame extends JFrame {

    public FormFrame() {
        super("Oracle Forms");
        Main m = new Main();
        getContentPane().add(m); //add(m);
        setSize(800, 600);
        setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new FormFrame();
    }

}

All it gives is the background color of the Applet. It looks like the Applet doesn't run.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Arolition
  • 145
  • 1
  • 2
  • 6
  • Didn't you have another question on adding an applet to a frame? BTW - specifically what is JBufferedApplet? Got an URL to the site where it is distributed? Access to the URL of a working version? – Andrew Thompson Mar 27 '12 at 23:33
  • Yes, there was another thread, but when I tried to edit it, to add the JFrame I was working on, there was a problem. And I couldn't find the thread anymore, so I had to open a new one. JBufferedApplet is developed by Oracle for Oracle Forms specifically (I think). It just inherets from Applet. I also don't know much about it, because there is not much information around about it. – Arolition Mar 28 '12 at 08:39

1 Answers1

4

You could always try to add the applet's contentPane, something like:

public class FormFrame extends JFrame {

   public FormFrame() {
       super("Oracle Forms");
       MyApplet myApplet = new MyApplet();
       myApplet.start();
       myApplet.init();
       getContentPane().add(myApplet.getContentPane()); 
       setSize(800, 600); // not sure about this.  Usually better to call pack();
       setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
       setVisible(true);
   }

   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            new FormFrame();
         }
      });
   }
}

Just don't forget to call the applet's init() method to allow it to initialize all its components.

Edit: changes made for thread safety as per trashgod's excellent recommendation.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • I've tried that, didn't fix it. I've also tried adding `myApplet.start()` , but also negative. I've tried printing out the AppletContext, but it gives a NullPointerException. When I try to run the Applet seperatly in Netbeans, it works perfectly. So for some reason it seems that the Applet just doesn't get executed. – Arolition Mar 27 '12 at 14:54
  • 1
    @Arolition: what if you call the applet's `start()` and `init()` methods both before extracting the applet's contentPane()? – Hovercraft Full Of Eels Mar 27 '12 at 14:57
  • 1
    Applets, too, must respect [Initial Threads](http://download.oracle.com/javase/tutorial/uiswing/concurrency/initial.html). – trashgod Mar 27 '12 at 16:14
  • @trashgod: changes made. Thanks! – Hovercraft Full Of Eels Mar 27 '12 at 17:11
  • @Arolition: any different with changes? – Hovercraft Full Of Eels Mar 27 '12 at 17:11
  • "*I've tried printing out the AppletContext,"* What applet context? Did you create an implementation of it and set it as the context via the stub? I thought we'd made some progress in your other thread (that now seems to be gone :( ). – Andrew Thompson Mar 27 '12 at 23:38
  • 1
    @Hovercraft AFAIR from another (now vanished) thread(1), this applet not only has parameters that are passed to the applet, but interacts with JS (declares MAYSCRIPT). An applet launched in a frame does not have a valid applet context (to get parameters) & no support for JS. 1) Not that you could know that extra information. – Andrew Thompson Mar 27 '12 at 23:42
  • I'm slowly getting there (with your help). The Parameter problem got solved with overriding the `getParameter()` method. The Applet gets now shown perfectly in the JFrame. But for some reason there is still a problem with the further execution of this Applet. At [http://pastebin.com/R7xXwLuy](http://pastebin.com/R7xXwLuy) can be found what I allready have. – Arolition Mar 28 '12 at 09:51
  • I've got it working after all. Moving `m.start();` after `setVisible(true);` (at the end of the constructor) solves the problem. Thanks everyone for your help! – Arolition Mar 28 '12 at 10:08