Results 1 to 2 of 2
Thread: Problem with run Java Applet
- 07-09-2007, 05:07 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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:
How would I make that run in an applet?Java 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); } }
I know I need to import java.applet.*, also a init() and a stop() methods are needed.
Here is what I attempted so far:
but when I open the html document where I embedded it, I get a blank screen.Java 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(){} }
Thanks.
Albert:rolleyes:
- 07-13-2007, 03:06 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 44
- Rep Power
- 0
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 ofdoJava Code:add(frame);
But, I'm not completely sure. I never really wrote many java applets..Java Code:add(panel)
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
Similar Threads
-
java applet button problem .. :( plz help!
By i4gotmyid in forum Java AppletsReplies: 1Last Post: 04-17-2008, 04:11 PM -
java applet button problem .. :( plz help
By i4gotmyid in forum New To JavaReplies: 0Last Post: 04-05-2008, 09:55 AM -
Serious applet problem
By willemjav in forum Java AppletsReplies: 1Last Post: 03-25-2008, 05:01 PM -
Java Applet re-creation problem
By Mikalai.Kardash in forum Java AppletsReplies: 0Last Post: 07-23-2007, 02:09 PM -
Applet problem
By Ed in forum Java AppletsReplies: 2Last Post: 07-02-2007, 03:35 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks