Reputation: 313
I am trying to open my Applet.jar in a html code.
My Java code is :
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void initComponents() {
setTitle("Example");
//more lines code base in JFrame with button,labels etc
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
}
My html code is :
<!DOCTYPE html>
<html>
<body>
<h1>Java Applet Example</h1>
<p><object type="application/x-java-applet" width="300" height="300"> <param name="code" value="NewJFrame.class" /> <param name="archive" value="20130717_Applet.jar" /> <param name="mayscript" value="true" /> Java failed to load </object></p>
</body>
</html>
So when i am trying to open the html file with a browser it throws me up :
Java Error: “ClassNotFoundException NewJFrame.class”
I change the security for the java control panel to Medium from High but i get the same error.
Upvotes: 0
Views: 5933
Reputation: 159754
AFAIK a class needs to extend one of the applet classes to run the class as an applet.
public class NewJFrame extends javax.swing.JApplet {
Since applets do not provided a setTitle
method (at least not directly), comment out the line
setTitle("Example");
To run the application directly using a JFrame
, Java Web Start could be used
Upvotes: 3