File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Unable to display the Applet in jsp display tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Unable to display the Applet in jsp display tomcat" Watch "Unable to display the Applet in jsp display tomcat" New topic
Author

Unable to display the Applet in jsp display tomcat

aristal wang
Greenhorn

Joined: Dec 23, 2006
Posts: 14
I am currently using jCreator.

The following is my applet code:
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//-----------------------------------------> import abv 4 line

import java.util.Calendar;
import java.util.Date;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.IntervalCategoryDataset;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/** Application to create a Ganttchart * */

//-----------------------------------------> change extends to JApplet instead of ApplicationFrame
public class Ganttchart extends JApplet{

/** Get Info **/
//String name = req.getParameter("Task");
//SimpleTimePeriod(date(1, Calendar.APRIL, 2001)


/** @param title , frame title **/

//-----------------------------------------> change the public Ganttchart to void init()
public void init() {

// super(title); -----------------------------------------> comment this line

final IntervalCategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);

// add the chart to a panel...
final ChartPanel chartPanel = new ChartPanel(chart);

// this size (500, 270) here doesn't matter cos this become the html control
// how big you wan can change in the html code the width="800" height="600"
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));


setContentPane(chartPanel);

}

/**
* Creates a sample dataset for a Ganttchart.
*
* @return The dataset.
*/
public static IntervalCategoryDataset createDataset() {

final TaskSeries s1 = new TaskSeries("Scheduled");
s1.add(new Task("Write Proposal",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(5, Calendar.APRIL, 2001))));
s1.add(new Task("Obtain Approval",
new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
date(9, Calendar.APRIL, 2001))));
s1.add(new Task("Requirements Analysis",
new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
date(5, Calendar.MAY, 2001))));



final TaskSeries s2 = new TaskSeries("Actual");
s2.add(new Task("Write Proposal",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(5, Calendar.APRIL, 2001))));
s2.add(new Task("Obtain Approval",
new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
date(9, Calendar.APRIL, 2001))));
s2.add(new Task("Requirements Analysis",
new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
date(15, Calendar.MAY, 2001))));

final TaskSeriesCollection collection = new TaskSeriesCollection();
collection.add(s1);
collection.add(s2);

return collection;
}

/**
* Utility method for creating <code>Date</code> objects.
*
* @param day the date.
* @param month the month.
* @param year the year.
*
* @return a date.
*/
private static Date date(final int day, final int month, final int year) {

final Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
final Date result = calendar.getTime();
return result;

}

/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createGanttChart(
"Ganttchart", // chart title
"Task", // domain axis label
"Date", // range axis label
dataset, // data
true, // include legend
true, // tooltips
false // urls
);
// chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
return chart;
}



}
---------------------------------------------------------------------------
The following is the jsp code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- DW6 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<link rel="stylesheet" href="2col_leftNav.css" type="text/css">
<style type="text/css">
<!--
.style3 {
font-size: large;
font-weight: bold;
}
-->
</style>
</head>
<!-- The structure of this file is exactly the same as 2col_rightNav.html;
the only difference between the two is the stylesheet they use -->
<body>
<div id="masthead">
<table width="97%" border="0" cellspacing="2" cellpadding="4">
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>Supplier</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>Company</strong>:  <Display company name from database> </td>
</tr>
</table>
<h1 id="siteName"> </h1>
<h1>Project:<BR>
  <Display main project>-<Display sub-project> </h1>
</div>
<div id="content">
<div class="feature">
<p><applet code="Ganttchart.class"
width="500" height="500" class="feature">
</applet>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p class="style3">Task Information </p>
<table width="90%" border="0" cellpadding="8" bgcolor="#FFFFFF">
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">Task</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="company" type="text" id="company" size="50"></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">Preprocessor</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="country" type="text" id="country" size="50"></td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">Task start on</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="s_dd" type="text" id="s_dd" size="2">
DD
<input name="s_mth" type="text" id="s_mth" size="2">
MTH
<input name="s_yyyy" type="text" id="s_yyyy" size="4">
YYYY</td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">Task end on</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="s_dd" type="text" id="s_dd" size="2">
DD
<input name="s_mth" type="text" id="s_mth" size="2">
MTH
<input name="s_yyyy" type="text" id="s_yyyy" size="4">
YYYY</td>
</tr>
<tr valign="top">
<td align="right" bgcolor="#CCCCCC">Duration</td>
<td colspan="2" bgcolor="#FFFFFF"><input name="duration" type="text" id="duration" size="3">
days</td>
</tr>
</table>
<p>
<input name="New Task" type="submit" id="New Task" value="New Task">
<input type="submit" name="Submit" value="Update">
</p>
<p>  </p>
<p> </p>
</div>
<div class="project_info"></div>
</div>
<!--end content -->
<div id="navBar">
<div id="search"> </div>
<div id="sectionLinks">
<ul>
<li><a href="#">Main Project listing </a></li>
<li><a href="#">Sub Project listing </a></li>
</ul>
</div>
<div class="relatedLinks">
<h3> </h3>
</div>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<table width="94%" border="0" cellspacing="2" cellpadding="4">
<tr>
<td align="center" bgcolor="#CCCCCC"><div align="left"><a href="javascript:history.go(-1)">Back</a> | <a href="#">Email Subcontractor</a></div></td>
</tr>
</table>
<p> </p>
</body>
</html>

I have no problem compiling the applet but i have problem displaying the jsp in tomcat.I've tried replacing the Ganttchartt.class by other applet and it works fine in Tomcat

Can anyone tell me what could be the problem?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  70
Welcome to Javaranch.

but i have problem displaying the jsp in tomcat

What does this mean - what kind of problem? Does anything get displayed, are there error messages either in the browser status bar or the Java Console?
aristal wang
Greenhorn

Joined: Dec 23, 2006
Posts: 14
I have no problem compiling the java applet but I have problem displaying it in the browser (http://localhost:8080/FYP/Project_info.jsp). It says,"applet Ganttchart not initiated" in the bottom left hand corner of the IE
I manage to compile the applet in jCreator though
[ December 23, 2006: Message edited by: aristal wang ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  70
That message means that either the class file was not found (check that it is present in the same directory as the JSP page, and that it is accessible over HTTP), or that an exception occurred during initialization of the applet (in which case there should a stack trace in the Java Console).

On closer examination, your applet tag does not contain an "archive" attribute that includes the JFreeChart library. That will prevent the applet from running.
[ December 23, 2006: Message edited by: Ulf Dittmer ]
aristal wang
Greenhorn

Joined: Dec 23, 2006
Posts: 14
I'm sorry but can you please enlighten me how i should go about doing this?

thank you
aristal wang
Greenhorn

Joined: Dec 23, 2006
Posts: 14
Hey hey, I've finally been able to solve the mystery.

<applet code=Ganttchart archive="jfreechart-0.9.21.jar, jcommon-0.9.6.jar" width="500" height="500" >
</applet>

thanks for the guidance.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unable to display the Applet in jsp display tomcat