Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Applet
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
 
class Naviagte extends Applet implements ActionListener
{
	Button b1;
	URL order;
	public void init()
   	{
		b1=new Button("Click Here for Next Page");
        		b1.setBounds(150,320,150,40);
        		add(b1);
        		b1.addActionListener(this);
 
		try
       		{
        			order =new URL("C:\Program Files\Java\jdk1.6.0_13\bin\Next.html");   
        		}
        		catch(MalformedURLException e)
		{
        			System.out.println("HH");
        		}
	}	
	public void actionPerformed(ActionEvent e)
    	{
	        	if(e.getSource()==b1)
        		{
        			getAppletContext().showDocument(order);
        			System.out.println("HI");
        		}
	}
}
I am unable to run this code.
It gives error on complication, such as "illegal escape character" in line
order =new URL("C:\Program Files\Java\jdk1.6.0_13\bin\Next.html");

I have made a html file for Naviagte and Next as well I have made a java file for Next class, but I am still unable to run it.
 
Please help me.
Posted 17-Aug-12 4:44am
v2
Comments
Wes Aday at 17-Aug-12 10:08am
   
order =new URL("C:\\Program Files\\Java\\jdk1.6.0_13\\bin\\Next.html");

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I do see a couple of problems here.
  1. The first one is the one you're concerned with. The common backslash is usally an escape character in strings to denote special characters like a tabulator via \t. So if you want to include a backslash in your strings you have to escape it with a backslash: \\.
  2.  
  3. The second point is that a file path is not a URL. If you want to know the proper syntax for file URLs you should google exactly that: "File system URLs".
  4.  
  5. I'm not sure what exactly you're trying to achieve, but groping around in the file system in the java installation's bin folder looks really fishy to me. I'm not sure an applet container would even allow the access to that folder on the clients computer.
 
Regards,
 
Manfred
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,130
1 DamithSL 5,089
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,647
4 Kornfeld Eliyahu Peter 4,409


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100