aspose file tools*
The moose likes Applets and the fly likes applet in a JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "applet in a JFrame" Watch "applet in a JFrame" New topic
Author

applet in a JFrame

jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
Hi,

Below is my main, and my attempt to get the applet contentPane into the JFrames. But nothing shows in the JFrame. Is something wrong with my code?


public static void main(String arg[]) {
JFrame f = new JFrame();
JApplet datamartApplet = new dataMartJApplet();
datamartApplet.init();
f.setContentPane(datamartApplet.getContentPane());
f.setBounds(0,0,750,500);
f.setVisible(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
Kevin Mangold
Greenhorn

Joined: Jan 13, 2005
Posts: 18
Why not just do this?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
If you read up on the applet lifecycle, you'll see that its 'start' method needs to be called to begin execution.

If you want to run an applet as an application, have a look at the MainFrame class, which provides a better environment to do that.
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
Thank you very much, i have a follow up question.

What about a reverse situation.

I need to get a class that extends JFrame to run in an applet.

public class DataMartJFrameUI extends javax.swing.JFrame

Here's my code so far; It will load both applet and DataMartJFrameUI seperately.

public class MyApplet extends JApplet {
private DataMartJFrameUI myFrame;
public MyApplet() {
init();
}
public void init() {
DataMartJFrameUI ddf = new DataMartJFrameUI();
ddf.setVisible(true);
myFrame.setSize(500, 300);
}
}

[ April 22, 2007: Message edited by: jite eghagha ]
[ April 22, 2007: Message edited by: jite eghagha ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
Follow the link I posted, and read about the "ApplicationApplet" class. It does the opposite of MainFrame - allowing you to run an application as an applet.
jite eghagha
Ranch Hand

Joined: Oct 06, 2006
Posts: 127
Without package Acme; that link isn't much help.

I read through the code but don't see anything that embeds a JFrame in the applet.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42906
    
  69
Without package Acme; that link isn't much help.

The other classes of the Acme package that may be required can be downloaded from that site as well.

I read through the code but don't see anything that embeds a JFrame in the applet.

That class helps embed an application (doesn't matter whether it uses a JFrame or not) in an applet. That's what you were trying to do, no? It would be trivial to change the "Applet" (which it currently is) to a "JApplet".

If you don't have a full application -just the class extending JFrame- what's stopping you from opening that in an applet?
seema pal
Ranch Hand

Joined: Nov 17, 2005
Posts: 39
seema pal
Ranch Hand

Joined: Nov 17, 2005
Posts: 39
seema pal
Ranch Hand

Joined: Nov 17, 2005
Posts: 39
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet in a JFrame