AWT Enhancements in V1.1 - Supporting Richer GUI Development

arunsnarayanan 2 views 25 slides Mar 11, 2025
Slide 1
Slide 1 of 25
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25

About This Presentation

The AWT was modified in version 1.1 of the JDK to provide major quality improvements while introducing the beginnings of a richer infrastructure for larger-scale GUI development.


Slide Content

AWT ENHANCEMENTS
Arun Seetharaman
March 10, 1998

OVERVIEW
•AWT Enhancements
•Popup menus
•Scroll pane
•Clipboard
•The AppletContext object
•Audio and Images
•Inter-applet communication

DESKTOP COLORS
•The new SystemColorclass helps Java detect the
color scheme set for the desktop
•Programmers can uses these colors by accessing the
final members of the class
•activeCaption: Caption background color
•contolText : Control’s text color
•desktop: Desktop’s background color
•menuText : Menu’s text color
•window: Window’s background color

POPUP MENUS
•Dynamically popped menus as specified position within
the component
•Defined the PopupMenu class of Java
•Invoke the show method to popup the menu
•void show(Component,int,int)
•If the popup menu object is used in place of a menu
item, the show()cannot be invoked

POPUP MENU -AN
EXAMPLE
public void mouseReleased(
MouseEvent evt) {
if (evt.isPopupTrigger()) {
popup.show(evt.getSource(),
evt.getX(), evt.getY());
}
else {
System.out.println("no popup");
}
}

SCROLLING CONTAINERS
•Container implementing automatic scrolling for a single
child component
•Needed in situations where the viewport is smaller than
the window
•Clipping the child’s contents appropriately depending
on the scroll position

THE SCROLLPANECLASS
•Display policy can be set
•as needed
•always
•never
•Placement is controlled by platform-specifc properties
•Implements the Adjustable interface, which can
be used for fine tuning

SCROLLPANE -AN
EXAMPLE
ScrollPane sp = new ScrollPane();
sp.getHAdjustable().setUnitIncrement(2);
sp.getVAdjustable().setUnitIncrement(2);
sp.add(new ImageComponent(
getToolkit().getImage(filename)));
add(sp, BorderLayout.CENTER);
setSize(200, 150);

DATA TRANSFER
•Clipboardand Drag-dropare the two major models of
data transfer
•Data transfer occurs using “flavors” defined by the
Transfer APIs
•The flavors to be used for data transfer encapsulate the
various MIME types
•The java.awt.datatransfer package caters to the needs
of these operations

CLIPBOARD
•Clipboard is a globally shared memory
•The toolkit has an instance of a clipboard, that uses the
system clipboard
•Class willing to write to a clipboard need to implement
the ClipboardOwner interface
•Data flavors need to be compatible for transfer of data
using clipboard

WRITING TO A
CLIPBOARD
class ClipboardSource extends Frame
implements ClipboardOwner {
TextArea ta = new TextArea();
void setContents() {
String s = ta.getSelectedText();
StringSelection contents = new
StringSelection(s);
getToolkit().getSystemClipboard(
).setContents(contents, this);
}
}

READING FROM
CLIPBOARD
Transferable t = getToolkit().
getSystemClipboard().getContents(
this);
if(t.isDataFlavorSupported(
DataFlavor.stringFlavor)) {
String str = t.getTransferData(
DataFlavor.stringFlavor);
}

DRAG AND DROP
•Uses the same data transfer mechanism
•Discussed later as a part of JFC

APPLET CONTEXT
•Corresponds to the applet’s execution environment
•In the normal execution circumstances, this object is
the browser
•Defined by the AppletContextinterface
•Use the getAppletContext() method to access
the context object

USING AUDIO
•Defined by the AudioClipinterface
•A simple abstraction for playing audio clips
•Multiple clips can be played simltaneously
•Created using the getAudioClip() method of the
applet context
•Can play the audio clip using
•play()
•loop()

IMAGING
•Defined by the Imageclass
•BufferedImagecan be used to achieve buffering
during image rendering
•Use getImage()of applet context to create a
Image object
•Use the drawImage()method in the Graphics class
to render images

ADVANCED FEATURES
•Defined in the java.awt.image package
•ImageProducer : a source of image data
•ImageConsumer : a user of image data
•ImageObserver : asynchronous notification on the image
•Defines color models to be used
•Defines some image filters

TRACKING THE MEDIA
•Useful for synchronous media preparation
•Defined in the MediaTracker class
•Applicable to both audio and images, but only images
supported currently
tracker = new MediaTracker(this);
for (int i = 0; i < 5; i++)
tracker.addImage(anim[i], 1);
for (int i = 0; i < 5; i++)
tracker.waitForID(i);

LOADING WEB PAGES
•Java applets can load other web pages
•Use the showDocument() method of the applet
context
•Can also be used to address framesets
•_self : same frame
•_parent: applet’s parent frame
•_top: top-level frame of applet
•_new: a new top-level window
•name: specified frame name

INTER-APPLET
COMMUNICATION
•Applets within the same applet context can
communicate with each other
•Obtain the object reference of the other applets using
•void getApplet(String);
•Enumeration getApplets();
•Communicate by invoking public methods

SCRIPTING APPLETS
•Help in communicating with applets from an external
entity
<SCRIPT LANGUAGE=VBScript>
Sub Update_onClick()
Marquee.setMessage(Message.Value)
End Sub
</SCRIPT>
<INPUT TYPE="Text" NAME="Message"
VALUE="">
<INPUT TYPE="Button" NAME="Update"
VALUE="Update">

REVIEW
•AWT offer capabilities like context menus, clipboard
support etc.
•Applet contexts help in
•rendering images and playing audio
•loading web pages
•inter-applet communication
Tags