Results 1 to 5 of 5

Thread: Applets and swing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Applets and swing

    I'm developing a web-based applet and I want it to open an external swing form that's stored in a separate class.

    Basically can someone just show me how to open a blank JPanel that is stored in a separate class file from an applet running in a browser? I believe I can do anything beyond that on my own. Any tips would be appreciated though.

    On another note:
    I'm pretty advanced with Java but I just have very little experience with applets. Would you recommend using the java.applet.Applet class or the swing JApplet class for my applets? Is there any big difference?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Applets and swing

    I didn't understand your question very well.
    I think to use a panel in your applet all you need is to include it's class path in the "classpath" when building the applet.

    About your second question. If your applet uses animation it'd be better to use the java.applet.Applet. But if you'll be using it as a web form the javax.swing.JApplet would be better (it's just a graphics thing)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Applets and swing

    asically can someone just show me how to open a blank JPanel that is stored in a separate class file from an applet running in a browser? I believe I can do anything beyond that on my own. Any tips would be appreciated though.
    extend JDialog and add the JPanel to it's container. It's just like a JFrame so you can customize the way it looks and you can easily call it from an Applet.

    I'm pretty advanced with Java but I just have very little experience with applets. Would you recommend using the java.applet.Applet class or the swing JApplet class for my applets? Is there any big difference?
    JApplet.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Ithaca, NY
    Posts
    145

    Re: Applets and swing

    Quote Originally Posted by System_Error
    extend JDialog and add the JPanel to it's container. It's just like a JFrame so you can customize the way it looks and you can easily call it from an Applet.
    Can you give me a quick code snippet maybe of how you're saying to set this up? I tried what you said and it's not working for me.

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Applets and swing

    Here's a really crude example:

    Code:
    import javax.swing.*;
    import java.awt.event.*;
    
    
    public class Test extends JApplet implements ActionListener
    {
       private JButton btn;
       public void init()
       {
           btn = new JButton("Test");
           btn.addActionListener(this);
           getContentPane().add(btn);
           setVisible(true);
       }
       
       public void actionPerformed(ActionEvent ae)
       {
           if (ae.getSource() == btn) new TestBox();
       }
    }
    
    class TestBox extends JDialog
    {
        public TestBox()
        {
            setSize(200,200);
            setVisible(true);
        }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width