Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 06:07 PM
Senior Member
 
Join Date: Jun 2007
Posts: 114
Albert is on a distinguished road
Problem with run Java Applet
Just wondering if there is an easy way to transform java applications into applets.
For instance, say I have a class that looks like this:
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JPanel; import javax.swing.JFrame; public class TrackOperator extends JPanel{ ... public static void main(String[] args){ JFrame frame = new JFrame("TrackOperatorPanel"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); TrackOperator panel = new TrackOperator(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } }
How would I make that run in an applet?
I know I need to import java.applet.*, also a init() and a stop() methods are needed.
Here is what I attempted so far:
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JPanel; import javax.swing.JFrame; import java.applet.*; public class TrackOperatorApplet extends Applet{ public void init(){ JFrame frame = new JFrame("TrackOperatorPanel"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); TrackOperator panel = new TrackOperator(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); add(frame); //should add the frame to the applet??? } public void stop(){} }
but when I open the html document where I embedded it, I get a blank screen.
Thanks.
Albert
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-13-2007, 04:06 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
If all you're doing is using the panel I believe you can do just an add on that panel, and not deal with the frame stuff.
That is instead of
Code:
add(frame);
do
Code:
add(panel)
But, I'm not completely sure. I never really wrote many java applets..

This is what I'm basing this idea off of:
http://java.sun.com/products/java-media/jmf/2.1.1/samples/samples/SimplePlayerApplet.java
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java applet button problem .. :( plz help! i4gotmyid Java Applets 1 04-17-2008 05:11 PM
java applet button problem .. :( plz help i4gotmyid New To Java 0 04-05-2008 10:55 AM
Serious applet problem willemjav Java Applets 1 03-25-2008 06:01 PM
Java Applet re-creation problem Mikalai.Kardash Java Applets 0 07-23-2007 03:09 PM
Applet problem Ed Java Applets 2 07-02-2007 04:35 PM


All times are GMT +3. The time now is 01:16 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org