Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default 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:
    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);
        }
    }
    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:
    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(){}
       }
    but when I open the html document where I embedded it, I get a blank screen.
    Thanks.
    Albert:rolleyes:

  2. #2
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    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
    Java Code:
    add(frame);
    do
    Java 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

Similar Threads

  1. java applet button problem .. :( plz help!
    By i4gotmyid in forum Java Applets
    Replies: 1
    Last Post: 04-17-2008, 04:11 PM
  2. java applet button problem .. :( plz help
    By i4gotmyid in forum New To Java
    Replies: 0
    Last Post: 04-05-2008, 09:55 AM
  3. Serious applet problem
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-25-2008, 05:01 PM
  4. Java Applet re-creation problem
    By Mikalai.Kardash in forum Java Applets
    Replies: 0
    Last Post: 07-23-2007, 02:09 PM
  5. Applet problem
    By Ed in forum Java Applets
    Replies: 2
    Last Post: 07-02-2007, 03:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •