简体   繁体   中英

Java applet will not execute in Safari

Beginner Java applet user. I'm not sure as to why my applet will not display in a page. I'm almost positive I have all necessary information. Is it possible that it will not show up due to using Safari? Will not show up in Chrome, either. Do you see what I'm missing? Thanks

EDIT: This >> Java Applet sandboxed in Safari? doesn't help, either.

Java program

  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.awt.Color.*;

  public class JNumberOne extends JApplet implements ActionListener
  {
      Font numberOneFont = new Font("Teen", Font.BOLD, 24);
      JButton numberOneButton = new JButton("Who's Number One?");
      JLabel numberOneMessage = new JLabel(" ");
      Container con = getContentPane();
      public void init()
   {
       numberOneMessage.setFont(numberOneFont);
       con.add(numberOneButton);
       con.setLayout(new FlowLayout());
       con.setBackground(Color.WHITE);
       numberOneButton.addActionListener(this);
   }
      public void actionPerformed(ActionEvent e)
   {
       con.remove(numberOneButton);
       numberOneMessage.setText("The 1992 Texas Rangers");
       con.add(numberOneMessage);
       con.setBackground(Color.YELLOW);
       validate();
   }
  }

HTML for Applet

  <!DOCTYPE html>
  <html>
      <head>
          <style>
        body{text-align:center; background:#00008B;opacity:.5;}
    </style>
   </head>
   <body>
       <object code = "JNumberOne.class" width=450 height=100></object>
   </body>
  </html>

Remove the quotes from the class name.

Replace

 <body>
       <object code = "JNumberOne.class" width=450 height=100></object>
 </body>

With

 <body>
       <object code = JNumberOne.class width=450 height=100></object>
 </body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM