0

I'm trying to test this applet example so I could use the same process for my real project, but every time I run my html page, it only displays a blank page in it. Heres my applet code written in Java:

ExampleEventHandling.java:

 import java.applet.Applet;
 import java.awt.Graphics;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 public class ExampleEventHandling extends Applet implements MouseListener{
     StringBuffer strBuffer;
     public void init() {
         addMouseListener(this);
         strBuffer = new StringBuffer();
         addItem("initializing the apple ");
     }
     public void start() {
         addItem("starting the applet ");
     }
     public void stop() {
         addItem("stopping the applet ");
     }
     public void destroy() {
         addItem("unloading the applet");
     }
     void addItem(String word) {
         System.out.println(word);
         strBuffer.append(word);
         repaint();
     }
     public void paint(Graphics g) {
         g.drawRect(0, 0, 
         getWidth() - 1,
         getHeight() - 1);
         g.drawString(strBuffer.toString(), 10, 20);
     }
     public void mouseEntered(MouseEvent event) {
     }
     public void mouseExited(MouseEvent event) {
     }
     public void mousePressed(MouseEvent event) {
     }
     public void mouseReleased(MouseEvent event) {
     }
     public void mouseClicked(MouseEvent event) {
         addItem("mouse clicked! ");
     }
 }

Here's my html page:

 <html>
    <title>Event Handling</title>
    <hr>
    <applet code = "ExampleEventHandling.class" 
     width = "300" height = "300">
    </applet>
    <hr>
 </html>

And I only executed a blank screen everytime. I got the .jar file of ExampleEventHandling.java packaged into my html project and everytime I run the html, it only shows a blank page. Can someone please help me? I don't know what else to do.

Anonymous
  • 3
  • 2
  • 1) Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. 2) Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 3) See [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and .. – Andrew Thompson Jul 31 '18 at 02:24
  • .. [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/moving-to-a-plugin-free-web). – Andrew Thompson Jul 31 '18 at 02:24

0 Answers0