Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: java applet program question (on getting path fails)

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java applet program question (on getting path fails)

    import java.applet.Applet;
    import java.awt.Graphics;
    import java.io.*;
    import java.awt.Color;
     
    public class chatbox extends Applet {
    	public String test() 
        {
            setBackground(Color.white);
     
    	String fileName = System.getProperty("user.home") +
    				  System.getProperty("file.separator") + "newfile";
    	String msg  = "This message was written by a signed applet!!!\n";
    	String s ;
     
    	try {
    	    FileWriter fos = new FileWriter(fileName);
    	    fos.write(msg, 0, msg.length());
    	    fos.close();
    	    s = new String("Successfully created file :" + fileName);
     
    	} catch (Exception e) {
    	    System.out.println("Exception e = " + e);
    	    e.printStackTrace();
    	    s = new String("Unable to create file :  " + fileName);
    	}
    	return s;
        }	
     
    	  public void paint(Graphics g)
    	  { 
     
     
     
     
    		  g.setColor(Color.blue);
    	        g.drawString("Signed Applet Demo", 120, 50);
    	        g.setColor(Color.magenta);
    	        g.drawString(test(), 50, 100);
     
     
    	  }
    }

    Running this in regular java it works. RUnning it in an applet it fails. test() for example is where it should show a string of the cache path.


    System.getProperty("user.home") fails in general when requesting it.

    Is there any way to still do this without it failing. Like a way to ask users permission to run.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: java applet program question (on getting path fails)

    From your problem description, it seems like you are working on MAC OS.
    Anyways, you should make a static method to read this path that would execute before any action performed.
    Hope this will help.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java applet program question (on getting path fails)

    No I am working on windows number 1
    Number 2, can someone give me an example of how to sign in an applet so I can get this to work.

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java applet program question (on getting path fails)

    Or if there is a way to tell users I am getting their path so they can accept it.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java applet program question (on getting path fails)

    Thank second link leads you to the best step by step description I've found. Worked for me the first time through, but your mileage may vary.

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java applet program question (on getting path fails)

    Signing in applets somehow pissed me off.

    I hate the restrictions. I know you have to get certified and everything but we have to wait days just to get certified. Why couldn't it just be. Hello java is trying to activate you, Do you accept permissions to let java run.

Similar Threads

  1. Applet paint program frame work.
    By ShaunB in forum Java Swing Tutorials
    Replies: 4
    Last Post: October 31st, 2012, 08:44 AM
  2. Replies: 3
    Last Post: March 17th, 2011, 10:09 AM
  3. locating the path to a jar file within a program
    By nemo in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 2nd, 2011, 05:41 PM
  4. how to get full path name from realtive path
    By priyanka3006 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: August 10th, 2009, 04:28 AM
  5. [SOLVED] How to a set java class path?
    By captjade in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2009, 06:40 AM