• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

applet in a JFrame

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just do this?

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
seema pal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
seema pal
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic