Merlin's Magic: the Sound in swing

Source: Internet
Author: User

An interesting Swing feature is added to J2SE version 1.4. Swing controls can now provide auditory feedback to respond to specific events, but this feature is disabled by default. This new feature helps Swing controls better mimic the behavior of controls on the system's local operating system.

Basic knowledge of hearing

Swing uses an pluggable look-and-feel (pluggable Look-and-feel,plaf) architecture. Developers do not have to hard-code for settings such as colors and fonts for different components, and instead, the components will request these settings from the user Interface Manager (UI) manager). As a developer, you can tell the UI manager what kind of interface you want the user to see; You can choose Windows, Motif, or Metal styles, and so on. The UI manager can then actually tell how each component should show itself. For a component like a button, the foreground color is controlled by setting the Button.foreground property, as follows:

Uimanager.put ("Button.foreground", color.red);

Here, Button.foreground is the user interface property name, and color.red represents a specific setting. After you change the settings, the foreground color of all new buttons will be red. (There are also ways to change the foreground color of previously created buttons.) Although different preset skins and sensations provide defaults for these settings, you can reset them.

Under J2SE 1.4, you can enable auditory feedback in a similar way. All you need to know is the UI property name and the appropriate settings. property is named here as Auditorycues.playlist, set to a String array of auditory hint names. The UI Manager will then map these names to the sound files that will play when a particular operation occurs.

The following will give a list of the supported sounds in the look and feel provided by the system. Their names are inherently explanatory.

Checkboxmenuitem.commandsound

Internalframe.closesound

Internalframe.maximizesound

Internalframe.minimizesound

Internalframe.restoredownsound

Internalframe.restoreupsound

Menuitem.commandsound

Optionpane.errorsound

Optionpane.informationsound

Optionpane.questionsound

Optionpane.warningsound

Popupmenu.popupsound

Radiobuttonmenuitem.commandsound

An array of String names provided to the Auditorycues.playlist property is the case-a collection of event names. The UI Manager is responsible for mapping these names to look and feel-specific sounds.

You can manually create an array of event names that you really want to support from these names, but this is not required. Thankfully, there are already two system-defined settings available for commonly used groups, and a setting that can be used to Metal look and feel.

These settings provide a lookup key auditorycues.allauditorycues that allows you to find an array of all sounds from the UI manager. Once you have looked up the array, you can use the Auditorycues.playlist key to store it in the UI manager, as follows:

UIManager.put("AuditoryCues.playList",
UIManager.get("AuditoryCues.allAuditoryCues"));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.