• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane  RSS feed

 
ch praveen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
When I implemented JOptionPane in a simple program which is illustrated below, its working fine. But When I implemented it in an applet it is giving me java.lang.ClassNotFound Exception. My question is, can we implement all of the Swing componeets in an applet (Are there any Swing components that can't be embedded in an applet). I have included the below code snippets for clarification.
----------- (Working :: SwingTest.java)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingTest1 {
public static void main(String args[]) {
Frame f = new Frame("SwingTest1");
f.setSize(200,300);
f.setVisible(true);
JOptionPane.showMessageDialog(f, "There's no \"there\" there.");
}
}
-----------
------------ (not working :: SwingTest1Applet.java)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingTest1Applet extends Applet {
public void init() {
Frame f = new Frame("SwingTest1");
f.setSize(200,300);
f.setVisible(true);
JOptionPane.showMessageDialog(f, "There's no \"there\" there.");
}
}
-------------
------------- ( testswingtest.html [SwingTest1Applet.class and testswingtest.html are in same directory] )
<applet code="SwingTest1Applet" width=200 height=300>
</applet>
-------------
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen,
It looks (to me) like you need to familiarize yourself with the Java Plug-in Technology.
Good Luck,
Avi.
 
ch praveen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Avi for your response. In my browser applets that containing awt components are working well. Now I want to switch the interface to Swings. Initially When I incorporated JOptionPane in my applet as shown above it, browser thrown a ClassNotFound Exception, later I have included a classpath to rt.jar. Now its throwing jva.lang.UnsatisfiedlinkError: java/security/AccessController doPriviled Exception. Can't we implement swings in applet that extends Applet instead of JApplet (code depicted in SwingTest1Applet.java , my firt post wrt.this topic)
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your applet is throwing a ClassNotFoundException when using Swing, the solution is not to add rt.jar to the classpath! That would mean the user would have to download the full Java API ( a ~22MB jarfile) every time they accessed the applet. The problem is that you don't have the Java Plugin installed in your browser (follow the link provided above by Avi). You shouldn't mix AWT and Swing components - so you shouldn't use Swing components in a regular Applet (with extends AWT's Panel class). You should use JApplet instead if you want to use Swing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!