Can a applet to invoke a JavaScript method?
I have a javascript method like:
<script language="JavaScript">
function openURL(strUrl) {
window.open(strUrl, "statusbar=no, scrollbar=no");
</script>
Can a applet to invoke the JavaScript method above sending "strUrl" parameter?
Yes.
http://java.sun.com/j2se/1.4.1/docs/guide/plugin/developer_guide/java_js.html
Similar Messages
-
Applet fails to call Javascript methods
I'm trying to implement round-trip javascript to Java to Javascript using LiveConnect, and having a lot of trouble in Firefox. It works perfectly in IE 6. In Firefox, I can successfully call a method of an applet, and get a return value. I have not been able to get the applet to call a Javascript method. I have tried using both the call and eval methods of the JSObject with no luck. Below is my code. Any suggestions would be appreciated.
Thanks.
import java.applet.Applet;
import java.awt.*;
import netscape.javascript.*;
public class test extends Applet {
String message="Hello Universe!";
JSObject proxy;
public void paint(Graphics g) {
g.drawString(message, 20, 20);
// pass in ref to JS object on which to call method
public Boolean handshake(JSObject jso) {
proxy = jso;
// try just calling straight eval
proxy.eval("alert('eval')");
// set up args object to pass to js method
Object[] args = new Object[1];
args[0] = "handshake";
// call method of js object 2 different ways
proxy.call("callback", args);
proxy.eval("o.callback('eval')");
return true;
// update java display to show JS to J communication
public void setMessage(String message) {
this.message = message;
repaint();
<html>
<head>
<script>
// js object to receive calls from applet
function obj() {};
obj.prototype = new Object();
obj.prototype.callback = function(arg) {
alert("callback: " + arg);
function doit() {
var a = gebi("myApplet");
a.setMessage("Goodbye World!");
o = new obj();
// test that js method works (it does)
o.callback("local");
// call applet method which should call back to js method
var there = a.handshake(o);
// show return value from applet method call
alert("there: " + there);
window.onload = doit;
</script>
</head>
<body>
<applet
id="myApplet"
code="test"
width="400"
height="50"
mayscript="mayscript">
</applet>
</body>
</html>Results:
In both IE and Firefox, the string shown by the applet switches to "goodbye world", the local call to the callback function works, and the call to handshake returns true.
That's all that works in Firefox.
In IE, the various calls to the callback method, and to the alert method of the Javascript all work.
The results are the same whether I run the HTML page as a local file, or through IIS.
I have also noticed that Firefox seems to hang up, crash, and just have a lot of problems dealing with this code.
Finally, I am running all of this on XP professional SP1 with J2SE 1.5.0_04-b05 and Firefox 1.07Hi,
Thanks for all your replies. Does this work on Java 5 too? Could you please share the complete code snippet which makes it work? I tried working on yours but no success.
Regards,
Alok -
Can an applet call one of the methods of servlet??
hi everyone...
i m very new servlet and applet programming and i have come accross a problem....
i m using a applet which establishes connection with the servlet(residing on server)..i want to use few of the methods of the servlet....
now is it possible tfor me to call the methods of this servlet using its object.???
please help me..
thanx in advancefirst of all thanx a lot for the reply...
but i wanted to know can an applet call any other
function of servlet other than get and post....as i
hacve defined some more functions in servlet..
please reply...I did this a while back (2003/4?) and unless it's changed you cannot do it directly, it must be GETor POST, then you could just use conditional logic to invoke another method. -
Can't find the Quicktime plugin Javascript methods
I am generating Quicktime embed code dynamically (using
QTGenerateOBJECTTextXHTML), with EnableJavaScript = true,
and inserting in the DOM.
The movie loads and plays back fine. I want to use Javascript methods
like Play(), GetMovieTimeScale(), etc. to control it.
I used to do this a couple of years ago and all I had to do was:
var movie = document['mymovie'];
movie.Play(); // etc.
Now when I access the plugin element (either object or embed), it
does not seem to have any of the Javascript methods.
Here's how I'm accessing the plugin object (it now varies between browsers):
In Safari:
document['mymovie'] returns an HTMLEmbedElement
document.getElementById('mymovie') returns HTMLObjectElement.
Neither one of them seems to have the Javscript methods.
In Firefox,
document['mymovie'] returns an array: [object#mymovie embed#mymovie]
document.getElementById('mymovie') returns object#mymovie
Again, neither one of them seems to have the Javscript methods.
I see the same behavior in Chrome and Opera, so I must not be looking
in the right place for the methods.
I searched these archives and the web and found hardly any recent
discussion of Quicktime Javascript scripting.
Thanks in advance for your help.Oops, I should have used code formatting for these:
var movie = document'mymovie';
object#mymovie, embed#mymovie -
Can we use JSP in a JavaScript method
Hi,
I have a following code. and I want to do a validation that whether a file exists or not before previewing it on my screen.
The code does not seem to work.
Is it the correct approach.
Please help.
<HTML>
<HEAD>
<TITLE> This is frame1 </TITLE>
<!%
private static boolean exists (String filename) {
return exists (filename, new File ("c:/image/"));
private static boolean exists (String filename, File dir) {
boolean exists = false;
filename=filename+".jpg";
if (new File (dir, filename).exists ()) {
exists = true;
} else {
File[] subdirs = dir.listFiles ();
int i = 0;
int n = (subdirs == null) ? 0 : subdirs.length;
while ((i < n) && ! exists) {
File subdir = subdirs;
if (subdir.isDirectory ()) {
exists = exists (filename, subdir);
i ++;
return exists;
%>
<script type="text/javascript">
<!-- Begin
// width to resize large images to
var maxWidth=150;
// height to resize large images to
var maxHeight=150;
// the id of the preview image tag
var outImage="previewField";
function preview(what){
var test;
var path = "C:/image/";
var source=what.value;
var finalpath = path+source+".jpg";
test= <%=exists((String)(request.getParameter("user")))%>
alert(test);
if(test = 'false')
alert("file does not exist");
//alert(finalpath);
// var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
//for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
globalPic=new Image();
var i = 0;
//alert(what.value);
globalPic.src=finalpath;
//alert(globalPic.src);
var field=document.getElementById(outImage);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
//alert(x);
field.height=y;
//alert(y);
</script>
</HEAD>
<BODY>
<table>
<form name=myform>
<tr>
<td>
<div align="center" style="line-height: 1.9em;">
Please enter the file name:
</td>
</tr>
<tr>
<td>
<input type="text" name = "user" id="picField" value='1-007156SKL'>
</td>
</tr>
<tr>
<td>
<INPUT TYPE="Submit" value="Submit" onClick = "parent.passText(this.form.user.value)">
</td>
</tr>
</table>
</form>
<INPUT TYPE="button" value="Show Image" onClick = "preview(myform.user)">
<img id="previewField" src="images.jpg">
</BODY>
</HTML>Here's the full code snippet :
<HTML>
<HEAD>
<TITLE> This is frame1 </TITLE>
<!%
private static boolean exists (String filename) {
return exists (filename, new File ("c:/image/"));
private static boolean exists (String filename, File dir) {
boolean exists = false;
filename=filename+".jpg";
if (new File (dir, filename).exists ()) {
exists = true;
} else {
File[] subdirs = dir.listFiles ();
int i = 0;
int n = (subdirs == null) ? 0 : subdirs.length;
while ((i < n) && ! exists) {
File subdir = subdirs;
if (subdir.isDirectory ()) {
exists = exists (filename, subdir);
i ++;
return exists;
%>
<script type="text/javascript">
// width to resize large images to
var maxWidth=150;
// height to resize large images to
var maxHeight=150;
// the id of the preview image tag
var outImage="previewField";
function preview(what){
var test;
var path = "C:/image/";
var source=what.value;
var finalpath = path+source+".jpg";
test= <%=exists((String)(request.getParameter("user")))%>
alert(test);
if(test = 'false')
alert("file does not exist");
//alert(finalpath);
// var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
//for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
globalPic=new Image();
var i = 0;
//alert(what.value);
globalPic.src=finalpath;
//alert(globalPic.src);
var field=document.getElementById(outImage);
var x=parseInt(globalPic.width);
var y=parseInt(globalPic.height);
if (x>maxWidth) {
y*=maxWidth/x;
x=maxWidth;
if (y>maxHeight) {
x*=maxHeight/y;
y=maxHeight;
field.style.display=(x<1 || y<1)?"none":"";
field.src=globalPic.src;
field.width=x;
//alert(x);
field.height=y;
//alert(y);
</script>
</HEAD>
<BODY>
<table>
<form name=myform>
<tr>
<td>
<div align="center" style="line-height: 1.9em;">
Please enter the file name:
</td>
</tr>
<tr>
<td>
<input type="text" name = "user" id="picField" value='1-007156SKL'>
</td>
</tr>
<tr>
<td>
<INPUT TYPE="Submit" value="Submit" onClick = "parent.passText(this.form.user.value)">
</td>
</tr>
</table>
</form>
<INPUT TYPE="button" value="Show Image" onClick = "preview(myform.user)">
<img id="previewField" src="images.jpg">
</BODY>
</HTML> -
How to call a javascript method after table load on JSFF Fragment load?
Hello,
The usecase is to invoke a javascript method after table is done loading (fetching data) when user lands to a JSFF fragment. With JSPX pages I can achieve that by using PagePhaseListener. I have tried with RegionController as follows, and the problem i face is that I cannot prevent multiple calls to the Javascript call when user presses a tab or button in a screen, or changes drop-down value with autosubmit on.
import javax.faces.context.FacesContext;
import oracle.adf.model.RegionBinding;
import oracle.adf.model.RegionContext;
import oracle.adf.model.RegionController;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
public class MyListener implements RegionController{
public MyListener() {
super();
@Override
public boolean refreshRegion(RegionContext regionContext) {
int refreshFlag = regionContext.getRefreshFlag();
System.out.println("Render flag is: "+refreshFlag);
if (refreshFlag == RegionBinding.PREPARE_MODEL)
initializeMethod();
regionContext.getRegionBinding().refresh(refreshFlag);
return false;
public boolean validateRegion(RegionContext regionContext) {
regionContext.getRegionBinding().validate();
return false;
public boolean isRegionViewable(RegionContext regionContext) {
return regionContext.getRegionBinding().isViewable();
public void initializeMethod() {
FacesContext f = FacesContext.getCurrentInstance();
ExtendedRenderKitService service = Service.getRenderKitService(f, ExtendedRenderKitService.class);
service.addScript(f, "myJSFunction();");
@Override
public String getName() {
return null;
I need the javascript to be called only once after the table is done loading when user lands to a fragment (jsff).
Any ideas appreciated?
JDeveloper version is 11.1.1.5.0
Thank you.
Valon
Edited by: Valon on Apr 11, 2013 3:10 PMOne of the requirements is to compare every row with the next row and highlight the changes. There are other requirements as well where JavaScript solution is used.
The question remains the same. Is it doable or not without changing the solution from JavaScript solution to server-side solution ? Can we call a JavaScript only once when the user lands to a jsff fragment ?
Hope that is clear.
Thanks.
Valon -
Problem with accessing Signed Applet from javascript method
Hi,
I am facing the following problem while accessing Signed Applet from javascript method.
java.security.AccessControlException: access denied (java.io.FilePermission c:/temp.txt read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at FileTest.testPerm(FileTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.invoke.JSInvoke.invoke(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin.javascript.JSClassLoader.invoke(Unknown Source)
at sun.plugin.com.MethodDispatcher.invoke(Unknown Source)
at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
at sun.plugin.com.DispatchImpl$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
I am using jdk1.5 for my development...
Can anyone help to resolve this security issue. Urgent...
Thanks in advance.Hey thanks. I wasn't able to get it to work with that sample but I did find this very similar code that does allow javascript to call JFileChooser in an applets public method.
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction()
public Object run(){
//do your special code here
return null; //return whatever you want
It seems a bit tempermental in that if you don't select a file quickly, it will hang the browser....no perfect solution but I'm going in the right direction.
Thanks,
Scott -
How would/should you invoke a javascriptable applet from WDA or WDJ?
The background to this question is here:
OK - finally a bioinformatic coding problem that may not be so easy ...
The question is as follows.
Suppose you have a javascriptable applet - that is, an applet whose behavior can be tailored by passing it certain parameters from javascript.
What would the best way be to invoke the javascript from WDA or WDJ, assuming that you wanted to "pop" the applet in a separate HTML frame within tne WDA or WDJ application?Anton -
Glad to see you contributing again!
Well, your original comment about RasMol shamed me into doing some research into molecular viewers callable as applets.
Here are the latest responses I've gotten from Angel Herraez at Jmol. (You might find it fun to join the Jmol project at SourceForge and also subscribe to its jmol-users list-server.)
I told Angel that here's what I want to do:
> 1) we're in Frame1 of a portal that has two other frames in it: FrameA and
> FrameB.
>
> 2) A query in Frame1 against a certain database brings back two sets of
> specifications for Jmol, say:
>
> a 1hru, A, 123-145
> b) 2eqa, A, 144-167
>
> 3) Via "client-side eventing" at the portal level , the portal passes the
> parameters in (a) to JMol and Jmol runs in FrameA to display the "partial"
> structure view requested (with rotate capability, same as in interactive
> JMol;
>
> 4) At the same time , the portal passes the parameters in (b) to JMol and
> Jmol runs in FrameB to display the "partial" structure view requested (with
> rotate capability, same as in interactive JMol;
>
> Is this scenario currently possible as JMol is currently written?
He then responded:
As long as you have already set the means to communicate with the
Jmol applets in your portal system, I think it is indeed.
This is what I'd pass to Jmol in FrameA:
load "1hru.pdb"; display *:A and 123-145;
and this to jmol in FrameB:
load "2eqa.pdb"; display *:A and 144-167;
(you will have to adjust the loading of the pdb file depending on
where it is located)
"display" is a better choice than the alternative, "restrict", for
reason I won't discuss now (but we can separately, if you need it)
Depending on your ways of inserting Jmol into your frames, there may
be some details to solve, but on the Jmol scripting side that's all
needed.
> Or would I have to settle for the portal simply invoking Jmol in FrameB
> and again in FrameC and letting the user manipulate settings in the
> console, as you suggest.
No, I won't suggest so, you can indeed preprogram what you want.
I also asked him about capturing the views after rotating in each frame to get the desired view of each structure, and here's his response to that:
Yes, the views can be captured to the user's computer, in a web page
(e.g. popup window) from where the user can copy or save them to
disk, using the browser's capabilities.
If you need to "capture" to the server, I cannot say *but see below.
The discussion on how to make snapshots is quite long. There are
several mesages in the list some time ago and there are several
places that use this functionality; Bob has at least one, I dont0
remember exactly where right now, and I have a testpage/tutorial at
http://biomodel.uah.es/Jmol/export-image/index.htm
See if you can make it from that, then ask if you need help.
>From the screenshot, displayed inside the browser, you can save
directly to your disk in some browsers, or else copy-paste into any
image editing program (I would not recommend Powerpoint, as the
quality of saved images is poor). You get a jpeg file directly.
Now that I think of it, in fact all the trouble was getting the
server-generated image into the client browser, so there should be a
way to store the image in the server maybe.
Anyway, will you be in LasVegas?
If so, will you be at SDN Community Day?
If neither, do you have MS shareview ????
Anyway, I will be talking soon (this weekend) in the WIKI about "alignments" and how I have to use them to get the results at StrucClues (http://strucclue.ornl.gov).
This is where the really interesting and heavy regex-ing and returned html parsing is going to come in, so I hope you will remain interested long enough to solve the new propblems I am going to pose. They will be much more related to real scripting problems - I just wanted to get this "view/rotate" issue out of the way, so that I could do an honest job at my SDN Community Day Session.
Very best regards
djh -
Javascript method for clientListener not getting invoked
Hi, I am trying to use a clientListener to call a javascript method when an image that's linked gets clicked on, but the javascript method is not getting invoked. I'm using Jdev 11g. E.g.
<af:resource type="javascript">
function sayhello(event) {
event.cancel();
alert("hello");
</af:resource>
<af:goLink id="gl1">
<af:clientListener type="click" method="sayhello"/>
<af:image id="i1" source="/image/test.gif"/>
</af:goLink>The sayhello javascript method does not get invoked when clicking the linked image. What I found though is that if I change the <af:goLink> to the following, then the javascript method gets invoked:
<af:goLink id="gl1" text="click me">
<af:clientListener type="click" method="sayhello"/>
</af:goLink>I want to have a linked image though instead of linked text. Any suggestions to make this work? In Jdev 10g, the following worked fine for me:
<af:goLink onclick="sayhello">
<af:objectImage source="/image/test.gif">
</af:goLink>I did try using <af:goImageLink> (with <af:clientListener>) and specify the image using the icon attribute. This worked fine in terms of being able to call the javascript method. However, the problem with using this is that it somehow shifts the image down and this doesn't look good in my UI because I basically have a row of <af:goLink> components that use images and using this <af:goImageLink> shows the image mis-aligned compared to the rest of the linked images.HI All,
Iin my case, clientLinstene is not working if i use more than one goLink , any body can you help me.
<af:goLink text="Forgot Password?" id="gl1">
<af:clientListener type="click" method="showPopupFromAction"/>
</af:goLink>
</af:panelFormLayout>
</af:panelGroupLayout>
<af:panelGroupLayout id="pgl4">
<af:spacer width="150" id="s3"/>
<af:outputText value="Choose Language: " id="ot2"/>
<af:goLink text="Arabic" id="cl1">
<af:clientListener type="click" method="testMethod"/>
</af:goLink>
one popup will call popup and anther will in call bean method that's my requirement. script is
<af:resource type="javascript">
* Shows a popup from an "action" type event.
* @param {AdfActionEvent} actionEvent the event being handled
function showPopupFromAction(actionEvent) {
actionEvent.cancel();
var eventSource = actionEvent.getSource();
var popup = eventSource.findComponent("popupForgetPassword");
popup.show( {
align : AdfRichPopup.ALIGN_OVERLAP, alignId : eventSource.getClientId()
</af:resource>
<af:resource type="javascript">
function testMethod(actionEvent) {
// my stuff here.... I will call server listener method.
</af:resource>
thanks
Palanivel -
How can i invoke the set method before value change listener?
Hi,
My code is like this:
<af:selectManyCheckbox value="#{bean.statusList}"
binding="#{bean.statusCheckBox}"
label=" " autoSumit="true"
valueChangeListener="#{bean.changeStatusList}"
id="dc_smc1" layout="vertical"">
<f:selectItems value="#{bean.statusBuckets}"
id="statusBuckets"/>
</af:selectManyCheckbox>
public void changeStatusList(ValueChangeEvent valueChangeEvent)
//in this method, i want to set the statusList by myself, this is not the same with the ui.
public void setStatusList(List<String> statusList)
this.statusList = statusList;
public List<String> getStatusList()
return statusList;
As i set the autoSumit="true", then no matter what i set the statusList in the method changeStatusList, it will be reset the value after invoke the method setStatusList, Therefore, it will always change the checkbox status through ui operation, i cannot change it through code.
Pl help me!
Thanks,
EmmaEmma, which jdev version do you use?
As you have set the value property to the list you try to change in the valueChangeListener method this is expected behavior. If the list is bound to the af:selectManyCheckbox values you can't change it with a set method.
It would help if you tell us what you are trying to do in a broader scope.
Timo -
Problem in Applet while communicating with Javascript
Hi,
Im facing a problem with applet. Applet calls JavaScript methods and vice versa. Applet works fine with JRE 5 to JRE 6 up to build no 1.6.0._7 but it fails with build no 1.6.0_10.
The problem description is given below:
After embedding applet in my HTML page using <OBJECT> tag, Ive to check either any problem during applets execution, I want to get the error reason by calling my defined method getErrorReason() in applet that returns the error reason, I call the getErrorReason() against the applets object in JavaScript immediately after embed applet code in my HTML page, a JavaScript errors occurs and my applet fails to perform its execution.
JavaScript error: Object does not support this property.
The error points to the HTML page area where Im calling getErrorReason() against applet object.
The above JavaScript error occurs after the successful completion of Applets init(). Im facing this problem only in JRE 6 build 1.6.0_10-b33.
Please suggest me any solution.
Thanks in advance.
Regards,
Israr AhmedHi Bharath,
Even i got similar error and i tried deleting the below(Attaching the stack trace is always better way.)
1) delete the folder workspace or rename(including all files and subfolders) in the path D:\Documents and Settings\lzcr8r\Documents\SAP\workspace
2) delete all .dtr/.dtc/.metadata directories in your personal folder (e.g. C:\Documents and Settings\lzcr8r).
Restart the IDE once you are done with the above steps.
Second part to increase the virtual mem
1) RtClick on the Shortcut of NWDS -->Properties and in the Target put the below
"C:\Program Files\SAP\IDE\IDE70\eclipse\SapIde.exe" -vmargs -Xms512m -Xmx1536m "C:\j2sdk1.4.2_08\bin\javaw.exe"
2) You can also try Creating a bat file with the complete path of your IDE and start your ide from the bat
content in the bat eg: "C:\Program Files\netbeans-4.1\bin\netbeans.exe" -vmargs -Xms512m -Xmx1536m
Here -Xms512m is the min JVM size and -Xmx1024m is the max JVM size.
You can place this batch file anywhere and double click the batch file.
It will automatically start your IDE
3) if you are using Tomcat you can try creating an env variable and assign Value
Variable Name: CATALINA_OPTS
Variable Value: -server -Xmx800m
please award points if usefull.
Regards
Souza
Edited by: Souza Aluri on Apr 9, 2008 9:46 AM -
Calling javascript method from java
Hi this is sri,
I have one doubt on Java Applets "how to call the javascript method from java Applet".Can u give me the complete sample code for one program(both java applet file and html file also)because i can easily understand the programming flow.
Thanks ,
Srilekha.It's an extremely important skill to learn how to search the web. Not only will it increase your research and development talents, it will also save you from asking questions that have already been answered numerous times before. By doing a little research before you ask a question, you'll show that you're willing to work and learn without needing to have your hand held the entire time; a quality that is seemingly rare but much appreciated by the volunteers who are willing to help you.
If you've done the research, found nothing useful, and decide to post your question, it's a great idea to tell us that you've already searched (and what methodologies you used to do your research). That way, we don't refer you back to something you've already seen.
To get you started, here's a link...
http://www.google.com/search?q=call+java+from+javascript -
Can you help me with mouse pressed method please?
hi
can you help me with my problem please, player label doesn't show up in the applet and the draw string method it doesn't draw any strings like X or O for the game I don't know what is the problem maybe it is with MousePressed method which is in Board class. I tried to write the code of the location many times I'm not sure if the problem comes from there.
there is no error in my code, but it doesn't work.
this is class Board which has the mouseListener
class Board extends JPanel implements MouseListener, MouseMotionListener
private JLabel playerlabel;
private boolean play;
private boolean start;
private int turn;
private Square squares[][];
private Player myplayer[][];
public Board()
setBackground( Color.WHITE );
playerlabel = new JLabel( "X player first" );
//playerlabel.setLayout(null);
// playerlabel.setLocation(500,500);
add( playerlabel );
play = true;
turn = 1;
squares = new Square[3][3];
myplayer = new Player[3][3];
int x = 40;
int y = 40;
for (int i=0; i<3; i++){
x = 40;
for (int j=0; j<3; j++){
Square s = new Square( x,y );
squares[i][j] = s;
x +=50;
y +=50;
this.addMouseListener(this);
this.addMouseMotionListener(this);
public void mouseClicked( MouseEvent event ){}
public void mouseMoved( MouseEvent event ){}
public void mouseEntered( MouseEvent event ){}
public void mouseExited( MouseEvent event ){}
public void mousePressed( MouseEvent event )
{int xPos = event.getX();
int yPos = event.getY();
if(play && turn ==1){
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
int x = squares[i][j].getX();
int y = squares[i][j].getY();
if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
if( squares[i][j].getOccupied() ==0 ){
String ptext;
ptext = "X";
Player p = new Player(x, y,ptext);
myplayer[i][j] = p;
squares[i][j].setOccupied(1);
playerlabel.setText( "O Player Turn" );
turn = 2;
repaint();
Win();
else{
turn = 2;
playerlabel.setText( "O Player Turn" );
repaint();
if ( play && turn ==2 )
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
int x = squares[i][j].getX();
int y = squares[i][j].getY();
if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
if( squares[i][j].getOccupied() ==0 ){
String ptext;
ptext = "O";
Player p = new Player(x, y,ptext);
myplayer[i][j] = p;
squares[i][j].setOccupied(2);
playerlabel.setText( "X Player Turn" );
turn = 1;
repaint();
Win();
else{
turn = 1;
playerlabel.setText( "X Player Turn" );
repaint();
public void mouseReleased( MouseEvent event )
public void mouseDragged( MouseEvent event )
public void Win(){
if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
//Vertically win
if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
//Diagonal win
if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
}//end win
public void setTurn(int t)
turn = t;
playerlabel.setText( "X Player Plays First" );
public void paintComponent( Graphics g )
super.paintComponent( g );
this.setBackground( Color.WHITE );
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
g.setColor( Color.BLACK );
g.drawRect( squares[i][j].getX(), squares[i][j].getY(), 50, 50 );
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
myplayer[i][j].draw(g);
//End of paintComponent
}and this is the whole code of my program.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class Player{
private int xCoordinate;
private int yCoordinate;
private String playerText;
public Player(int x, int y, String t)
playerText = t;
xCoordinate = x;
yCoordinate = y;
public void draw(Graphics g)
g.drawString(playerText, xCoordinate, yCoordinate);
public void SetText(String t)
{ playerText = t;
}//end player
class Square
private int x;
private int y;
private int occupied;
public Square(int x1, int y1)
x = x1;
y= y1;
occupied = 0;
public void setX(int x1)
x = x1;
public int getX()
return x;
public void setY(int y1)
y = y1;
public int getY()
return y;
public void setOccupied(int o)
occupied = o;
public int getOccupied()
return occupied;
public class TicTac extends JApplet implements ActionListener
{ private JPanel panel;
private JButton newgame;
private Board B;
public void init()
B = new Board();
add( B, BorderLayout.CENTER );
panel = new JPanel();
newgame = new JButton( "New Game" );
panel.add( newgame);
add( panel, BorderLayout.SOUTH );
newgame.addActionListener(this);
public void actionPerformed( ActionEvent ev)
{ Object source = ev.getSource();
if (source == newgame)
{remove(B);
repaint();
B = new Board();
add( B, BorderLayout.CENTER );
B.setTurn(1);
repaint();
validate();
}//end class TicTac
class Board extends JPanel implements MouseListener, MouseMotionListener
private JLabel playerlabel;
private boolean play;
private boolean start;
private int turn;
private Square squares[][];
private Player myplayer[][];
public Board()
setBackground( Color.WHITE );
playerlabel = new JLabel( "X player first" );
//playerlabel.setLayout(null);
// playerlabel.setLocation(500,500);
add( playerlabel );
play = true;
turn = 1;
squares = new Square[3][3];
myplayer = new Player[3][3];
int x = 40;
int y = 40;
for (int i=0; i<3; i++){
x = 40;
for (int j=0; j<3; j++){
Square s = new Square( x,y );
squares[i][j] = s;
x +=50;
y +=50;
this.addMouseListener(this);
this.addMouseMotionListener(this);
public void mouseClicked( MouseEvent event ){}
public void mouseMoved( MouseEvent event ){}
public void mouseEntered( MouseEvent event ){}
public void mouseExited( MouseEvent event ){}
public void mousePressed( MouseEvent event )
{int xPos = event.getX();
int yPos = event.getY();
if(play && turn ==1){
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
int x = squares[i][j].getX();
int y = squares[i][j].getY();
if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
if( squares[i][j].getOccupied() ==0 ){
String ptext;
ptext = "X";
Player p = new Player(x, y,ptext);
myplayer[i][j] = p;
squares[i][j].setOccupied(1);
playerlabel.setText( "O Player Turn" );
turn = 2;
repaint();
Win();
else{
turn = 2;
playerlabel.setText( "O Player Turn" );
repaint();
if ( play && turn ==2 )
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
int x = squares[i][j].getX();
int y = squares[i][j].getY();
if(xPos> x && xPos<x+40&& yPos> y && yPos<y+40){
if( squares[i][j].getOccupied() ==0 ){
String ptext;
ptext = "O";
Player p = new Player(x, y,ptext);
myplayer[i][j] = p;
squares[i][j].setOccupied(2);
playerlabel.setText( "X Player Turn" );
turn = 1;
repaint();
Win();
else{
turn = 1;
playerlabel.setText( "X Player Turn" );
repaint();
public void mouseReleased( MouseEvent event )
public void mouseDragged( MouseEvent event )
public void Win(){
if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if(squares[0][0].getOccupied() == squares[0][1].getOccupied() &&squares[0][1].getOccupied()==squares[0][2].getOccupied() &&squares[0][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[1][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[1][2].getOccupied() &&squares[1][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if(squares[2][0].getOccupied() == squares[2][1].getOccupied() &&squares[2][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
//Vertically win
if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if (squares[0][0].getOccupied() == squares[1][0].getOccupied() &&squares[1][0].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[0][1].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][1].getOccupied() &&squares[2][1].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if(squares[0][2].getOccupied() == squares[1][2].getOccupied() &&squares[1][2].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
//Diagonal win
if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 1)
{playerlabel.setText("Player 1 X WON THE GAME!");
play =false; }
if (squares[0][0].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][2].getOccupied() &&squares[2][2].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
else if (squares[0][2].getOccupied() == squares[1][1].getOccupied() &&squares[1][1].getOccupied()==squares[2][0].getOccupied() &&squares[2][0].getOccupied() == 2)
{playerlabel.setText("Player 2 O WON THE GAME!");
play =false; }
}//end win
public void setTurn(int t)
turn = t;
playerlabel.setText( "X Player Plays First" );
public void paintComponent( Graphics g )
super.paintComponent( g );
this.setBackground( Color.WHITE );
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
g.setColor( Color.BLACK );
g.drawRect( squares[i][j].getX(), squares[i][j].getY(), 50, 50 );
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
myplayer[i][j].draw(g);
//End of paintComponent
Edited by: mshadows on May 18, 2008 7:53 AMI was playing with this a little bit and came up with this game model, something that I'm sure can be improved upon greatly:
TttXO.java
an enum to encapsulate X vs O. I could use a boolean here since it has 2 states, but this seems more intuitive to me
package dy08.m05.ttt;
* tic tac toe encapsulation of X vs O
* @author Pete
public enum TttXO
X, O
}TttCell.java
encapsulates an individual cell in the tictactoe grid.
package dy08.m05.ttt;
* Tic Tac Toe Game cell
* can be occupied or not
* can hold TttXO X or O or null
* @author Pete
public class TttCell
private boolean occupied = false;
private TttXO xo = null;
public TttCell()
* sets a Square for either x or o
* @param TttXO
* @return true if successful, false if already occupied
public boolean setXO(TttXO xo)
if (occupied)
return false;
else
occupied = true;
this.xo = xo;
return true;
public void reset()
occupied = false;
xo = null;
public boolean isOccupied()
return occupied;
public TttXO getXO()
return xo;
// used to test and debug the class
public String toString()
if (occupied)
return xo.toString();
else
return "-";
package dy08.m05.ttt;
* Tic Tac Toe game model
* @author Pete
public class TttGameModel
private TttCell[][] cellGrid = new TttCell[3][3];
private boolean xTurn = true;
private boolean win = false;
public TttGameModel()
for (int i = 0; i < cellGrid.length; i++)
for (int j = 0; j < cellGrid.length; j++)
cellGrid[i][j] = new TttCell();
public void reset()
xTurn = true;
win = false;
for (int i = 0; i < cellGrid.length; i++)
for (int j = 0; j < cellGrid[i].length; j++)
cellGrid[i][j].reset();
public boolean isXTurn()
return xTurn;
public boolean isWin()
return win;
* @param row
* @param col
* @return true if valid move, false if game already over or cell occupied
public boolean takeTurn(int col, int row)
TttXO currentXO = TttXO.O;
TttCell cell = cellGrid[row][col];
if (win)
return false;
if (cell.isOccupied())
return false;
if (xTurn)
currentXO = TttXO.X;
cell.setXO(currentXO);
win = checkWin(col, row, currentXO);
xTurn = !xTurn; // toggle xturn
return true;
public boolean checkWin(int col, int row, TttXO xo)
boolean win = false;
// first rows and columns
boolean temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[row][i].getXO() == xo;
win |= temp;
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][col].getXO() == xo;
win |= temp;
if (row == col) // if slash diagonal
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][i].getXO() == xo;
win |= temp;
if (row + col == 2) // if backslash diagonal
temp = true;
for (int i = 0; i < 3; i++)
temp &= cellGrid[i][2 - i].getXO() == xo;
win |= temp;
return win;
// used to test and debug the class
public String toString()
StringBuilder sb = new StringBuilder();
for (int i = 0; i < cellGrid.length; i++)
for (int j = 0; j < cellGrid[i].length; j++)
sb.append(cellGrid[i][j] + " ");
sb.append("\n");
if (win)
sb.append("win! Game over");
else
sb.append("No winner yet");
return sb.toString();
// test the class
public static void main(String[] args)
TttGameModel model = new TttGameModel();
checkMove(model, 0, 0);
checkMove(model, 1, 0);
checkMove(model, 1, 1);
checkMove(model, 2, 0);
checkMove(model, 1, 0); // bad move
checkMove(model, 2, 2);
// to test the class
private static void checkMove(TttGameModel model, int i, int j)
System.out.println("OK move: " + model.takeTurn(i, j));
System.out.println(model + "\n"); -
How to call a javascript method after the PPR event has finished ?
Hi!
How can we make a javascript method get called after the processing of ADF PPR event?
My specific use case is,
I want to call a javascript function after the data in the table is loaded...
In 10g, that is not a problem, as the data used to get loaded directly during onLoad, and so i would call my js function on load;
but in 11g , the table data is being loaded through PPR which is initiated onload, and so i needed to call my function after the PPR Response processing has been done; for which I need the name of the event triggered at that instance.
Is it possible to do this?
Regards,
SambaHey, I got it.
I handled the ADF Controller's PREPARE_RENDER_ID phase of the lifecycle, and then called the
script to get Executed.
The code :
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
FacesPageLifecycleContext ctx = (FacesPageLifecycleContext)pagePhaseEvent.getLifecycleContext();
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
if(AdfFacesContext.getCurrentInstance().isPostback() )
afterRender();
}is written in lifecycle listener , and my backing bean extended this listener ,
and in the afterRender() method I did this :
public void afterRender(){
System.out.println("AFTER RENDER CALLED");
FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService service = (ExtendedRenderKitService)Service.getRenderKitService(context, ExtendedRenderKitService.class);
service.addScript(context, "translate();");
}That's it.
It did work, magnificently.
Thanks for the idea.
Regards,
Samba -
Strange about invoking web service method declared string method(void);
Dear forum readers
Im experimenting with OpenESB and web services. Ive create a simple web service using NetBeans 6.1. The method consists of a single method, getTime, that is declared:
String getTime()
My current experiment is to invoke this method from a BPEL-process using the Invoke process object. The strange thing is that it seems like I have to provide a dummy inbound variable from the BPEL-designer even though the method doesnt take any parameters. I include a snippet from the BPEL process below which includes the section where I set the dummy GetTimeIn-variable and then invokes the WS method getTime().
<assign name="Assign2">
<copy>
<from>'DummyValue'</from>
<to variable="GetTimeIn" part="parameters"/>
</copy>
</assign>
<invoke name="Invoke1" partnerLink="PartnerLink1" operation="getTime" xmlns:tns="http://ws/" portType="tns:MyWebService" outputVariable="GetTimeOut" inputVariable="GetTimeIn"/>
If I dont initiate the dummy variable or remove it altogether, I cant successfully call the method. If I include the dummy in-parameter the call works just fine and I get back the current time as a string.
I must admit that Im still a rookie to web services, especially when calling them from a BPEL-process, so it may be a very trivial reason for this behaviour. Anyway, any help on this matter would be greatly appreciated.
Regards, OlaThank you both for the response. Regarding Rennays posting I have an additional question. When I create a new web service I don't have the "Document Literal" option nor a "Concrete Configuration" tab. I've created the web service using the "Web Application" project type and then adding a web service using the "Web Service..." wizard. This wizard doesn't have the configuration properties you mention, but if I add a WSDL-file to a BPEL-project the wizard has the properties you mention.
Is it possible to create a web service, programmed as an ordinary Java-class, from an existing WSDL-file? In that case it may solve the problem with the Document Literal property. Currently I dont know any other way to create such a web-service other than the through the web service wizard in a web application project. Of course, its possible to craft it from scratch but thats to much work to be practical.
Regards, Ola
Maybe you are looking for
-
Problem with "transitions" in PS Elements 9
I am a long time Roxio user, but recently purchased PS Elements 9. I find some things vastly superior, while other things seem to be a severe step in the wrong direction. At first glance "transitions" fit into the latter category. My problem is that
-
How do I select multiple columns in a recordset
I am very new to Dreamweaver/PHP/MYSQL I have created my recordset but I cant work out how I select multiple columns. How do I select multiple columns, I want to search for data that is spread over different columns. My recordset looks like this just
-
"Search Result Types" Error on page view
When visiting "Search Result Types" under Site Collection Administration on a few of my site collections I get an error. This only happens on some of the site collections and I can't pin down why its occurring. I've tried disabling "SharePoint Server
-
i plug in my ipod using the usb cable but it does not pop up or register on the computer. What do i do? Can i fix it?
-
Prime setup 2.0.0.0.294-2-K9 asks for Red Hat CD
Ok since i have this problem with a Cisco Prime https://supportforums.cisco.com/discussion/12333166/ncs-prime-lost-licenses-after-application-restore I decided to do a complete re-install. Since this is a physical appliance i downloaded the PI-APL-2.