Doug Hauf
Doug Hauf

Reputation: 3223

HTML display applet not working

I am wanting to test some java Applets with a simple HTML page on my desktop. Below is the code that I have written for the use with the class and it doesn't show the applet. Error class not found.

HTML:

<html>
<head>
<title>Java HTML Example</title>

<body>
This is a test of the JApplet
<br>
<embed Code="LifeCycle.class" width=300 height=300>
</embed>
</body>
</html>

Java Code:

Why would this work with Applet but not JApplet????

import java.awt.*;
import java.applet.Applet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * This class can be run as either a JApplet or a JFrame
 * @author home-1
 */
public class LifeCycle extends Applet
{

    private static final long serialVersionUID = 1L;
    String output = "test";
    String event;

    //All of the GUI for the Applet goes here in the initialize
    public void init()
    {
         setLayout(new BorderLayout()); 
         Button okButton = new Button("A button"); 
         add(new JButton("North"),BorderLayout.NORTH);
         add(new JButton("South"),BorderLayout.SOUTH);
         add(new JButton("East"),BorderLayout.EAST);
         setBackground(Color.RED);
//         TextField nameField = new TextField("A TextField",100); 
//         CheckboxGroup  radioGroup = new CheckboxGroup(); 
//         Checkbox   radio1 = new Checkbox("Radio1", radioGroup,false); 
//         Checkbox   radio2 = new Checkbox("Radio2", radioGroup,true); 
//         Checkbox   option = new Checkbox("Option",false); 
//
//         okButton.setBounds(20,20,100,30); 
//         nameField.setBounds(20,70,100,40); 
//         radio1.setBounds(20,120,100,30); 
//         radio2.setBounds(140,120,100,30); 
//         option.setBounds(20,170,100,30); 
//   
//         add(okButton); 
//       add(nameField); 
//       add(radio1); 
//       add(radio2); 
//       add(option); 

         event = "\nInitializing...";
         printOutput();
    }

    public void start()
    {
        event = "\nStarting..."; 
        printOutput();
    }

    public void stop()
    {
        event = "\nStopping...";
        printOutput();
    }

    public void destroy()
    {
        event = "\nDestroying...";
        printOutput();
    }

    private void printOutput()
    {
        System.out.println(event);
        output += event;
      //  repaint();
    }

    private void gui() {
        JFrame f = new JFrame("Not resizable");
        JPanel d = new JPanel();

        d.setLayout(new BorderLayout());
        d.add(new JButton("top    button"),BorderLayout.NORTH);
        d.add(new JButton("bottom button"),BorderLayout.SOUTH);
        d.add(new JButton("center button"),BorderLayout.EAST);
        d.setBackground(Color.RED);

        f.add(d);
        f.setSize(545,340); 
        f.setResizable(false);
        f.setLocationRelativeTo(null);
        f.setTitle("Test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }

    public void paint(Graphics g)
    {
        System.out.println("Graphics Paint Method!");
        g.drawString(output, 100, 100);
        g.drawString("Hello", 10, 10);
    }

    public static void main(String[] args) {
        LifeCycle l = new LifeCycle();
        l.gui();
    }
}

Upvotes: 0

Views: 196

Answers (1)

vishnu
vishnu

Reputation: 740

Perhaps you can try the following

   <embed id="testapplet"
   type="application/x-java-applet;version=1.6"
   width="256" height="256" 
   archive="mytest.jar"
   code="LifeCycle.class"
   pluginspage="http://java.com/download/"
   myParam="My Param Value" />

further reading here

Upvotes: 1

Related Questions