View Single Post
  #1 (permalink)  
Old 07-09-2007, 06:07 PM
Albert Albert is offline
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
Reply With Quote
Sponsored Links