Java Applet: how to simulate an url has been clicked? - java

Basically I want my Java Applet to simulate an url has been clicked, once a certain event listener has been executed.
Say, before I have a link in html:
<a href='destinationpage.php?pid=1001' target='rightFrame' />
I'd like to keep the same link to php intact, and when Applet actually invoke the click simulation method, the "target" attribute can also be used to control the behavior.
Similar SO thread found at here, but it doesn't have an answer.
I have little experience in this area, but I am okay with Java programming so long as someone can give me the suggestion of where to get started with.
Many thanks in advance.
Edit:
Okay, tried to get JSObject from the netscape.javascript package to work, added plugin.jar into CLASSPATH, unfortunately I finally got an ExceptionInInitializerError, so this approach failed, unless I can know how to debug in such a mess...

You could call the url directly in the applet but if you want to reference the link in the page something like the following should work. I have not tested this though.
getAppletContext().showDocument(new URL("javascript:function() {
document.getElementById('mylink').click();
}"));
}

Related

HtmlSelect does not trigger event at selection

I am working on a program for this website using the Java module HtmlUnit. I need to select options from the select fields, but when I do so, it doesn't trigger any events. I have tried a few solutions on forums for this same question (fireEvent method, injecting a JS script to trigger the event), but none have worked so far.
I would really appreciate some help with this one
If you like to get some help you have to provide more details; the version of HtmlUnit you use and your code (as simple as possible). Including a description where your expectation differs from the real results. And of course more details why you think the event is not triggered.
If you think this is a HtmlUnit issue please open a issue in the HtmlUnit issue tracker.
Have written a Wetator (www.wetator.org) test for the web site. Was able to work with all the select boxes and got the appropriate changes on the web site. Based on this i'm really sure this is not a problem with HtmlUnit. Post your code and i will have a look.

How to call gwt servlet from native java?

GWT code is a part of UI as an iframe. Now when the page is logged out, It should somehow call the gwt servlet code in the background and to invalidate the session. I have tried syncproxy, gwtrpccommlayer, But it didnt work since objects for the clients cant be created since it doesnt come under the gwt lifecycle.
Please suggest me how to achieve this. Thanks in advance.

I can't run my applet in NetBeans

When I try to run my applet in NetBeans it tells me that there is no main class. I looked it up and others have had this error, but they don't give great instructions how to fix it. I tried going to Properties > Application > Web Start and changing it to Applet descriptor with my applet class. But, it still doesn't work, and I don't know why. can anyone help me out? Thanks!
Change the run configuration in the toolbar to Web Start:
Now when you click run, it will run the applet.
Try putting in a main class that simply does nothing.
If you have two different classes for this one applet, make sure you are running the one that has a main, only one needs one.
As far as "selecting your applet as the main class" I don't have a clue what that means either.
Hope I've been helpful, I'm new to the whole graphics thing (for java, anyway) too!
If this problem persists, please elaborate!

Best way to call a JavaScript function from an Java Applet

I export a method to javascript window with JSNI, and I want to call this function from a applet in a GWT application..
I think that sometimes I have problems with Window context, so, I do some research and found the JSObject class.
I afraid with the package name (netscape.javascript). Is this class still be used? Is there another better way to do this?
I already tried to get applet context and show a new URl (with javascript:myFunction();), but, in some browsers it redirects the user to a new blank window...
What can I do to make it works best as possible?
Thanks in advance.
The netscape.javascript package is included with every Oracle JRE that I am aware of. Not entirely sure about the others.

Embed Element: Could not access DOMWindow Context

I have a page with a JS Function called test (e.g.), and, in one page of my app I have to open a Java Applet.
In google chrome, it opens as an embed element, and in firefox in an object.
Sometimes, in my applet, I have to call my JS function to do something in the page. I doing this with:
applet.getAppletContext().showDocument(new URL("javascript:window.test();"));
In browser that use the object, this code work like a boss, but, if it use embed, it do nothing, trowing a exeption in Browser console, saying that the Window does not have a "test" function.
I think thi is some trouble with embed context and document context, but I dont know how to fix it, or, if it is "fixable".
So, I like to know if is there any workaround to make it work.
thanks in advance.
I found the problem.
A minor update of chrome solve it. I dont know if the problem was in Webkit or in chrome itself, but, now it works.

Categories

Resources