Solved

Applets and browser interaction

Posted on 2000-04-11
9
562 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
  • 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now