This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

applet in a JFrame

 
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);
}
});
}
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just do this?

 
Rancher
Posts: 43016
76
  • 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: 43016
76
  • 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: 43016
76
  • 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?
 
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
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic