Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet in a JFrame

 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just do this?

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
seema pal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
seema pal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic