7 Replies Latest reply: Mar 16, 2012 10:40 AM by 918375 RSS

    Open a Java Applet from an html link?

    918375
      Can someone please provide direction to open an applet from an HTML <a> link? Maybe something along the lines of this:
      <a href="#">
      <applet code="#.class" height=600 width=600>
      </applet>
      </a>
      I'm very new to JAVA, and any help would be greatly appreciated!!! Thanks in advance

      Edited by: EJP on 16/03/2012 10:37: { code } tags
        • 1. Re: Open a Java Applet from an html link?
          918375
          I had the "a href" tags above and below the applet code.......
          • 2. Re: Open a Java Applet from an html link?
            EJP
            <applet code="#.class" height=600 width=600>
            </applet>
            You can't have a class named '#' so this is completely wrong for a start. And the value of the 'code' attribute is a Java class name, not a file name. And I don't know what the point of enclosing it in an anchor tag was.
            • 3. Re: Open a Java Applet from an html link?
              918375
              The code was lightsout.class, not #.class...

              I just want an HTML link to open a JAVA JFrame. Would a button work instead of an HTML link? Here's the beginning/initialization of my JFrame:

              public lightsout() {
                        frame = new JFrame("LightsOut");
                        frame.setSize(new Dimension(700, 700));
                        frame.setTitle("Lights Out!");
                        frame.setLocation(50, 50);
                        frame.setResizable(false);
                        japplet.setFocusable(false);
                        frame.setAlwaysOnTop(true);
                        
                        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                        int height = screenSize.height;
                        int width = screenSize.width;
                        
                        frame.setLocationRelativeTo(null);
                        
                        frame.setLayout(new BorderLayout());
                        
                        centerPanel = new JPanel(new GridLayout(5, 5));
              • 4. Re: Open a Java Applet from an html link?
                918375
                In my code, the following should read: frame.setFocusable(false); not japplet.........

                Please bear with my lack of knowledge for programming. Thanks again for any help!
                • 5. Re: Open a Java Applet from an html link?
                  EJP
                  The code was lightsout.class, not #.class...
                  That is also incorrect for the reason I stated.
                  I just want an HTML link to open a JAVA JFrame.
                  It won't. Your HTML link just goes to "#" in the current page, which is the top.
                  Would a button work instead of an HTML link?
                  The button would have to activate something that caused the <applet> tag to be rendered. The way you have it now, the applet tag is always rendered, so it always appears, link or no link.
                  • 6. Re: Open a Java Applet from an html link?
                    Umer
                    Please have a look here:
                    http://docs.oracle.com/javase/tutorial/deployment/applet/html.html
                    You problem will be solved after reading this.
                    • 7. Re: Open a Java Applet from an html link?
                      918375
                      Thank you for providing this link, as this is what I needed!