Applets and browser interaction

Hi there,
I'm using some mask edit applets in HTML pages. What I want is to give the focus to the next/previous control (or applet) in the page when pressing <tab> / <shift>+<tab>.
As my applets are treating the keyboard input, the tabIndex property of the <Applet> tag has no effect (the browser don't know the <tab> key has been pressed).
I found a solution by using some functions (like isTabPressed()) in the applets. Those functions are called (within the page) every 10 milliseconds after the onFocus.

The HTML code looks like this :

<SCRIPT FOR=EDIT1 EVENT=onfocus>
  window.setTimeout("checkTab(EDIT1)", 10);
</SCRIPT>

function checkTab(S)
{
  if (S.isTabPressed())
       document.all.item(S.NextID)._focus();
  else if (S.isShiftTabPressed())
      document.all.item(S.PrevID)._focus();
  else
    window.setTimeout("checkTab("+S.id+")", 10);
}

Unfortunately, i can't use it :
- i don't want to add JavaScript events for that
- the tab order should be respected also for the other components (not only for the applets)
- as my HTML code is the result of an interpretation, I don't know which ID will be next in advance

I was thinking the keyPressed event was
first fired in the browser and then sent to the applet, but that's not true.
I tried then to send the keyPressed message from the applet up to the browser but i couldn't find the appropriate way...

Can anybody help me with my tab-keeping applets ?

Le_RonAsked:
Who is Participating?
 
phutsonCommented:
Okay here is the only information I could find on j++. The class that allows java to jscript/html access is com.ms.wfc.html and a place to start looking for information
http://msdn.microsoft.com/library/techart/msdn_dhtmljava.htm

jscript to java is simply a matter of something like
document.myApplet.runThis()
or
set app1 = document.myApp
app1.showthis()

The thing to remember is that any public method or member of an applet is accessible to javascript or jscript, including public static members or methods such as system.out.println() which makes for some very interesting posibilities.

-Philip
0
 
phutsonCommented:
Do you not want any java script. If you don't mind some java script then I would make the buttons regular html buttons that use the onClick property to call the appropriate java method in the applet such as
onclick="document.nextPrevApplet.next();"

-Philip
0
 
Le_RonAuthor Commented:
Hi Philip,

If you have a html form containing edits or check boxes, ... they have a tab order. That means when you press the tab key, the focus is given to the following control. The problem i'm experiencing is that i use applets which intercept the keyPressed event, so the browser cannot handle the tab in the usual way.

What i want to know is 'how can i tell the browser the tab key has been pressed from within an applet'.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
phutsonCommented:
I looked for a way to generate a key event in jscript or java and was unable to find one so the only way I could come up with to move focus is the following. Add the onfocus to the applet tag that sets a jscript variable (it looks like your working in ie 5.x) to point to it's self (onfocus="setSelf(document.appletOne)") then have another jscript function that will call the blur method of the object that is refereced to by the variable that is set with the setSelf jscript function. Then from within the applet call the jscript function that calls the blur function.
-Philip
0
 
Le_RonAuthor Commented:
Hi Philip,

You wrote:

>>Then from within the applet call the
>>jscript function that calls the blur
>>function

Alright, but how can i do that ? Is there a special function to send messages to the browser ?
0
 
phutsonCommented:
Which java are you using sun or ms. I do not have the j++/jscript method of calling jscript functions but I am looking for it. The method I show below uses sun's java and a netscape class but the resulting applet works in both ie 5.x or netscape 4.0x.
Netscape has an almost acceptable explanation of the javascript to java communication technology (live connect
http://developer.netscape.com/docs/manuals/liveconnect.html
from there there are a few links that help fill the information but it is still severly lacking) another reference for liveconnect is in O'Reilly's JavaScript: The definitive guide third edition (isbn 1-56592-392-8).

Here is an example (from an applet I just recently finished) of a java method to call a javascript method that take a calling argument of a string. The netscape.javascript.JSObject class is within java40.jar which is in the netscape program directory structure.

import netscape.javascript.JSObject;

      public void setDate(String inDate){
            String[] date = new String[1];
            
            date[0] = inDate;
            JSObject win = JSObject.getWindow(this);
            win.call("setData",date);
      }


For you your java method you could do a lot less. It would look something like this. tabMe is the name of the javascript function.

import netscape.javascript.JSObject;

      public void blurMe(){
            JSObject win = JSObject.getWindow(this);
            win.call("tabMe");
      }

-Philip
0
 
Le_RonAuthor Commented:
Tank you for your interest in my question, but i got my own solution now. Anyway, your informations are useful ,and i'll give you some points for that !

Thanks
0
 
SeshCommented:
how did you end up doing it?
0
 
Le_RonAuthor Commented:
Well, i call a function in the onLoad event. that function runs through all applets in the page and tests, for each of them, a property isTabPressed and isShiftTabPressed. Those boolean members are set in within the applet when tab - or shift-tab - is pressed.
The function ends by calling itself after a timeout of 0.1 second.

If isTabPressed or isShiftTabPressed is true, another JavaScript function is called with the name of the applet as an argument, giving focus to the next or previous control on the page. In order to do this, a loop is done over all elements of the document, looking for the applet. When it has been found, i just have to take the previous one or the next one in the array and give the focus to it.

If you're interrested in it, i can send you some code (if i find it back). Because after all, i'm using ATL objects that have normal behavior regarding the tab and shift-tab.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.