|
Is your code written as an Applet? (i.e. your main class extends java.applet.Applet or javax.Swing.JApplet ?) If not, it won't work as an applet. Google java applet for more information.
Peter
[edit] corrected typo - Swing is in javax not java [/edit]
Software rusts. Simon Stephenson, ca 1994.
modified on Wednesday, August 17, 2011 9:51 PM
|
|
|
|
|
Well, the class extends an applet, but could you check it for me ? its pretty short.
import java.applet.*;
import java.awt.*;
public class Testapp extends Applet {
public String hdr = "abcd";
public void init() {
super.init();
}
public void paint(Graphics g) {
super.paint(g);
g.drawString(hdr, 5, 15);
}
}
Could it be that i have to make a Main and then create a new object? would be silly if u ask me
|
|
|
|
|
Roysten1818 wrote:
Could it be that i have to make a Main and then create a new object? would be silly if u ask me No. your code looks fine from that aspect.
Roysten1818 wrote: could you check it for me ? Sorry, don't have the resources right now.
jschell's suggestions are good - have a look at what is getting delivered from the server.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Roysten1818 wrote: to the HTML file The Testapp is a .class file and the server can find the
file and sends it.
To verify.
1. The client requests the html.
2. The server sends it.
3. The client requests that applet
4. The server sends it.
If so I would guess the problem is the content of 4.
Simple way to figure out what is really in there.
1. Get another http server.
2. Set it up to send the applet.
3. Verify everything works.
4. Run with a network sniffer in place to see what the client/server traffic looks like.
You will find a difference. Once you find the difference then go track down the relevant RFCs and read them to understand what it is doing.
|
|
|
|
|
Oeh! thats a neat idea, will do it first thing in the morning! will edit this post with the result...
i hope its a problem with the header or else it would a lot more work!
thanks already
|
|
|
|
|
hi there i am working on a project that my goal is when i run my code it will create another file(classes) (exp: personalList.java) and user must associate with second file. for example;
i have a file "PersonalDatabaseCreator.java" and this file creates "Person.java" (which is my object and includes properties getters setters etc.) and "PersonalList.java" which user will interact. (PersonalList.java ask the location of the text file which contains people to add into a LinkedList. Therefore, user will do add search remove etc. operations). but the problem it only works when i create classes in IDE myself and copying the code into them and run them. so i need a code which will do it itself!. you will say i am working on a silly project : D. but i wonder if is there any code samples like this_?. and i hope i explained my problem correctly. so thanks anyway : ).
|
|
|
|
|
quartaela wrote: you will say i am working on a silly project
No, you said that.
|
|
|
|
|
well ok you are right : ). i will delete the topic .
|
|
|
|
|
Createing code at runtime and then compiling it is possible.
Certainly sounds like you are missing the second part of that. You can find examples of that.
However nothing in your post really suggests why you need that.
|
|
|
|
|
yess i mean this. well i am taking java courses and i want some java homework so he told me that i can work on this subject.: )
|
|
|
|
|
yess i mean this. well i am taking java courses and i want some java homework so he told me that i can work on this subject.: ) finally i created the code and it creates the files which must be compiled. so only the problem is how can i compile them : )
|
|
|
|
|
Yes you can do this. Java 1.6 has an interface JavaCompiler that lets you call the compiler from within code. There is an article here:
The Java 6.0 Compiler API[^]
Depending on what you are trying to achieve (it's not entirely clear to me), you may find something like BeanShell a better solution.
BeanShell[^]
|
|
|
|
|
well i will have a search on these links. thanks mate : )
|
|
|
|
|
Hi All,
I am using JSP and servlet technology for making graphs.
Below please find my jsps,
Display.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.awt.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import="org.jfree.chart.labels.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.CategoryItemRenderer" %>
<%@ page import="org.jfree.chart.urls.*" %>
<%@ page import="org.jfree.data.*" %>
<%@ page import="org.jfree.data.CategoryDataset" %>
<%
final double[][] data = new double[][]{{210, 300, 320, 265, 299},{200, 304, 201, 201, 340}};
final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Team ", "", data);
final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", "", "Value", dataset, PlotOrientation.VERTICAL,true, true, false);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setForegroundAlpha(0.5f);
chart.setBackgroundPaint(new Color(249, 231, 236));
try {
final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
File file1 = new File("../webapps/jspGraphFunction/web/areachart.png");
ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
} catch (Exception e) {
out.println(e);
}
%>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<!-- <IMG SRC="areachart.png" WIDTH="600" HEIGHT="400" BORDER="0"
USEMAP="#chart">-->
<IMG SRC="web/areachart.png" WIDTH="600" HEIGHT="400" BORDER="0"
USEMAP="#chart">
</body>
</html>
Now its giving the below error for the bolded statement in the code:
Quote:
The method createAreaChart(String, String, String, CategoryDataset, PlotOrientation,
boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments
(String, String, String, CategoryDataset, PlotOrientation, boolean, boolean, boolean)
On net only this way of using the jfreechart is given
I have included the two jars Jfreechart... and jcommon in my lib folder.
Pls suggest,
Chandan
|
|
|
|
|
You need to check if the FQN (full qualified name) of the classes that you are passing to the function are the same as those expected by the class. Make sure the CategoryDataset and the PlotOrientation are correct.
Also your programming environment should already be warning you when calling this type of method incorrect.
|
|
|
|
|
All things are correct it is giving error in the below code of line
final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", "", "Value", dataset, PlotOrientation.VERTICAL,true, true, false);
telling that
The method createAreaChart(String, String, String, CategoryDataset, PlotOrientation,
boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments
(String, String, String, CategoryDataset, PlotOrientation, boolean, boolean, boolean)
everything is correct seems, dont bother about the names these are correct, also CategoryDataset and the PlotOrientation are correct
I have given the warning and error in the underline lines above.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Regards
Chandan
|
|
|
|
|
I everyone,
I'm currently initiating the development of a web app in GWT and I was thinking if JAAS is the way to go for me. In every article I've read so far JAAS is configured in an XML file, something like this:
<security-role-mapping>
<role-name>USERS</role-name>
<group-name>Users</group-name>
</security-role-mapping>
Which makes me wonder: will I be able to add roles, users, groups, etc, programmatically (without restarting the server)? If the application grows in a great deal of number of users (and roles, etc), will it escalate?
Not sure if it matters, but I'm using NetBeans + GlassFish.
regards
Fratelli
|
|
|
|
|
I need to execute unix commands in the putty prompt via java code.
So far :
String[] cmdArray = {"putty.exe", "server IP"};
Runtime.exec(cmdArray);
has got the prompt open.
Need help to interact with this window and execute other commands.
|
|
|
|
|
Try reading the documentation[^].
You should be able to execute a remote file, see 3.8.3.6 -m: read a remote command or script from a file in the above link.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
ProcessBuilder and Process may help. You can get an output stream for the Process and send input to the command line through that.
|
|
|
|
|
Hi All,
I am little bit new to struts framework though I have used tiles in struts application. Now I want to display charts in my application. After searching I found jFreechart library to create charts. (Though it doesn't generate all the charts, like box in web application).
Now I also found some link on how to use jFreechart in struts application. Though the post are not much descriptive, I tried in the same way to incorporate the chart functionality but it is not working......
Can someone please provide the entries to be made in [B]struts.xml[/B], [B]web.xml[/B] to make this functionality work.
Pls find below the different files I am using to run my application.
I have made the changes that I made for graph functionality in bold
[B][I][U]Struts.xml[/U][/I][/B]
[CODE]="1.0"="UTF-8"
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="portal" namespace="/portal" extends="struts-default , [B]jfreechart-default[/B]
">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
[B]<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
<param name="height">150</param>
<param name="width">200</param>
</result-type>[/B]
</result-types>
<global-results>
<result name="error">/pages/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.NullPointerException" result="error"/>
<exception-mapping exception="java.lang.NumberFormatException" result="error"/>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
<action name="Login" class="graph.Login">
<result name="success">/pages/display.jsp</result>
<result name="error">/pages/login.jsp</result>
<result name="input">/pages/login.jsp</result>
</action>
[B]<action name="Graph" class="graph.Graph">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">png</param>
<param name="width">640</param>
<param name="height">480</param>
</result>
<result name="error">/pages/display.jsp</result>
</action>
[/B]
</package>
</struts>[/CODE]
[B][I][U]web.xml[/U][/I][/B]
[CODE]="1.0"="UTF-8"
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>graphFunctionWeb</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>Tiles Filter</filter-name>
<filter-class>org.apache.tiles.web.startup.TilesFilter</filter-class>
<init-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
</param-value>
</init-param>
</filter>
[B] <filter>
<filter-name>Chart Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ChartResult</filter-class>
</filter>[/B]
<filter-mapping>
<filter-name>Chart Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>Tiles Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
[B]<filter-mapping>
<filter-name>Chart Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>[/B]
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/pages/login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.apache.tiles.servlet.TilesServlet</servlet-class>
<init-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
</web-app>[/CODE]
[B][I][U]Graph.java[/U][/I][/B]
[CODE]package graph;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.data.*;
import com.opensymphony.xwork2.ActionSupport;
public class Graph extends ActionSupport {
private JFreeChart chart;
public String execute() throws Exception {
// chart creation logic...
XYSeries dataSeries = new XYSeries("first"); // pass a key for this serie
for (int i = 0; i <= 100; i++) {
dataSeries.add(i, i+100);
}
XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
ValueAxis xAxis = new NumberAxis("Raw Marks");
ValueAxis yAxis = new NumberAxis("Moderated Marks");
// set my chart variable
chart =
new JFreeChart( "Moderation Function", JFreeChart.DEFAULT_TITLE_FONT,
new XYPlot( xyDataset, xAxis, yAxis, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
false);
chart.setBackgroundPaint(java.awt.Color.white);
return SUCCESS;
}
// this method will get called if we specify <param name="value">chart</param>
public JFreeChart getChart() {
return chart;
}
}[/CODE]
After logging I am redirecting to display.jsp
[CODE]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Graph display</title>
</head>
<body>
hellooooooooooooooooooo
<div align="center">
<center>
<table border = "0" cellpadding = "0" cellspacing = "0" width="400">
<tr>
<td>
<ul>
<li><a href="portal/Graph.action">Login Application </a></li>
</ul>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>[/CODE]
The error I am getting is :
[COLOR="Red"]SEVERE: Exception starting filter Chart Filter
java.lang.ClassCastException: org.apache.struts2.dispatcher.ChartResult cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Aug 10, 2011 10:08:08 AM org.apache.catalina.core.ApplicationContext log
INFO: TilesDecorationFilter:Initializing filter
Aug 10, 2011 10:08:09 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Aug 10, 2011 10:08:09 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/graphFunctionWeb] startup failed due to previous errors
Aug 10, 2011 10:08:09 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/graphFunctionWeb] created a ThreadLocal with key of type [com.opensymphony.xwork2.ActionContext.ActionContextThreadLocal] (value [com.opensymphony.xwork2.ActionContext$ActionContextThreadLocal@ce16ad]) and a value of type [com.opensymphony.xwork2.ActionContext] (value [com.opensymphony.xwork2.ActionContext@32bd65]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Aug 10, 2011 10:08:09 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/graphFunctionWeb] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@130633a]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@1c286e2]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Aug 10, 2011 10:08:10 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Aug 10, 2011 10:08:10 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Aug 10, 2011 10:08:10 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/58 config=null
Aug 10, 2011 10:08:10 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2670 ms[/COLOR]
//////////////////////////////////////////////////////////////////////////////////
But the same code runs when I remove the chart functionality from the xml files. please check and provide some input, will appreciate if u will provide the code snippet.
Some links I checked like, [url]http://struts.apache.org/2.1.6/struts2-plugins/struts2-jfreechart-plugin/apidocs/org/apache/struts2/dispatcher/ChartResult.html[/url]
but not much useful.
Regards,
Chandan
|
|
|
|
|
Pls help and provide the way .....
|
|
|
|
|
How to check with Java that a program is installed on Linux or Mac.
In windows I can check registry for a specific entry or to check the existence of program folder.
Thanks.
|
|
|
|
|
This is not really a Java issue, more one of how to get information from the OS. You would probably need to research program installation on each of these platforms. See also the Java Desktop[^] class.
|
|
|
|
|
Pretty sure there is an environmnet variable that specifies the windows version.
That won't exist on OSX
Probably something similar on OSX.
Although there might even be a VM specific value that has such information.
You can use System.getProperties() to list all the env vars for the VM.
|
|
|
|
|