Creation of an applet JApplet in a desktop JDesktopPane

how its posible to load from a jar file an applet which come from package my.package.myclass of the jar file.
next i want to put it in a JInternalFrame and put this desktop frame in a JDesktopPane.
indeed i can move the applet around with other applets in a little window!
here's the code of the desktop_panel.javapackage kevin_shell;
import kevin_shell.Kdemos.*;
import java.awt.*;
import java.awt.event.*;
import java2d.MemoryMonitor;
//import java2d.demos.Lines.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import com.l2fprod.gui.plaf.skin.Skin;
import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;
public class desktop_panel extends JPanel {
JInternalFrame win_info = new JInternalFrame();
public void killme(KDemo demo) {
demo = null;
public void view_image(String file) {
thread_load_cube load = new thread_load_cube(file);
load.start();
JPanel jPanel2 = new JPanel();
JDesktopPane pan_workspace = new JDesktopPane();
public void paint(Graphics p) {
p.setColor(Color.blue);
p.fillRect(0, 0, 1000, 1000);
p.setColor(Color.red);
p.drawString("kevin OS", 10, 10);
super.paint(p);
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel3 = new JPanel();
JButton jButton1 = new JButton();
JInternalFrame win_memory = new JInternalFrame();
JInternalFrame win_terminal = new JInternalFrame();
MemoryMonitor win_mem = new MemoryMonitor();
KClock win_perf = new KClock();
JPanel jPanel4 = new JPanel();
JLabel jLabel1 = new JLabel();
JButton jButton2 = new JButton();
JLabel jLabel6 = new JLabel();
JLabel jLabel4 = new JLabel();
JButton but_collect = new JButton();
JButton but_refresh = new JButton();
JTextField nb_free = new JTextField();
Border border1;
Border border2;
JLabel jLabel2 = new JLabel();
JTextField ed_jdk_path = new JTextField();
JTextField nb_total = new JTextField();
JLabel jLabel3 = new JLabel();
JLabel jLabel5 = new JLabel();
bean_clock bean_clock1 = new bean_clock();
JPanel jPanel5 = new JPanel();
JPanel jPanel1 = new JPanel();
JTabbedPane tabber = new JTabbedPane();
BorderLayout borderLayout2 = new BorderLayout();
JList list1 = new JList();
JList list_system = new JList();
JList list3 = new JList();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JButton jButton6 = new JButton();
test_applet Itest_applet = new test_applet();
JButton jButton7 = new JButton();
public desktop_panel() {
try {
jbInit();
System.out.println("initializing desk");
bean_clock1.setLocation(0, 0);
bean_clock1.setSize(win_info.getPreferredSize());
//bean_clock1.start();
pan_workspace.add(win_info);
win_info.show();
win_info.setLocation(0, 0);
win_info.setSize(win_info.getPreferredSize());
//Class bruno=java.lang.ClassLoader.getSystemClassLoader().loadClass("demo_cube");
//Object b=bruno.newInstance();
pan_workspace.add(win_memory);
win_memory.show();
win_memory.setSize(win_memory.getPreferredSize());
pan_workspace.add(win_terminal);
win_terminal.show();
win_terminal.setSize(win_terminal.getPreferredSize());
pan_workspace.add(win_mem);
win_mem.setVisible(true);
win_mem.setSize(win_mem.getPreferredSize());
pan_workspace.add(win_perf);
win_perf.setVisible(true);
win_perf.setSize(100, 100);
win_perf.setLocation(400, 400);
win_perf.startClock();
//list_system.add("welcome to kevin os");
//tabber.add(list_system);
tabber.add(list1);
tabber.add(list3);
win_terminal.getContentPane().add(tabber, BorderLayout.CENTER);
win_terminal.setSize(300, 300);
win_terminal.setResizable(true);
win_terminal.setLocation(400, 400);
System.out.println("ok");
} catch (Exception e) {
e.printStackTrace();
class thread_load_cube extends Thread {
String file;
thread_load_cube() {
file = "pics/babe1.jpg";
thread_load_cube(String f) {
file = f;
//win_cube
public void run() {
try {
System.out.println("cube loading");
Class demo = java.lang.ClassLoader.getSystemClassLoader().
loadClass("kevin_shell.Kdemos.demo_cube");
KDemo win_cube = (KDemo) demo.newInstance();
//list_system.add("win cube (loading....)");
java.net.URL stoneURL = main_win.class.getResource(file);
java.net.URL skyURL = main_win.class.getResource(
"pics/babe2.jpg");
//win_cube=new demo_cube();
win_cube.set_parameters(stoneURL, skyURL);
//pan_workspace.add(win_cube);
win_cube.show();
win_cube.setLocation(300, 300);
win_cube.setSize(300, 300);
win_cube.setResizable(true);
win_cube.setTitle("java 3d cube");
win_cube.setIconifiable(true);
win_cube.init();
win_cube.setClosable(true);
System.out.println("ok");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("problem with class");
} catch (IllegalAccessException e) {
e.printStackTrace();
System.out.println("acces problem");
} catch (InstantiationException e) {
e.printStackTrace();
System.out.println("instance");
class thread_load_j3d extends Thread {
public void run() {
//list_system.add("j3d test loading...");
//kev
try {
Class demo = java.lang.ClassLoader.getSystemClassLoader().
loadClass("kevin_shell.Kdemos.demo_j3d");
KDemo win = (KDemo) demo.newInstance();
//pan_workspace.add(win);
win.show();
win.setLocation(300, 300);
win.setSize(300, 300);
win.setResizable(true);
win.setTitle("j3d test");
win.setIconifiable(true);
win.init();
win.setClosable(true);
System.out.println("ok");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("problem with class");
} catch (IllegalAccessException e) {
e.printStackTrace();
System.out.println("acces problem");
} catch (InstantiationException e) {
e.printStackTrace();
System.out.println("instance");
private void jbInit() throws Exception {
border1 = BorderFactory.createMatteBorder(4, 4, 4, 4,
new Color(91, 91, 91));
border2 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
Color.white, Color.white,
new Color(153, 153, 204),
new Color(153, 153, 204));
jButton2.setBackground(Color.white);
jButton2.setBorder(BorderFactory.createLineBorder(Color.black));
jButton2.setPreferredSize(new Dimension(70, 70));
//jButton2.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/on_kevin.gif")));
jButton2.setMargin(new Insets(0, 0, 0, 0));
jButton2.setBounds(new Rectangle(9, 6, 52, 54));
jLabel1.setFont(new java.awt.Font("Dialog", 1, 70));
jLabel1.setForeground(SystemColor.desktop);
jLabel1.setText("kevin os 1.0");
jLabel1.setBounds(new Rectangle(66, 6, 255, 22));
this.setLayout(borderLayout1);
this.setBackground(UIManager.getColor("EditorPane.selectionBackground"));
jPanel2.setLayout(null);
jPanel2.setBackground(UIManager.getColor(
"InternalFrame.activeTitleBackground"));
jPanel2.setMaximumSize(new Dimension(100, 100));
jPanel2.setMinimumSize(new Dimension(100, 100));
jPanel2.setPreferredSize(new Dimension(100, 100));
jPanel3.setBackground(new Color(255, 231, 0));
jPanel3.setPreferredSize(new Dimension(60, 10));
jButton1.setBackground(Color.white);
jButton1.setBorder(BorderFactory.createLineBorder(Color.black));
jButton1.setPreferredSize(new Dimension(50, 50));
//jButton1.setIcon(new ImageIcon(desktop_panel.class.getResource("icons/info.gif")));
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton1_mouseClicked(e);
pan_workspace.setBackground(UIManager.getColor(
"List.selectionBackground"));
pan_workspace.setOpaque(false);
pan_workspace.setAlignmentX((float) 0.0);
pan_workspace.setAlignmentY((float) 0.0);
pan_workspace.setLayout(null);
win_memory.setToolTipText("");
win_memory.getContentPane().setBackground(SystemColor.controlDkShadow);
win_memory.setTitle("memory");
win_memory.setBorder(border2);
win_memory.setIconifiable(true);
win_memory.setNormalBounds(new Rectangle(10, 10, 381, 254));
win_memory.setPreferredSize(new Dimension(381, 254));
win_memory.setMinimumSize(new Dimension(381, 254));
win_info.setFrameIcon(null);
win_info.setPreferredSize(new Dimension(269, 230));
win_info.setMinimumSize(new Dimension(269, 230));
win_info.setBorder(border2);
win_info.getContentPane().setBackground(UIManager.getColor(
"CheckBoxMenuItem.selectionBackground"));
win_info.setMaximumSize(new Dimension(100, 100));
win_info.setResizable(true);
win_info.setIconifiable(true);
win_info.setTitle("kevin OS info");
but_collect.setBackground(Color.orange);
but_collect.setText("garbage collector");
but_collect.setBounds(new Rectangle(13, 114, 162, 31));
but_collect.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
but_collect_mouseClicked(e);
but_refresh.setText("refresh");
but_refresh.setBounds(new Rectangle(11, 150, 162, 32));
but_refresh.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
but_refresh_mouseClicked(e);
nb_free.setBackground(Color.white);
nb_free.setDisabledTextColor(Color.white);
nb_free.setEditable(false);
nb_free.setBounds(new Rectangle(107, 40, 108, 22));
jPanel4.setBackground(UIManager.getColor(
"InternalFrame.activeTitleBackground"));
jLabel2.setBackground(Color.pink);
jLabel2.setFont(new java.awt.Font("Dialog", 1, 50));
jLabel2.setForeground(Color.red);
jLabel2.setText("-OS-");
jLabel2.setBounds(new Rectangle(98, 12, 139, 52));
ed_jdk_path.setBackground(Color.white);
ed_jdk_path.setDisabledTextColor(Color.white);
ed_jdk_path.setEditable(false);
ed_jdk_path.setBounds(new Rectangle(104, 14, 190, 22));
nb_total.setBackground(Color.white);
nb_total.setDisabledTextColor(Color.white);
nb_total.setEditable(false);
nb_total.setBounds(new Rectangle(228, 40, 108, 22));
jLabel3.setToolTipText("");
jLabel3.setText("free");
jLabel3.setBounds(new Rectangle(106, 70, 112, 16));
jLabel5.setBounds(new Rectangle(228, 70, 112, 16));
jLabel5.setText("total");
jLabel5.setToolTipText("");
win_terminal.setTitle("terminal");
jPanel5.setLayout(borderLayout2);
jButton3.setPreferredSize(new Dimension(50, 27));
jButton3.setText("cube");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton3_mouseClicked(e);
jButton4.setText("test");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton4_mouseClicked(e);
jButton5.setText("skin cool");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton5_mouseClicked(e);
jButton6.setText("skin xp");
jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton6_mouseClicked(e);
jButton7.setText("test applet");
jButton7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton7_actionPerformed(e);
win_memory.getContentPane().add(jPanel4, BorderLayout.CENTER);
jPanel4.setLayout(null);
jPanel4.setMinimumSize(new Dimension(100, 100));
jPanel4.setPreferredSize(new Dimension(100, 100));
jLabel6.setText("java memory");
jLabel6.setBounds(new Rectangle(16, 40, 78, 18));
jLabel4.setText("jdk path");
jLabel4.setBounds(new Rectangle(18, 16, 76, 18));
this.add(jPanel3, BorderLayout.WEST);
jPanel3.add(jButton7);
jPanel3.add(jButton1, null);
jPanel3.add(jButton3, null);
jPanel3.add(jButton4, null);
jPanel3.add(jButton5, null);
jPanel3.add(jButton6, null);
this.add(pan_workspace, java.awt.BorderLayout.CENTER);
jPanel4.add(jLabel4, null);
jPanel4.add(jLabel6, null);
jPanel4.add(but_collect, null);
jPanel4.add(ed_jdk_path, null);
jPanel4.add(nb_free, null);
jPanel4.add(nb_total, null);
jPanel4.add(but_refresh, null);
jPanel4.add(jLabel3, null);
jPanel4.add(jLabel5, null);
win_info.getContentPane().add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jButton2, null);
jPanel2.add(jLabel1, null);
jPanel2.add(jLabel2, null);
tabber.add(list1, "list1");
tabber.add(list_system, "list_system");
tabber.add(list3, "list3");
void but_refresh_mouseClicked(MouseEvent e) {
nb_free.setText(String.valueOf(java.lang.Runtime.getRuntime().
freeMemory()));
nb_total.setText(String.valueOf(java.lang.Runtime.getRuntime().
totalMemory()));
void jButton1_mouseClicked(MouseEvent e) {
win_info.show();
win_info.setLocation(0, 0);
//win_info.setSize(100,100);
void but_collect_mouseClicked(MouseEvent e) {
java.lang.Runtime.getRuntime().gc();
but_refresh_mouseClicked(e);
//list_system.add("collecting memory");
void jButton3_mouseClicked(MouseEvent e) {
//win_cube.begin_anim();
void jButton4_mouseClicked(MouseEvent e) {
thread_load_j3d load = new thread_load_j3d();
load.start();
void jButton6_mouseClicked(MouseEvent e) {
try {
Skin skin = null;
//windows xp
skin = SkinLookAndFeel.loadThemePack("skins/BeOS-theme.jar");
// set the skin
SkinLookAndFeel.setSkin(skin);
// ask Swing to use Skin Look And Feel
UIManager.setLookAndFeel(
"com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
SwingUtilities.updateComponentTreeUI(this);
this.validate();
this.updateUI();
} catch (Exception er) {
System.out.println("Failed loading L&F: ");
er.printStackTrace();
void jButton5_mouseClicked(MouseEvent e) {
try {
Skin skin = null;
skin = SkinLookAndFeel.loadThemePack("skins/themepack.zip");
// set the skin
SkinLookAndFeel.setSkin(skin);
// ask Swing to use Skin Look And Feel
UIManager.setLookAndFeel(
"com.l2fprod.gui.plaf.skin.SkinLookAndFeel");
} catch (Exception er) {
er.printStackTrace();
void jButton3_actionPerformed(ActionEvent e) {
thread_load_cube load = new thread_load_cube();
load.start();
public void jButton7_actionPerformed(ActionEvent e) {
JApplet applet=null;
frame_applet frame=null;
try{
//ExtClassLoader ecl = new ExtClassLoader("/home/kevinet/CODE/JAVA/jlguiapplet2.3.1-selfsigned/lib/jlguiapplet2.3.jar");
//Class demo = ecl.loadClass("javazoom.jlgui.player.amp.PlayerApplet");
Class demo = java.lang.ClassLoader.getSystemClassLoader().loadClass("kevin_shell.Kdemos.test_applet");
applet = (JApplet) demo.newInstance();
frame=new frame_applet(applet);
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
System.out.println("problem with class");
catch (IllegalAccessException iae) {
iae.printStackTrace();
System.out.println("acces problem");
catch (InstantiationException ie) {
ie.printStackTrace();
System.out.println("instance");
System.out.println("hello");
pan_workspace.add(frame);
applet.init();
//applet.setLocation(0,0);
applet.start();
frame.setVisible(true);
frame.show();
frame.setLocation(300, 300);
frame.setSize(300, 300);
frame.setResizable(true);
frame.setTitle("test applet");
frame.setIconifiable(true);
frame.setClosable(true);
}

What about calling getLocation on the applet itself?
Otherwise, if you are using Swing, you can try (where "this" is the applet object):
javax.swing.SwingUtilities.getWindowAncestor(this).getLocation();
or
javax.swing.SwingUtilities.convertPointToScreen(this.getLocation(), this);
The latter should work, at least.

Similar Messages

  • Is correct? Application (JFrame) to Applet (JApplet)

    I need to convert a java application (JFrame) into an applet (JApplet), and I have seen a few "big steps":
    1�: make the class extends to JApplet instead of a JFrame
    2�: To replace the construction method by init ()
    3�: To comment the main method
    Is correct?, because I have some doubts that later I�ll explain
    Thanks

    I think in the init method (in a JApplet) I cannot call the super method. but my problem is how to change this? if in others files (in Files.java) I have calls to super metod, because thus it constructs a dialog box, asking for a file.
    In file Files.java I have a class called "Abort" (extends to JDialog) in whitch:
    /* class Files.java */
    class Abort extends JDialog
              boolean abort = true;
              JTextArea mensage = null;
              JButton acept = new JButton("Acept");
              JButton cancel = new JButton("Cancel");
              Abort(String nanemFile)
                   super(MainClassFile.mainWindow, " Attention!", true);
    /* clas Files.java */Please help

  • How can I use applet to get the desktop image of client

    hi,I have a question to ask u.
    How can I use applet to get the desktop image of client? Now I develop a web application and want user in the client to get his current image of the screen.And then save as a picture of jpeg format ,then upload it to the server?
    I have done an application to get the screen image and do upload file to server in a servlet with the http protocal.

    Since the desktop image is on the client's local hard drive, you'll need to look at trusted applets first.

  • Applets on Windows Active Desktop

    I've tried a couple of other forums with no results. No one seems to know the answer to my problem. Maybe someone here can help.
    I am trying to get a simple JApplet to appear on my active desktop. I have winXPpro and JDK1.5.
    My applet works fine in both IE(browser) and Firefox. But on the active desktop (which uses IE, I believe) it simply shows up as a gray box.
    Has anyone experienced this problem before?

    In Vista, request to end-user, registing your domain as trust site.
    http://crazytazo.com

  • Opening an applet from a java desktop application

    I have an applet and I've seen some fairly complicated methods (for me) of making the main class hybrid and open as both an applet and an application. Isn't there a simple way o having a class with a main method to open the applet class in an applet viewer or maybe the browser? Then I could compile it and run the same jar file as both an application and an applet. What is the simplest way you can think of to do this?

    The simplest was is to put all that GUI stuff into a JPanel, and not a JFrame or JApplet. That way, you can embed it in anything you like.

  • Applet woes on Active Desktop

    Has anyone had any luck creating an applet that you display on the active desktop? I created a simple applet that runs on my desktop as an active desktop component. It stopped working and I can't figure out why. It works perfectly if you open the html with Internet Explorer, but if you open the Active Desktop item, it doesn't work at all.
    It use to, but something has changed and I can't figure out what it is.
    Any suggestions?
    Thanks, paul

    I ran a different applet that I had created and it worked perfectly. I am completely stumped. It looks like everything is working when you open in Internet Explorer, but it doesn't work as an Active Desktop Item.
    Also, there is one other problem that could be the cause. I will post that in another topic. Thanks!

  • How to create an applet in a JDestopPane?

    hello i would like to create an applet (JApplet) in a desktop (JDesktopPane).
    i have to put the applet in a JInternalFrame so i can move and resize the window around.
    indeed i can have several applets in the JDesktopPane.
    it would be more powerfull than viewing it in a web navigator.
    more i want to load an applet from its web site from its jar file.
    i know that from a html page, you have to tell the navigator where is the jar file with the "archive" tag; the "CODE" tag is the name of the class file not the path to the package like my.package.myclass !
    can i put my.package.myclass instead of myclass.class in the "CODE" tag?

    duplicate post

  • How to create an applet in a jDesktopPane

    hello i would like to create an applet (JApplet) in a desktop (JDesktopPane).
    i have to put the applet in a JInternalFrame so i can move and resize the window around.
    indeed i can have several applets in the JDesktopPane.
    it would be more powerfull than viewing it in a web navigator.
    more i want to load an applet from its web site from its jar file.
    i know that from a html page, you have to tell the navigator where is the jar file with the "archive" tag; the "CODE" tag is the name of the class file not the path to the package like my.package.myclass !
    can i put my.package.myclass instead of myclass.class in the "CODE" tag?
    here's some snaphot of my softwar kevin_shell to give you some ideas:
    http://go.to/kevin-net/SNAP
    desktop_panel: the JDesktopPane where i have opened a simple applet.
    explorer_panel
    it is an open source project.
    hope someone answer me, i will give to you my source code.

    duplicate post

  • JApplet as Desktop Background

    Is it possible to set the background/wallpaper of the Windows desktop to a java applet? I use windows xp.

    This really is the wrong forum ! however ...
    Make a html document including the applet
    Right-click on desktop -> Properties
    -> Desktop Tab
    -> Customise Desktop button
    -> Web Tab
    -> New button
    Wrong forum :-)

  • Cant get image to load in JApplet - java.security.AccessControlException

    hi,
    I need to make a JApplet that loads and displays images. Before I worry about media tracker or anything else I need to get the image to load.
    My code is:
    package Applet;
    import java.awt.*; 
    import javax.swing.*;
    import java.applet.*;
    * @author Nick
    public class TestJApplet extends JApplet {
        /** Creates a new instance of TestJApplet */
        public TestJApplet() {
        public void init()
        public void paint(Graphics g)
            Image image;
            image = getImage(this.getDocumentBase(),"a.gif");
            g.drawRect(30,30,30,30);
    }where a.gif is located in the same folder as the .java file.
    I get the following message:
    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission \C:\Documents and Settings\Nick\Math\build\a.gif read)
            at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
            at java.security.AccessController.checkPermission(AccessController.java:427)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
            at sun.awt.image.URLImageSource.<init>(URLImageSource.java:37)
            at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:33)
            at sun.misc.Ref.get(Ref.java:47)
            at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:377)
            at sun.applet.AppletViewer.getImage(AppletViewer.java:372)
            at java.applet.Applet.getImage(Applet.java:236)
            at java.applet.Applet.getImage(Applet.java:258)
            at Applet.TestJApplet.paint(TestJApplet.java:27)
            at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
            at sun.awt.RepaintArea.paint(RepaintArea.java:224)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
            at java.awt.Component.dispatchEventImpl(Component.java:4031)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Component.dispatchEvent(Component.java:3803)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission \C:\Documents and Settings\Nick\Math\build\a.gif read)
            at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
            at java.security.AccessController.checkPermission(AccessController.java:427)
            at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
            at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
            at sun.awt.image.URLImageSource.<init>(URLImageSource.java:37)
            at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:33)
            at sun.misc.Ref.get(Ref.java:47)
            at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:377)
            at sun.applet.AppletViewer.getImage(AppletViewer.java:372)
            at java.applet.Applet.getImage(Applet.java:236)
            at java.applet.Applet.getImage(Applet.java:258)
            at Applet.TestJApplet.paint(TestJApplet.java:27)
            at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
            at sun.awt.RepaintArea.paint(RepaintArea.java:224)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:254)
            at java.awt.Component.dispatchEventImpl(Component.java:4031)
            at java.awt.Container.dispatchEventImpl(Container.java:2024)
            at java.awt.Component.dispatchEvent(Component.java:3803)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Could someone help me get an image to load in an Applet/JApplet.
    Cheers :)

    From looking at your code there are two problems... the first is that you have a security exception being thrown because you are attempting to load a file locally with insufficient privileges to do so. This is because Applets have additional security levied on them so they don't say, in this circumstance steal a file off the loaded machine and send it back to the server that delivered them.
    If you want to get your applet to load a local file (I don't think that is what you're asking here) then you have to digitally sign your applet and allow the user to decide if they want to be allow it to load a local file.
    Nutshell is that you need to understand that the URL returned from getDocumentBase() in an applet is going to be from the Jar file you send the applet with or the URL you served the applet from. This is a bit of debugging code to show you what you are looking at and hopefully explain anything ambiguous I may have stated.
    package testapplication;
    import java.awt.EventQueue;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    * Description : <p></p>
    * @author John Michael Resler<br/>
    * Class : DocBaseApplet<br/>
    * Creation Time : 8:31 AM<br/>
    * Creation Date : June 18, 2006<br/>
    * Compiler : Sun Java Community Edition (version 1.5.0_06)<br/>
    public class DocBaseApplet extends javax.swing.JApplet implements MouseListener {
         * Initializes the applet DocBaseApplet
        public void init() {
            try {
                EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        initComponents();
            } catch (Exception ex) {
                ex.printStackTrace();
        private void initComponents() {
            documentBaseLabel = new javax.swing.JLabel();
            documentBaseLabel.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    documentBaseLabelMouseClicked(evt);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(documentBaseLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(documentBaseLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                    .addContainerGap())
        private void documentBaseLabelMouseClicked(java.awt.event.MouseEvent evt) {                                              
            // TODO add your handling code here:
            this.documentBaseLabel.setText(this.getDocumentBase().toString());
        public void mouseClicked(MouseEvent e) {
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
        private javax.swing.JLabel documentBaseLabel;
    }

  • How to create a frame in a applet?

    Dear All,
    How to create a frame in a applet?
    Thanks in advance
    Kityy

    You can't add a Frame/JFrame to an Applet/JApplet.
    An Applet/JApplet has its origins in the class Panel/JPanel.
    So, if you make your Applet to an application you
    can easily do that by putting your Applet "above" a Frame.
    Maybe you can archieve your goals with some Panels?!

  • Export applet from eclipse with referenced jars?

    Hey guys,
    I've been looking around for a good answer for how to do this. I'm working on a project that consists of an applet (JApplet) and some referenced jars. In Eclipse I can export the jar but can't figure out how to get it to include all of the referenced jars as well. Any idea how to go about doing this?
    Thanks
    Edit:
    I came across this post:
    http://forums.sun.com/thread.jspa?forumID=421&threadID=630738
    but didn't find a suitable answer
    Edited by: JFactor2004 on May 17, 2010 1:24 PM

    Figured it out. Just had to include the names of the jars in the applet tag in the html file.

  • How to read client's home directory files using  signed applets

    hi
    i want to konw the exact procedure for the creation of signed applets . using that i want to read my client files....
    Thanks
    Dileep

    google: http://www.google.com/search?q=how+to+sign+an+applet

  • Applet Security loading & running on local PC

    I understnd the limits of an Applet loaded from a server to a local PC. What I am trying to do is test my Applet (JApplet actually) as I create it. I have some GIF and JPG files that need to be loaded from the same DIR that the JApplets HTML file is in. When I run the Applet in appletviewer it works fine, when I run it in IE5.5 I get security errors and the Applet fails to initialize.
    I have read the online section on applet security. It seems to me that my applet 'thinks' it is being loaded from a remote server.
    The online HTML talks about a properties file that can be edited to include the rights to read and/or write to specific local files. Anybody know the name of this file ??
    It should not make a difference that I am doing my work on a W2K Server, should it ???
    Any specific help would be greatly appreciated !!

    java.security.AccessControlException: access denied (java.io.FilePermission CHR.gif read)
    All I try to do in my code is place a GIF as am Icon on a JButton.
    //add buttons to controlPanel
            for(int i=0;i<siteNames.length; i++){
                icon = new ImageIcon(icons);
    JButton b = new JButton(siteNames[i],icon);
    b.addActionListener(listener);
    b.setActionCommand(siteNames[i]);
    controlPanel.add(b);
    Where icons[i] is a string listing of GIF files. The code works fine in IE5.5 without the icons on the buttons. Only when I put the icons on the buttons do I get the access denied error.
    Any Ideas ????
    Could it be the fact that I am doing my coding and testing on a W2K Server ????

  • Applet can't be instantiated on IE browser.

    I have created an SWING Applet (JApplet). It works fine inside JDeveloper IDE using the Appletviewer but when I deploy it and I try to launch it through the Internet Explorer browser I get the following message:
    "Applet can't be instantiated".
    I'm working with JDeveloper 3.1.1.2
    Can somebody help me out with this? I will really appreciate it.
    null

    In the java console of IE are you getting any class not found errors?
    Please refer to the following URL (Swing Applet Test ) to check whether your browser supports swing classes or not.
    http://java.sun.com/products/jfc/tsc/articles/getting_started/applet_test.html
    Another way to create and run Swing applets in IE or netscape is to use Java Plug-in.
    null

Maybe you are looking for