# Java-Applet Funzt ned!



## weirer (8. Okt 2007)

Hi!
Mein Java Applet Funktioniert nicht!
link: http://sawei3.lima-city.de/upload.html
bzw http://sawei3.lima-city.de/uploader/upload.html
fehler beim ersten: 
java.lang.reflect.InvocationTargetException
	at java.awt.EventQueue.invokeAndWait(Unknown Source)
	at uploader.Upload.init(Upload.java:25)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
	at java.lang.System.getProperty(Unknown Source)
	at java.io.Win32FileSystem.getUserPath(Unknown Source)
	at java.io.Win32FileSystem.resolve(Unknown Source)
	at java.io.File.getAbsolutePath(Unknown Source)
	at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
	at sun.awt.shell.Win32ShellFolder2.listFiles(Unknown Source)
	at sun.awt.shell.ShellFolder.listFiles(Unknown Source)
	at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
	at sun.awt.shell.ShellFolder.get(Unknown Source)
	at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(Unknown Source)
	at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(Unknown Source)
	at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
	at javax.swing.plaf.metal.MetalFileChooserUI.installUI(Unknown Source)
	at javax.swing.JComponent.setUI(Unknown Source)
	at javax.swing.JFileChooser.updateUI(Unknown Source)
	at javax.swing.JFileChooser.setup(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)
	at javax.swing.JFileChooser.<init>(Unknown Source)
	at uploader.Upload.initComponents(Upload.java:49)
	at uploader.Upload.access$000(Upload.java:13)
	at uploader.Upload$1.run(Upload.java:29)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


Fehler beim Zweiten:
java.lang.NoClassDefFoundError: Upload (wrong name: uploader/Upload)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(Unknown Source)
	at java.security.SecureClassLoader.defineClass(Unknown Source)
	at sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)



Lg und danke!


----------



## wayne (8. Okt 2007)

Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)

dies zeigt, daß du über die beschränkungen der sandbox hinaus arbeiten möchtest. um das zu können, musst du dein applet signieren. dazu gibts in diesem forum, wie auch in vielen anderen und selbstverständlich auch in unzähligen google-beiträgen bereits genügend text, sodaß ich dir das vorgehen dazu hier jetzt nicht schreiben werde.

viel glück

wayne


----------



## weirer (8. Okt 2007)

beu jetzt das ganze neu auf und jetzt funzts komischer weise!


----------



## weirer (9. Okt 2007)

Hi!
hab n neues Problem mit dem Applet!
jetzt, wo ich signiert habe, funzt alles!
nur ich hab da ja nen filechooser und ne tabelle mit nem eigenen tablemodel von abstracttablemodel abgeleitet!
wenn ich da aber eine datei auswähl, dann wird die nicht in die tabelle eingefügt!
was kann ich machen?

Quellcode meine GUI bzw JApplet:

```
/*
 * Upload.java
 *
 * Created on 01. Oktober 2007, 10:54
 */

package uploader;



/**
 *
 * @author  alle
 */
public class Upload extends java.applet.Applet
{
  TableModel tm;

  
  /**
   * Initializes the applet Upload
   */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {
        public void run()
        {
          initComponents();
          tm = new TableModel();
          tbData.setModel(tm);
        }
      });
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }
  
  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
  private void initComponents()
  {
    fcBrowse = new javax.swing.JFileChooser();
    jScrollPane1 = new javax.swing.JScrollPane();
    tbData = new javax.swing.JTable();
    jPanel1 = new javax.swing.JPanel();
    btBrowse = new javax.swing.JButton();
    btDeleteSelected = new javax.swing.JButton();
    btDeleteAll = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    btUpload = new javax.swing.JButton();
    pbStatus = new javax.swing.JProgressBar();
    btStop = new javax.swing.JButton();

    fcBrowse.setDialogTitle("Browse");

    setLayout(new java.awt.BorderLayout());

    tbData.setAutoCreateRowSorter(true);
    tbData.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][]
      {

      },
      new String []
      {
        "Name", "Size", "Directory", "LastModified"
      }
    )
    {
      Class[] types = new Class []
      {
        java.lang.String.class, java.lang.Long.class, java.lang.String.class, java.lang.Long.class
      };

      public Class getColumnClass(int columnIndex)
      {
        return types [columnIndex];
      }
    });
    jScrollPane1.setViewportView(tbData);

    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jPanel1.setLayout(new java.awt.GridLayout(1, 3));

    btBrowse.setText("Browse");
    btBrowse.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(java.awt.event.ActionEvent evt)
      {
        btBrowseActionPerformed(evt);
      }
    });

    jPanel1.add(btBrowse);

    btDeleteSelected.setText("Delete Selected");
    btDeleteSelected.addKeyListener(new java.awt.event.KeyAdapter()
    {
      public void keyPressed(java.awt.event.KeyEvent evt)
      {
        onKlick(evt);
      }
    });

    jPanel1.add(btDeleteSelected);

    btDeleteAll.setText("Delete All");
    btDeleteAll.setActionCommand("jButton3");
    btDeleteAll.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(java.awt.event.ActionEvent evt)
      {
        btDeleteAllActionPerformed(evt);
      }
    });
    btDeleteAll.addKeyListener(new java.awt.event.KeyAdapter()
    {
      public void keyPressed(java.awt.event.KeyEvent evt)
      {
        onKlick(evt);
      }
    });

    jPanel1.add(btDeleteAll);

    add(jPanel1, java.awt.BorderLayout.NORTH);

    jPanel2.setLayout(new java.awt.GridLayout(1, 3));

    btUpload.setText("Upload");
    btUpload.setMaximumSize(new java.awt.Dimension(30, 23));
    btUpload.setMinimumSize(new java.awt.Dimension(30, 23));
    btUpload.setPreferredSize(new java.awt.Dimension(30, 23));
    jPanel2.add(btUpload);

    jPanel2.add(pbStatus);

    btStop.setText("Stop");
    jPanel2.add(btStop);

    add(jPanel2, java.awt.BorderLayout.SOUTH);

  }// </editor-fold>                        

  private void btDeleteAllActionPerformed(java.awt.event.ActionEvent evt)                                            
  {                                                
    tm.removeAll();
  }                                           

  private void onKlick(java.awt.event.KeyEvent evt)                         
  {                             
    tm.removeFile(tbData.getSelectedRow());
  }                        

  private void btBrowseActionPerformed(java.awt.event.ActionEvent evt)                                         
  {                                             
    fcBrowse.showOpenDialog(this);
    fcBrowse.setVisible(true);
    tm.addFile(fcBrowse.getSelectedFile());
  }                                        
  
  
  // Variables declaration - do not modify                     
  private javax.swing.JButton btBrowse;
  private javax.swing.JButton btDeleteAll;
  private javax.swing.JButton btDeleteSelected;
  private javax.swing.JButton btStop;
  private javax.swing.JButton btUpload;
  private javax.swing.JFileChooser fcBrowse;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JProgressBar pbStatus;
  private javax.swing.JTable tbData;
  // End of variables declaration                   
  
}
```


Quellcode meiner Classe TableModel:

```
/*
 * TableModel.java
 *
 * Created on 01. Oktober 2007, 15:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package uploader;

import java.io.File;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Samuel Weirer
 */
public class TableModel extends AbstractTableModel
{
   Data data;
   File file;
   int rowCount = 4;
   int columnCount = 4;
   Object valueAt;
   Vector<Data> v = new Vector<Data>();
  
   
    /**
   * Creates a new instance of TableModel
   */
    public TableModel()
    {
       this.setValueAt(data, rowCount, columnCount);
    }

    
    
    public void addFile(File file)
    {
      data = new Data(file);
      v.add(data);
      rowCount ++;
      
    }
    
    public void removeFile(int index)
    {
      v.remove(index);
    }
    
    public void removeAll()
    {
      v.removeAllElements();
    }
    
    public int getRowCount()
    {
        return rowCount;
    }

    public int getColumnCount()
    {
        return columnCount;
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        return valueAt;
    }
    
}
```


Quellcode meiner Klasse Data:

```
/*
 * Data.java
 *
 * Created on 01. Oktober 2007, 15:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package uploader;

import java.io.File;

/**
 *
 * @author Samuel Weirer
 */
public class Data
{
    
    private File file;
    private String name;
    private String directory;
    private long size;
    private long modified;
    
    
    
    /** Creates a new instance of Data */
    public Data(File aFile)
    {
        setFile(aFile);
    }
    
    
    public File getFile()
    {
        return file;
    }
    
    public void setFile(File file)
    {
        this.file = file;
    }
    
    public String getName()
    {
        name = file.getName();
        return name;
    }
    
    public String getDirectory()
    {
        directory = file.getPath();
        return directory;
    }
    
    public long getSize()
    {
        size = file.length();
        return size;
    }
    
    public long getModified()
    {
        modified = file.lastModified();
        return modified;
    }
    
}
```

vll hilfts ja!

Lg.


----------

