Results 1 to 4 of 4
  1. #1
    Liquid is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Question application to applet converstion

    hey guys, i was wondering what the easiest way to convert a simple java jpanel app and make it useable on the web either as an applet or a popup java app.
    a tutorial or link in the right direction would be much appritiated
    Thanks for your help
    :)

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by Liquid View Post
    hey guys, i was wondering what the easiest way to convert a simple java jpanel app and make it useable on the web either as an applet or a popup java app.
    a tutorial or link in the right direction would be much appritiated
    Thanks for your help
    :)

    the direction isn't hard to understand. if you have a class that extends a JFrame when you add a JPanel the JPanel will be shown in a window style and if you have a class that extends a JApplet when you add a JPanel the JPanel will be shown as an applet.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    It's easy to have a class that extends Applet and also has a main method that constructs and displays a JFrame with the same content.
    Java Code:
    public class DualPurpose extends JApplet {
    
      public void init() {
        add(createContents());
      }
    
      public static void main(String[] args {
        SwingUtilities.invokeLater(new Runnable() {
    
          public void run() {
            JFrame frame = new JFrame();
            frame.add(createContents();
            frame.pack();
    
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
          }
        });
      }
    
      private JComponent createContents() {
        JPanel panel = new JPanel();
        // add components and functionality
        return panel;
      }
    }
    Another and probably better approach would be to write the code within createContents() as a class extending JPanel, and two driver classes that add this customized panel to an applet or a frame.

    db
    Last edited by DarrylBurke; 05-05-2011 at 09:55 AM. Reason: Added invokeLater

  4. #4
    Liquid is offline Member
    Join Date
    Oct 2010
    Posts
    9
    Rep Power
    0

    Default

    If i showed you how my code is laid out would you be able to explain it more specifically to my app. i have three classes, a driver class, a display window class(extends jframe) and a constructor with all my buttons and rectangles and ovals and stuff. i think i understand what your saying but its always been useful to have a worked example. do you have the "before" code of your applet. like the equivalent of it but as a desktop app.

Similar Threads

  1. Converting this Applet to an Application
    By karthus in forum New To Java
    Replies: 4
    Last Post: 07-07-2010, 05:30 AM
  2. Applet vs application
    By gan5016 in forum Java Applets
    Replies: 3
    Last Post: 08-27-2009, 02:53 PM
  3. [SOLVED] Application -> Applet
    By Ypsilon IV in forum Java Applets
    Replies: 2
    Last Post: 04-25-2009, 09:26 PM
  4. Applet to Application (Game)
    By AndrewM16921 in forum Java Applets
    Replies: 3
    Last Post: 04-12-2009, 01:24 PM
  5. Temperature converstion
    By jamesov89 in forum New To Java
    Replies: 6
    Last Post: 09-29-2008, 05:51 AM

Tags for this Thread

Posting Permissions

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