Newsgroup: it.comp.java
Titolo: Dov'è il cursore?

Vorrei inserire in una pagina web una maschera per l'inserimento di dati
di un questionario.
Poichè si tratta di un lavoro molto ripetitivo, vorrei potermi spostare
fra i vari campi e selezionare i vari bottoni con la tastiera, invece di
dover vagare per lo schermo col mouse.
Poiché né i form HTML né Javascript permettono di leggere l'input da
tastiera, mi toccherà usare Java, che ha la possibilità di rispondere
alla pressione dei vari tasti. In pratica, vorrei usare le frecce
direzionali per spostarmi direttamente da un bottone all'altro del form.
Ma come faccio a capire quale è il bottone su cui mi sono spostato?
Esiste un cursore lampeggiante che io possa far comparire in
corrispondenza del bottone attivo?
Grazie,
Piersante
-- 
**********************************
Piersante Sestini MD
Institute of Respiratory Diseases
University of Siena
tel +39-(577)-586794
fax +39-(577)-280744
E-mail 
ses...@unisi.it
http://respir.med.unisi.it/sestini.htm
**********************************

Lo spostamento del cursore dipende dalle varie piattaforme e dal JDK che
montano.
Il JDK1.0 per HP-UX (Unix), per esempio, permette ti spostarsi tra i vari
componenti usando i tasti [tab] e [alt]+[tab],
bisogna aspettare per vedere la stessa funzione su Win95.
Comunque gli stessi tasti funzionano con le form... se vuoi spostarti da un
componente all'altro in ordine.
Dov'e' il cursore? Ancora, dipende dalla piattaforma, talvolta il tasto ha
il bordo piu' spesso, talvolta la "label" sul tasto ha una piccola
cornice... e il cursore lo vedi quando sei in un TextField o TextArea. Sotto
questo aspetto il MacOS e' il migliore, e' piu' chiaro ed ofre queste
opportunita'.
Se vuoi pero' usare delle "macro":
F1: input "nome"
F2: input "anno nascita"
F3: maschio/femmina
allora puoi usare i metodi requestFocus() di ogni elemento in questione,
dopo che hai "catch"ato il tasto con un event.
La documentazione originale dovrebbe essere piu' chiara:
-----------------
Mousless AWT
Purpose
 Although typical GUIs today are designed to be driven with a mouse, there
are numerous circumstances where mouseless operation in a GUI becomes
important (and sometimes even critical) for usability. Some of those
circumstances include:
· Accelerated operation for the "power" user
· Disabled access
· Avoidance or treatment for RSI (repetitive stress injury)
 AWT1.0 does not provide any explicit facilities for building mouseless
operation into Java programs, except where the native peers components
provide it by default (i.e. tabbed focus traversal, space-bar activation,
etc.). For JDK1.1, the AWT will add som e baseline support to better enable
mouseless mode in Java programs, although it by no means provides a 100%
solution to this problem. This support will be expanded in subsequent
releases. The two features that will be in 1.1 are:
· Focus Traversal
· Menu Shortcuts
______________________________________________________________________________
Focus Traversal
 Focus traversal is defined to be the ability to use keystrokes (not the
mouse) to traverse components capable of accepting keyboard focus. Those
keystrokes are defined to be <Tab> to move forward and <Shift-Tab> to move
backward. Once the focus is owned b y a component then it should be possible
to activate/drive that component with further defined keystrokes (such as
<space> to press a Button). It is the responsibility of the component (not
the AWT), to implement the proper activation once it has focus
 A component which is capable of accepting focus in this way should always
render some form of visual feedback when it gets focus so that the user can
easily see which component has focus as the user traverses using
Tab/Shift-Tab. Typically this feedback takes the form of a colored bounding
box drawn around the component.
 The native toolkits on each platform provide varying degrees of support for
focus traversal by default. However, explicit support for this has been
implemented in the common java AWT code so that the behavior is more
consistent across platforms.
The Focus Traversal API
The API is extremely simple; it consists of a new method on
java.awt.Component and java.awt.peer.ComponentPeer:
        public boolean isFocusTraversable()
 This method returns true if the component is a type inherently capable of
accepting keyboard focus and returns false otherwise.
 The reason this method also exists for the peer class is because the native
peer components that are created by the AWT components have different
traversal rules on different platforms. This allows the tailoring of this
attribute appropriately on each pla tform (for example, on the Mac, Buttons
cannot take focus, but on Motif and Win32, they can).
 All existing AWT components should have this attribute set properly by
default, but there is the option to subclass a component and override this
method to return a value appropriate for your program. In particular, if you
are subclassing java.awt.Canvas to build your own custom component that is
designed to take keyboard focus, then you should do the following three
things:
1. override isTabbable() to return true (Canvas returns false by default)
2. catch the mouse-down event on the component and invoke requestFocus() (to
implement click-to-type for your component)
3. when your component gets focus, provide visual feedback indicating it has
the focus
 If your component does not adhere to the above steps, users may have
trouble getting focus into your component.
 The AWT internally tracks which component has the focus so that it can move
the focus forward or backward in response to a Tab or Shift-Tab keyboard
event. This is handled by a private FocusManager object that is registered
on the Window. The FocusManager  can manage this focus migration correctly,
no matter how deeply nested a window's containers are. The order of this
traversal will be equal to the order of the components contained in the
containers; by default this will be equal to the order the childre n were
added to the container, however the Container's add(Component c, int pos)
method can be used to control this ordering. The FocusManager automatically
checks to see if a "focusTraversable" component is both visible and active
before it assigns it th e focus (hence, the isFocusTraversable() method need
not take this state into account for its return value).
 Note: We realize that a more flexible mechanism for configuring the order
of traversal is needed and we are currently working on a solution to that
problem.
______________________________________________________________________________
Menu Shortcuts
 The goal for the AWT Shortcut API is to provide an easy way for application
developers to provide shortcuts as an aid to menu navigation. This API only
addresses menu shortcuts, and does not touch on any other mouseless menu
navigation issues.
 A Shortcut is defined to be a keyboard equivalent of a menu command, such
that invoking the appropriate key combination will cause the same action to
be initiated as if the menu item had been selected. Shortcuts are also known
as keyboard equivalents or accelerators.
The Shortcuts API
The API consists of a class:
        java.awt.MenuShortcut
java.awt.MenuItem then has the following additional methods:
        public MenuItem(String label, MenuShortcut s)
        public MenuShortcut getShortcut()
        public void setShortcut(MenuShortcut s)
        public void deleteShortcut();
java.awt.MenuBar has the following additional methods:
        public MenuItem getShortcutMenuItem(MenuShortcut s);
        public Enumeration shortcuts();
        boolean handleShortcut(KeyEvent e);
        public void deleteShortcut(MenuShortcut s);
Modifiers
Application shortcuts all have a common key modifier per-platform:
· <Command> on Macs
· <Control> on Windows
· <Control> Motif
Note: ALT isn't supposed to be used for application shortcuts, other than
QUIT, which is already mapped by the AWT.
 Although most of the shortcut API is implemented in shared code, one method
has been added to java.awt.Toolkit to return the appropriate modifier per
platform:
            public int getMenuShortcutKeyMask();
Visual Indicators
 In order for users to learn and use menu shortcuts, it's important that a
menu item display some visual indicator for the shortcut it supports. This
will be handled automatically by the AWT, in a manner most appropriate for
the given platform.
Sample Code
The code to create menu-items in 1.0:
            menu.add(new MenuItem("Save..."));
            menu.add(new MenuItem("Send..."));
The code to create menu-items with shortcuts in 1.1:
            // Specify an 's' shortcut for save, and 'shift-s' for send.
            menu.add(new MenuItem("Save...", new MenuShortcut('s'));
            menu.add(new MenuItem("Send...", new MenuShortcut('s', true));
______________________________________________________________________________
 Send feedback 
to:java...@java.sun.com
Copyright © 1996, 1997 Sun Microsystems, Inc. All rights reserved.
----------------
Buon Lavoro!
Piersante Sestini wrote:

--
Alexis Paul Bertolini
- PhD student in Computer Science at Milan University, Italy
- Managing director of Warehouse Creations
- Developer of Java applications, Web services, Network Databases
- Teacher of English as a foreign language

 corrispondenza del bottone attivo?
Non devi far comparire nulla perche' quando un componente Java puo'
intercettare l'input della tastiera cambia aspetto automaticamente (es. un
TextField presenta un cursore lampeggiante e un bottone viene evidenziato
con un tratteggio). E' sufficiente che utilizzi il metodo requestFocus() sul
componente desiderato.
Ciao.
--
     o     Leonardo Boselli   
bos...@technologist.com
    o o    TETRACTYS Software 
tetr...@geocities.com
   o o o          Java and NetRexx Tutorials
  o o o o        
http://tetractys.home.ml.org