Solved

Applets and browser interaction

Posted on 2000-04-11
9
570 Views
Last Modified: 2013-11-19
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 ?

0
Comment
Question by:Le_Ron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 1

Expert Comment

by:phutson
ID: 2705726
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
 

Author Comment

by:Le_Ron
ID: 2706831
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
 
LVL 1

Expert Comment

by:phutson
ID: 2709618
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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

Author Comment

by:Le_Ron
ID: 2710839
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
 
LVL 1

Expert Comment

by:phutson
ID: 2712374
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
 
LVL 1

Accepted Solution

by:
phutson earned 100 total points
ID: 2713815
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
 

Author Comment

by:Le_Ron
ID: 2721808
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
 

Expert Comment

by:Sesh
ID: 2765220
how did you end up doing it?
0
 

Author Comment

by:Le_Ron
ID: 2768548
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

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question