为什么我的小程序没有显示?

时间:2018-07-30 14:15:04

标签: java netbeans applet

我正在尝试测试该applet示例,以便可以对实际项目使用相同的过程,但是每次我运行html页面时,它只会在其中显示空白页面。这是我用Java编写的applet代码:

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! ");
     }
 }

这是我的html页面:

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

我每次只执行一个空白屏幕。我将ExampleEventHandling.java的.jar文件打包到我的html项目中,每次运行html时,它仅显示一个空白页。有人可以帮帮我吗?我不知道该怎么办

0 个答案:

没有答案