The AWT changed significantly between the 1.0.2 and 1.1 releases. Certain old ways of doing things are deprecated -- no longer recommended -- and might not be supported in a future major release. To help you convert your programs well ahead of time, the Java compiler warns you whenever you compile a program that uses deprecated API.
For the curious: The AWT marks deprecated API using the@deprecated
tag in documentation comments in the AWT source code. These tags were not present in the beta 1.1 releases.
When you use the 1.1 compiler to compile a class that calls deprecated API, you'll see a warning like the following:
To see a list of everywhere your program calls deprecated API, use% javac Test.java Note: Test.java uses a deprecated API. Recompile with "-deprecation" for details. 1 warning %
javac -deprecation
.
You might see many warnings.
Don't panic!
Your program will continue to work for a long time.
However, you might want to make plans to convert it.
And any new code you write
should use the new API,
if at all possible.
For complete information on how and why to convert your AWT programs, see How to Convert Programs to the 1.1 AWT API.
Note:
The Java compiler does not currently warn you
when a program overrides a deprecated method.
It warns you only
when a program calls a deprecated method.
For example, the compiler won't usually warn you
if a program overrides the action
method,
since most implementations of action
don't call the superclass's implementation.
updateAWT
can
make the simplest replacements for you.
See How to Convert
Programs to the 1.1 AWT API
for instructions and examples of using the script.
A table similar to this one is in Simple Name Changes. That table contains a bit less information than this one, and it's alphabetized by the 1.1 column to help you easily undo incorrect changes that the script has made.
In the following table,
method names in bold font
are the preferred method names.
Some of the valid 1.1 substitutes for event-handling methods
are less preferable
than other 1.1 solutions.
For example,
although gotFocus
can be replaced by processFocusEvent
,
we'd rather you replaced it with
focusGained
implemented in a FocusListener
,
as described in
How to Convert Event-Handling Code.
Deprecated Method | Class Where Deprecated | 1.1 Replacement |
---|---|---|
action
| Component
| See How to Convert Event-Handling Code for examples of handling action events. |
allowsMultipleSelections
| List
| isMultipleMode
|
appendText
| TextArea
| append
|
bounds
| Component
| getBounds
|
clear
| List
| removeAll
|
countComponents
| Container
| getComponentCount
|
countItems
| Choice, List, Menu
| getItemCount
|
countMenus
| MenuBar
| getMenuCount
|
deliverEvent
| Component, Container
| dispatchEvent
|
disable()
| MenuItem
| setEnabled(false)
|
enable()
| Component, MenuItem
| setEnabled(true)
|
enable(expression)
| Component
| setEnabled(expression)
|
getBoundingBox
| Polygon
| getBounds
|
getClipRect
| Graphics
| getClipBounds
|
getCurrent
| CheckboxGroup
| getSelectedCheckbox
|
getCursorType
| Frame
| getCursor method in Component
|
getLineIncrement
| Scrollbar
| getUnitIncrement
|
getPageIncrement
| Scrollbar
| getBlockIncrement
|
getPeer
| Component
| No replacement. |
getVisible
| Scrollbar
| getVisibleAmount
|
gotFocus
| Component
| processFocusEvent
See How to Convert Event-Handling Code for information on preferred ways to handle events. |
handleEvent
| Component
| processEvent
See How to Convert Event-Handling Code for information on preferred ways to handle events. |
hide
| Component
| setVisible(false)
|
insertText
| TextArea
| insert
|
insets
| Container
| getInsets
|
inside
| Component, Polygon, Rectangle
| contains
|
isSelected
| List
| isIndexSelected
|
keyDown
| Component
| processKeyEvent
See How to Convert Event-Handling Code. |
keyUp
| Component
| processKeyEvent
See How to Convert Event-Handling Code. |
layout
| Component, Container, ScrollPane
| doLayout
|
locate
| Component, Container
| getComponentAt
|
location
| Component
| getLocation
|
lostFocus
| Component
| processFocusEvent
See How to Convert Event-Handling Code. |
minimumSize
| Component, Container, TextArea, TextField
| getMinimumSize
|
mouseDown
| Component
| processMouseEvent
See How to Convert Event-Handling Code. |
mouseDrag
| Component
| processMouseMotionEvent
See How to Convert Event-Handling Code. |
mouseEnter
| Component
| processMouseEvent
See How to Convert Event-Handling Code. |
mouseExit
| Component
| processMouseEvent
See How to Convert Event-Handling Code. |
mouseMove
| Component
| processMouseMotionEvent
See How to Convert Event-Handling Code. |
mouseUp
| Component
| processMouseEvent
See How to Convert Event-Handling Code. |
move
| Component, Rectangle
| setLocation
|
nextFocus
| Component, Container, Window
| transferFocus
|
postEvent
| Component, Window
| dispatchEvent
|
preferredSize
| Component, Container, TextArea, TextField
| getPreferredSize
|
replaceText
| TextArea
| replaceRange
|
reshape
| Component, Rectangle
| setBounds
|
resize
| Component, Rectangle
| setSize
|
setCurrent
| CheckboxGroup
| setSelectedCheckbox
|
setCursor
| Frame
| setCursor method in Component
|
setEchoCharacter
| TextField
| setEchoChar
|
setLineIncrement
| Scrollbar
| setUnitIncrement
|
setMultipleSelections
| List
| setMultipleMode
|
setPageIncrement
| Scrollbar
| setBlockIncrement
|
show()
| Component
| setVisible(true)
|
show(expression)
| Component
| setVisible(expression)
|
size
| Component
| getSize
|