This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes Displaying Farsi in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Displaying Farsi in applet" Watch "Displaying Farsi in applet" New topic
Author

Displaying Farsi in applet

Farid Abdi
Greenhorn

Joined: Dec 25, 2012
Posts: 12

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Farsi in applet
 
Similar Threads
Problem render whit trinidad
counter doesnt work
Whats wrong with this?
Please help me run this applet
Images not shown in Applet