Hey,

I am having a NIGHTMARE of a time trying to write a simple applet client for ftp over SSH. I thought it was going to be the networking syntax that was going to give me trouble. Turns out its the gui that I am getting most gyp with.

The part that I am most stuck with is trying to create a box that displays the local file system and a box that contains the server file system. I looked at using a JFilechooser but it turned out that wouldnt do what I wanted so I thought, I know I will use a JTree. That looked like the perfect solution but then I couldnt get it to work accessing the file system.

Now, It would be a school boy error to overlook the fact that an applet cannot access a files or clipboard on a machine unless it is trusted. SO I created a certificate for permission and a JAR file to allow it permission to access the system, but now my main applet cannot access any of the external classes that I have written. Let me elaborate on the situation so far:

I have:

Sting.java
Sting.class


Description: This is the main Applet code

----------------------------

guiLayout.java
guiLayout.class


Description: This is the swing portion of the applet. I put it in a separate class so that It would keep to some form of OOP.

---------------------------

StingAuth - Certificate
Sting.Jar - JAR file
Sting.Bat - Batch file for compiling the JAR.


Here is the code from Sting.java:

Code:
/*
	***********************************

	Sting SFtp
	Creator: Stephen Cheesley
	Designer: Stephen Cheesley

	***********************************
*/

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFileChooser.*;
import javax.swing.filechooser.*;
import java.applet.*;

public class Sting extends JApplet //implements ActionListener
{

	private Component me;

	public void init()
	{
		try
		{
			javax.swing.SwingUtilities.invokeAndWait(new Runnable()
			{
				public void run()
				{
			    	guiLayout steve = new guiLayout();
			    	getContentPane().add(steve);
			    }
			});

		}
		catch (Exception e)
		{
			System.err.println("ActionEvent e FOULED UP");
		}
	}

	public void start()
	{

	}

	public void stop()
	{

	}

}
Here is the code for guiLayout.java

Code:
/*
	***********************************

	Sting SFtp

	guiLayout.class is a package belonging to
	Sting SFtp. It is responsible for the look
	and feel of the software.

	Creator: Stephen Cheesley
	Designer: Stephen Cheesley

	***********************************
*/

import java.io.*;
import java.io.File;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFileChooser.*;
import java.applet.*;
import java.util.*;
import java.lang.*;

public class guiLayout extends JApplet implements ActionListener
{
	public guiLayout()
	{

		//Where the variables are created:
		JMenuBar menuBar;
		JMenu file, help;
		JMenuItem menuItem;
		final JPanel welcome, files_local, files_server;
		JLabel Wlabel, Llabel, Slabel, about1;
		JButton testButton;

		// *****************************************************


		// *****************************************************

		// ------------------------------------------------
		//|					MenuBar Setup				   |
		// ------------------------------------------------


		//Create the menu bar.
		menuBar = new JMenuBar();

		//Create file menu.
		file = new JMenu("File");
		file.setMnemonic(KeyEvent.VK_A);
		file.getAccessibleContext().setAccessibleDescription(
		        "The only menu in this program that has menu items");
		menuBar.add(file);

			//Add Items to the file menu
			menuItem = new JMenuItem("Cut");
			file.add(menuItem);
			menuItem = new JMenuItem("Copy");
			file.add(menuItem);
			menuItem = new JMenuItem("Paste");
			file.add(menuItem);
			file.addSeparator();
			menuItem = new JMenuItem("Logout");
			file.add(menuItem);

		//Create help menu
		help = new JMenu("Help");
		menuBar.add(help);

			//Add Items to the help menu
			menuItem = new JMenuItem("Readme");
			help.add(menuItem);
			// help.addSeparator();  --- Separator
			menuItem = new JMenuItem("About Sting...");
			help.add(menuItem);
			menuItem.addActionListener(this);
			menuItem.setActionCommand("about");

		//Add the menu bar to the GUI
		setJMenuBar(menuBar);

		// *****************************************************



		// *****************************************************

		// ------------------------------------------------
		//|					Panel Layout				   |
		// ------------------------------------------------

		// This section sets the three main layout panels in
		// positions top left and right.


		// The top "Welcome" panel
		welcome = new JPanel();
		welcome.setBackground(Color.white);
		getContentPane().add(welcome, BorderLayout.PAGE_START);
		Wlabel = new JLabel("Welcome <user> ...");
		welcome.add("West",Wlabel);
		testButton = new JButton("Test");
		welcome.add(testButton);


		// The left panel for local file handler
		files_local = new JPanel();
		files_local.setBackground(Color.red);
		getContentPane().add(files_local, BorderLayout.LINE_START);
		Llabel = new JLabel("Local Files     ");
		files_local.add(Llabel);


		//The right panel for server file Handler
		files_server = new JPanel();
		files_server.setBackground(Color.blue);
		getContentPane().add(files_server, BorderLayout.LINE_END);
		Slabel = new JLabel("Server Files      ");
		files_server.add(Slabel);

		// -------------------------------------------------

		testButton.addActionListener(this);
		testButton.setActionCommand("test");

		// *****************************************************

		// -----------------------------------------------------
		// Create JTree
		// -----------------------------------------------------

	}
/*
JTree dirTree = null;


public void FileTree()
{
        //initComponents();
        File dir = new File("C:/j2me");
        dirTree = new JTree(dir.listFiles());
        dirTree.setPreferredSize(new Dimension(200, 400));
        files_local.add(dirTree);
        //this.setSize(350,450);
}*/



	// ******************************************************************************

	// -------------------------------------------------------------------
	//
	//
	public void actionPerformed(ActionEvent e)
	{
		String s = e.getActionCommand();

		if(s==("about"))
		{
			JLabel about1, about2, about3, title;
			JPanel about;

			about1 = new JLabel("Sting SFTP...");
			about2 = new JLabel("Written By: Stephen Cheesley");
			about3 = new JLabel("Developed: 26/06/2006");
			about = new JPanel();

			about.setLayout(new BorderLayout());
			about.add("North", about1);
			about.add("Center",about2);
			about.add("South",about3);

			JOptionPane.showMessageDialog(getContentPane(),about,"Sting SFTP",JOptionPane.PLAIN_MESSAGE);
		}
		else if(s==("test"))
		{
			/*
			final JFileChooser chooser = new JFileChooser();
   			int returnVal = chooser.showOpenDialog(this);
			if (returnVal == JFileChooser.APPROVE_OPTION)
			{
				File file = chooser.getSelectedFile();
				//if (file!=null)
				//{}// do something with file
			}*/

		}

    }
}
I hope someone can help as this has become really frustrating.

Many thanks,

Steve