Hi
I have a problem in displaying Farsi in
Java applications and applets...When I click on 1.html the Farsi
string is not displayed and starnge things is displayed...How I can solve this problem ???
thanks very much
when i click SiteSelctor.html ... there is no problem...but when i click 1.html..the Farsi is not displayed correctly....I have this problem in both
applets and applications...........
1.html :
<html>
<head>
<title>Site Selecting Application</title>
</head>
<body>
<applet code = "SiteSelector.class" width = "300" height = "75">
<param name = "title0" value = "بلاگفا">
<param name = "location0" value = "http://www.blogfa.com">
<param name = "title1" value = "Java World Website">
<param name = "location1" value = "http://www.javaworld.com">
</applet>
</body>
</html>
SiteSelector.html :
<html>
<head>
<title>Site Selector</title>
</head>
<body>
<applet code = "SiteSelector.class" width = "300" height = "75">
<param name = "title0" value = "Java Home Page">
<param name = "location0"
value = "http://www.oracle.com/technetwork/java/">
<param name = "title1" value = "Deitel">
<param name = "location1" value = "http://www.deitel.com/">
<param name = "title2" value = "JGuru">
<param name = "location2" value = "http://www.jGuru.com/">
<param name = "title3" value = "JavaWorld">
<param name = "location3" value = "http://www.javaworld.com/">
</applet>
</body>
</html>
SiteSelctor.java :
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.ArrayList;
import java.awt.BorderLayout;
import java.applet.AppletContext;
import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class SiteSelector extends JApplet
{
private HashMap< String, URL > sites; // site names and URLs
private ArrayList< String > siteNames; // site names
private JList siteChooser; // list of sites to choose from
// read parameters and set up GUI
public void init()
{
sites = new HashMap< String, URL >(); // create HashMap
siteNames = new ArrayList< String >(); // create ArrayList
// obtain parameters from XHTML document
getSitesFromHTMLParameters();
// create GUI components and lay out interface
add( new JLabel( "Choose a site to browse" ), BorderLayout.NORTH );
siteChooser = new JList( siteNames.toArray() ); // populate JList
siteChooser.addListSelectionListener(
new ListSelectionListener() // anonymous inner class
{
// go to site user selected
public void valueChanged( ListSelectionEvent event )
{
// get selected site name
Object object = siteChooser.getSelectedValue();
// use site name to locate corresponding URL
URL newDocument = sites.get( object );
// get applet container
AppletContext browser = getAppletContext();
// tell applet container to change pages
browser.showDocument( newDocument );
} // end method valueChanged
} // end anonymous inner class
); // end call to addListSelectionListener
add( new JScrollPane( siteChooser ), BorderLayout.CENTER );
} // end method init
// obtain parameters from XHTML document
private void getSitesFromHTMLParameters()
{
String title; // site title
String location; // location of site
URL url; // URL of location
int counter = 0; // count number of sites
title = getParameter( "title" + counter ); // get first site title
// loop until no more parameters in XHTML document
while ( title != null )
{
// obtain site location
location = getParameter( "location" + counter );
try // place title/URL in HashMap and title in ArrayList
{
url = new URL( location ); // convert location to URL
sites.put( title, url ); // put title/URL in HashMap
siteNames.add( title ); // put title in ArrayList
} // end try
catch ( MalformedURLException urlException )
{
urlException.printStackTrace();
} // end catch
++counter;
title = getParameter( "title" + counter ); // get next site title
} // end while
} // end method getSitesFromHTMLParameters
} // end class SiteSelector