Subject : Java 1.1 AWT deprecated methods

Solution Description:
=====================

. ¾Æ·¡ÀÇ ¿¹Á¦´Â jdk1.0.2¿¡¼­ ÀÛ¼ºÇÑ ¼Ò½ºÄÚµåÀÌ´Ù.

www% vi DialogWindow.java

import java.awt.*;

public class DialogWindow extends Frame {
    private boolean inAnApplet = true;
    private SimpleDialog dialog;
    private TextArea textArea;

    public DialogWindow() {
        textArea = new TextArea(5, 40);
        textArea.setEditable(false);
        add("Center", textArea);
        Button button = new Button("Click to bring up dialog");
        Panel panel = new Panel();
        panel.add(button);
        add("South", panel);
    }

    public boolean handleEvent(Event event) {
        if (event.id == Event.WINDOW_DESTROY) {
            if (inAnApplet) {
                dispose();
            } else {
                System.exit(0);
            }
        }   
        return super.handleEvent(event);
    }

    public boolean action(Event event, Object arg) {
        if (dialog == null) {
            dialog = new SimpleDialog(this, "A Simple Dialog");
        }
        dialog.show();
        return true;
    }

    public void setText(String text) {
        textArea.appendText(text + "\n");
    }

    public static void main(String args[]) {
        DialogWindow window = new DialogWindow();
        window.inAnApplet = false;

        window.setTitle("DialogWindow Application");
        window.pack();
        window.show();
    }
}

class SimpleDialog extends Dialog {
    TextField field;
    DialogWindow parent;
    Button setButton;

    SimpleDialog(Frame dw, String title) {
        super(dw, title, false);
        parent = (DialogWindow)dw;

        //Create middle section.
	Panel p1 = new Panel();
        Label label = new Label("Enter random text here:");
        p1.add(label);
        field = new TextField(40);
	p1.add(field);
        add("Center", p1);

        //Create bottom row.
        Panel p2 = new Panel();
        p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
        Button b = new Button("Cancel");
        setButton = new Button("Set");
        p2.add(b);
        p2.add(setButton);
        add("South", p2);

	//Initialize this dialog to its preferred size.
	pack();
    }

    public boolean action(Event event, Object arg) {
        if ( (event.target == setButton)
           | (event.target == field)) {
            parent.setText(field.getText());
        }
        field.selectAll();
        hide();
        return true;
    }
}

. À§ÀÇ Äڵ带 jdk1.1.x ȯ°æ¿¡¼­ ÄÄÆÄÀÏÇÏ¸é ¾Æ·¡¿Í °°Àº message°¡ print°¡
  µÇ´Â °ÍÀ» º¼¼ö ÀÖ´Ù.
  ÀÚ¹Ù´Â jdk1.1.x·Î upgradeµÇ¸é¼­ º¯È­°¡ ÀÖ¾ú´Ù. 
  ƯÈ÷ Window Programming °ü·ÃÇÏ¿© ¸¹Àº º¯È­°¡ ÀÖ¾ú´Ù.
  ¾Æ·¡ÀÇ message´Â jdk1.1Àº ´õÁÁÀº method°¡ ÀÖÀ¸´Ï ¹Ù²Ù¾î¼­ jdk1.1·Î ÃÖÀûÈ­
  ½Ãų¼ö ÀÖ´Ù´Â ÀǹÌÀÌ´Ù. ¹°·Ð conversionÀ» ÇÏÁö ¾Ê¾Æµµ ½ÇÇàÇϴµ¥´Â
  ¹®Á¦°¡ ¾ø´Ù. Áï 1.1Àº 1.0.2¸¦ ¼ö¿ëÇÑ´Ù´Â ÀǹÌÀÌ´Ù.


www% javac DialogWindow.java
Note: DialogWindow.java uses a deprecated API.  Recompile with "-deprecation" for details.
1 warning

. »ó¼¼ÇÑ Á¤º¸¸¦ º¸·Á¸é ´ÙÀ½°ú °°Àº optionÀ» ÁÙ¼öµµ ÀÖ´Ù.

www% javac -deprecation DialogWindow.java
DialogWindow.java:18: Note: The method boolean handleEvent(java.awt.Event) in class java.awt.Component has been deprecated, and class DialogWindow (which is not deprecated) overrides it.
    public boolean handleEvent(Event event) {
                   ^
DialogWindow.java:26: Note: The method boolean handleEvent(java.awt.Event) in class java.awt.Component has been deprecated.
        return super.handleEvent(event);
                                ^
DialogWindow.java:29: Note: The method boolean action(java.awt.Event, java.lang.Object) in class java.awt.Component has been deprecated, and class DialogWindow (which is not deprecated) overrides it.
    public boolean action(Event event, Object arg) {
                   ^
DialogWindow.java:38: Note: The method void appendText(java.lang.String) in class java.awt.TextArea has been deprecated.
        textArea.appendText(text + "\n");
                           ^
DialogWindow.java:81: Note: The method boolean action(java.awt.Event, java.lang.Object) in class java.awt.Component has been deprecated, and class SimpleDialog (which is not deprecated) overrides it.
    public boolean action(Event event, Object arg) {
                   ^
DialogWindow.java:87: Note: The method void hide() in class java.awt.Component has been deprecated.
        hide();
            ^
Note: DialogWindow.java uses a deprecated API.  Please consult the documentation for a better alternative.
7 warnings
www% 

. ´ÙÀ½Àº À§ÀÇ Äڵ带 1.1¿¡ ¸Â²²²û conversionÇÏ´Â °úÁ¤ÀÌ´Ù.

  ¸ÕÀú ¾Æ·¡ÀÇ Å×À̺íÀ» »ìÆ캸ÀÚ.

                     AWT 1.1 Deprecated Method Table

--------------------------------------------------------------------------------
    Deprecated Method        Class Where            1.1 Replacement
                             Deprecated
--------------------------------------------------------------------------------
                                            See How to Convert
 action                   Component         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,     getItemCount
                          Menu
 countMenus               MenuBar           getMenuCount

 deliverEvent             Component,        dispatchEvent
                          Container
 disable()                MenuItem          setEnabled(false)

 enable()                 Component,        setEnabled(true)
                          MenuItem
 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
                                            processFocusEvent
                                            See How to Convert
 gotFocus                 Component         Event-Handling Code for
                                            information on preferred ways
                                            to handle events.
                                            processEvent
                                            See How to Convert
 handleEvent              Component         Event-Handling Code for
                                            information on preferred ways
                                            to handle events.
 hide                     Component         setVisible(false)
 insertText               TextArea          insert
 insets                   Container         getInsets
                          Component,
 inside                   Polygon,          contains
                          Rectangle
 isSelected               List              isIndexSelected
                                            processKeyEvent
 keyDown                  Component         See How to Convert
                                            Event-Handling Code.
                                            processKeyEvent
 keyUp                    Component         See How to Convert
                                            Event-Handling Code.
                          Component,
 layout                   Container,        doLayout
                          ScrollPane

 locate                   Component,        getComponentAt
                          Container
 location                 Component         getLocation
                                            processFocusEvent
 lostFocus                Component         See How to Convert
                                            Event-Handling Code.
                          Component,
 minimumSize              Container,        getMinimumSize
                          TextArea,
                          TextField
                                            processMouseEvent
 mouseDown                Component         See How to Convert
                                            Event-Handling Code.
                                            processMouseMotionEvent
 mouseDrag                Component         See How to Convert
                                            Event-Handling Code.
                                            processMouseEvent
 mouseEnter               Component         See How to Convert
                                            Event-Handling Code.
                                            processMouseEvent
 mouseExit                Component         See How to Convert
                                            Event-Handling Code.
                                            processMouseMotionEvent
 mouseMove                Component         See How to Convert
                                            Event-Handling Code.
                                            processMouseEvent
 mouseUp                  Component         See How to Convert
                                            Event-Handling Code.

 move                     Component,        setLocation
                          Rectangle
                          Component,
 nextFocus                Container,        transferFocus
                          Window

 postEvent                Component,        dispatchEvent
                          Window
                          Component,
 preferredSize            Container,        getPreferredSize
                          TextArea,
                          TextField
 replaceText              TextArea          replaceRange

 reshape                  Component,        setBounds
                          Rectangle

 resize                   Component,        setSize
                          Rectangle
 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
--------------------------------------------------------------------------------

. ¿ø·¡ÀÇ 1.0.2ÀÇ Äڵ带 À§ÀÇ Å×À̺íÀ» ÂüÁ¶ÇÏ¿© ¼öÀÛ¾÷À¸·Î ÇÒ ¼öµµ ÀÖÁö¸¸
  ´ÙÀ½°ú °°Àº toolÀ» ÀÌ¿ëÇÏ¿© ÀÚµ¿À¸·Î conversionÇÏ´Â °Ô Æí¸®ÇÏ´Ù.

www% JAVA_HOME/java/docs/guide/awt/updateAWT DialogWindow.java > tmp.java

www% diff tmp.java DialogWindow.java
33c33
<         dialog.setVisible(true);
---
>         dialog.show();
38c38
<         textArea.append(text + "\n");
---
>         textArea.appendText(text + "\n");
47c47
<         window.setVisible(true);
---
>         window.show();
87c87
<         setVisible(false);
---
>         hide();
www% 
www% cp tmp.java DialogWindow.java
www% javac -deprecation DialogWindow.java
DialogWindow.java:18: Note: The method boolean handleEvent(java.awt.Event) in class java.awt.Component has been deprecated, and class DialogWindow (which is not deprecated) overrides it.
    public boolean handleEvent(Event event) {
                   ^
DialogWindow.java:26: Note: The method boolean handleEvent(java.awt.Event) in class java.awt.Component has been deprecated.
        return super.handleEvent(event);
                                ^
DialogWindow.java:29: Note: The method boolean action(java.awt.Event, java.lang.Object) in class java.awt.Component has been deprecated, and class DialogWindow (which is not deprecated) overrides it.
    public boolean action(Event event, Object arg) {
                   ^
DialogWindow.java:81: Note: The method boolean action(java.awt.Event, java.lang.Object) in class java.awt.Component has been deprecated, and class SimpleDialog (which is not deprecated) overrides it.
    public boolean action(Event event, Object arg) {
                   ^
Note: DialogWindow.java uses a deprecated API.  Please consult the documentation for a better alternative.
5 warnings
www% 

. À§ÀÇ °úÁ¤À» º¸¸é updateAWT¸¦ ÀÌ¿ëÇÏ¿© ¿ÏÀüÇÏ°Ô convertÇÒ ¼ö ¾øÀ½À» ¾Ë°Ô
  µÇ¾úÀ» °ÍÀÌ´Ù. Áï À§ÀÇ ¿¹Á¦¿¡¼­ º¸¸é handleEvent, actionµî ¼ÒÀ§ Event CodeµîÀº
  ÀÚµ¿À¸·Î º¯È¯ÀÌ ¾ÈµÇ°í ¾Æ·¡ÀÇ Å×À̺íÀ» ÂüÁ¶ÇÏ¿© ¼öÀÛ¾÷À¸·Î °íÃÄÁÖ¾î¾ß ÇÑ´Ù.


                      Event-Handling Code Conversion Table

--------------------------------------------------------------------------------
                     1.0                 |                              1.1
--------------------------------------------------------------------------------
  Event/Method         |Generated By     |  Interface      |   Methods
--------------------------------------------------------------------------------
                       |Button, List,    |                 |
                       |MenuItem,        |ActionListener   |actionPerformed
                       |                 |                 |(ActionEvent)
                       |TextField        |                 |
 ACTION_EVENT/action   |--------------------------------------------------------
                       |Checkbox,        |                 |
                       |CheckboxMenuItem,|ItemListener     |itemStateChanged
                       |                 |                 |(ItemEvent)
                       |Choice           |                 |
--------------------------------------------------------------------------------
                       |                 |                 |windowClosing
                       |                 |                 |(WindowEvent)
                       |                 |                 |windowOpened
                       |                 |                 |(WindowEvent)
                       |                 |                 |windowIconified
                       |                 |                 |(WindowEvent)
 WINDOW_DESTROY        |                 |                 |windowDeiconified
                       |                 |                 |(WindowEvent)
 WINDOW_EXPOSE         |                 |                 |windowClosed
                       |                 |                 |(WindowEvent) (no
 WINDOW_ICONIFY        |Dialog, Frame    |WindowListener   |1.0 equivalent)
 WINDOW_DEICONIFY      |                 |                 |windowActivated
                       |                 |                 |(WindowEvent) (no
                       |                 |                 |1.0 equivalent)
                       |                 |                 |windowDeactivated
                       |                 |                 |(WindowEvent) (no
                       |                 |                 |1.0 equivalent)
--------------------------------------------------------------------------------
                       |                 |                 |componentMoved
                       |                 |                 |(ComponentEvent)
                       |                 |                 |componentHidden
                       |                 |                 |(ComponentEvent)
                       |                 |                 |(no 1.0 equivalent)
 WINDOW_MOVED          |Dialog, Frame    |ComponentListener|componentResized
                       |                 |                 |(ComponentEvent)
                       |                 |                 |(no 1.0 equivalent)
                       |                 |                 |componentShown
                       |                 |                 |(ComponentEvent)
                       |                 |                 |(no 1.0 equivalent)
--------------------------------------------------------------------------------
 SCROLL_LINE_UP        |                 |                 |
 SCROLL_LINE_DOWN      |                 |                 |
 SCROLL_PAGE_UP        |                 |AdjustmentListener|
 SCROLL_PAGE_DOWN      |Scrollbar        |(or use the new  |adjustmentValueC
                       |                 |                 |hanged(Adjustment
 SCROLL_ABSOLUTE       |                 |ScrollPane class)|Event)
 SCROLL_BEGIN          |                 |                 |
 SCROLL_END            |                 |                 |
--------------------------------------------------------------------------------
 LIST_SELECT           |Checkbox,        |                 |
 LIST_DESELECT         |CheckboxMenuItem,|ItemListener     |itemStateChanged
                       |                 |                 |(ItemEvent)
                       |Choice, List     |                 |
--------------------------------------------------------------------------------
 MOUSE_DRAG/mouseDrag  |Canvas, Dialog,  |                 |mouseDragged
                       |                 |                 |(MouseEvent)
 MOUSE_MOVE/mouseMove  |Frame, Panel,    |MouseMotionListener|mouseMoved
                       |                 |                 |(MouseEvent)
                       |Window           |                 |
--------------------------------------------------------------------------------
                       |                 |                 |mousePressed
                       |                 |                 |(MouseEvent)
 MOUSE_DOWN/mouseDown  |                 |                 |mouseReleased
                       |                 |                 |(MouseEvent)
 MOUSE_UP/mouseUp      |Canvas, Dialog,  |                 |mouseEntered
                       |                 |                 |(MouseEvent)
 MOUSE_ENTER/mouseEnter|Frame, Panel,    |MouseListener    |mouseExited
                       |                 |                 |(MouseEvent)
 MOUSE_EXIT/mouseExit  |Window           |                 |mouseClicked
                       |                 |                 |(MouseEvent) (no
                       |                 |                 |1.0 equivalent)
--------------------------------------------------------------------------------
 KEY_PRESS/keyDown     |                 |                 |
 KEY_RELEASE/keyUp     |                 |                 |keyPressed
                       |                 |                 |(KeyEvent)
 KEY_ACTION/keyDown    |Component        |KeyListener      |keyReleased
                       |                 |                 |(KeyEvent)
 KEY_ACTION_RELEASE/keyUp|               |                 |keyTyped(KeyEvent) 
                       |                 |                 |(no 1.0 equivalent)
--------------------------------------------------------------------------------
 GOT_FOCUS/gotFocus    |                 |                 |focusGained
                       |                 |                 |(FocusEvent)
 LOST_FOCUS/lostFocus  |Component        |FocusListener    |focusLost
                       |                 |                 |(FocusEvent)
--------------------------------------------------------------------------------
 No 1.0 equivalent.    |                 |ContainerListener|componentAdded 
                       |                 |                 |(ContainerEvent)
                       |                 |                 |componentRemoved 
                       |                 |                 |(ContainerEvent)
--------------------------------------------------------------------------------
 No 1.0 equivalent.    |                 |TextListener     |textValueChanged
                       |                 |                 |(TextEvent)
--------------------------------------------------------------------------------
 
. ¾Æ·¡´Â conversionÀ» ¸¶Ä£ÈÄÀÇ ¿¹Á¦ ÄÚµåÀÌ´Ù.

www% vi DialogWindow.java

import java.awt.*;
import java.awt.event.*;

public class DialogWindow extends Frame 
			  implements WindowListener,
			             ActionListener {
    private boolean inAnApplet = true;
    private SimpleDialog dialog;
    private TextArea textArea;

    public DialogWindow() {
        textArea = new TextArea(5, 40);
        textArea.setEditable(false);
        add("Center", textArea);
        Button button = new Button("Click to bring up dialog");
	button.addActionListener(this);
        Panel panel = new Panel();
        panel.add(button);
        add("South", panel);
	addWindowListener(this);
    }

    public void windowClosed(WindowEvent event) {
    }

    public void windowDeiconified(WindowEvent event) {
    }

    public void windowIconified(WindowEvent event) {
    }

    public void windowActivated(WindowEvent event) {
    }

    public void windowDeactivated(WindowEvent event) {
    }

    public void windowOpened(WindowEvent event) {
    }

    public void windowClosing(WindowEvent event) {
        if (inAnApplet) {
            dispose();
        } else {
            System.exit(0);
        }
    }

    public void actionPerformed(ActionEvent event) {
        if (dialog == null) {
            dialog = new SimpleDialog(this, "A Simple Dialog");
        }
        dialog.setVisible(true);
    }

    public void setText(String text) {
        textArea.append(text + "\n");
    }

    public static void main(String args[]) {
        DialogWindow window = new DialogWindow();
        window.inAnApplet = false;

        window.setTitle("DialogWindow Application");
        window.pack();
        window.setVisible(true);
    }
}

class SimpleDialog extends Dialog implements ActionListener {
    TextField field;
    DialogWindow parent;
    Button setButton;

    SimpleDialog(Frame dw, String title) {
        super(dw, title, false);
        parent = (DialogWindow)dw;

        //Create middle section.
	Panel p1 = new Panel();
        Label label = new Label("Enter random text here:");
        p1.add(label);
        field = new TextField(40);
	field.addActionListener(this);
	p1.add(field);
        add("Center", p1);

        //Create bottom row.
        Panel p2 = new Panel();
        p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
        Button b = new Button("Cancel");
	b.addActionListener(this);
        setButton = new Button("Set");
	setButton.addActionListener(this);
        p2.add(b);
        p2.add(setButton);
        add("South", p2);

	//Initialize this dialog to its preferred size.
	pack();
    }

    public void actionPerformed(ActionEvent event) {
	Object source = event.getSource();
        if ( (source == setButton)
           | (source == field)) {
            parent.setText(field.getText());
        }
        field.selectAll();
        setVisible(false);
    }
}

----------------------------------------------------------------------------

Revision History

ÀÛ¼ºÀÏÀÚ : 97.07.21
ÀÛ¼ºÀÚ : À̹ÎÈ£

¼öÁ¤ÀÏÀÚ :
¼öÁ¤ÀÚ :