Results 1 to 12 of 12
  1. #1
    iuna's Avatar
    iuna is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default deprecated method.. help!

    Can someone please help me in converting the deprecated method handleEvent() to processEvent() in this program? I don't know how..

    attached is the program I'm working on.. thanks for the help
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    What have you tried so far?
    What does the doc say for the new method?
    Why are you using such low level methods? This must be a VERY old program.

  3. #3
    iuna's Avatar
    iuna is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    it says that I have to use protected void processEvent(AWTEvent e)..

    seems like I have to create an AWTEvent method.. does it mean that I just have to copy all the contents of handleEvent into the AWTEvent?

    waa.. O_O

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    There is a problem with Game.zip file. I can't open it after its downloaded.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I opened it with 7-zip, but it was created using AWT which I don't know:

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    Why are you using such low level methods?
    You should rewrite the code to use current techniques such as Listeners.
    What events does the code handle?

  8. #8
    iuna's Avatar
    iuna is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    sorry for the corrupted file..

    it can be downloaded at mediafire[dot]com/download[dot]php?2scvqbhzg6x

    (seems like I can't post links here)

  9. #9
    iuna's Avatar
    iuna is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You should rewrite the code to use current techniques such as Listeners.
    What events does the code handle?
    I think it handles the "Start", "Submit" and "Accept" events

  10. #10
    iuna's Avatar
    iuna is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Did you read the Java document? It should be clearly explain what you have to do.
    yes I've read it but I'm still new to Java so I'm still lost with the API..

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    "Start", "Submit" and "Accept" events
    Those don't sound like events. Are they the labels on buttons?
    Buttons create ActionEvents which are handled by actionListeners.

    The deprecation messages are only warnings. You can ignore them for now. The program should execute. As you learn java you will learn about events and listeners and will be able to rewrite the program to use them instead of using handleEvent

  12. #12
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    //import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    //import java.lang.Math;
    
    public class BotNav extends Panel implements ActionListener,
                                                 ItemListener {
        Matches parent;
        TextField counter;
        Label lcounter;
        Label lchoice;
        Choice choice;	
        Button submit;
        Button start;
        Button accept;
        int selected = 1;
        String content;
    
        BotNav(Matches contr) {
            super();
            parent = contr;
            counter = new TextField(3);
            counter.setEditable(false);
            lcounter = new Label("       Counter:");
            lchoice = new Label("     Your turn:");
            choice = new Choice();
            choice.addItem("1");
            choice.addItem("2");
            choice.addItem("3");
            choice.addItemListener(this);
            start = new Button("Start");
            submit = new Button("Submit");
            accept = new Button("Accept");
            start.addActionListener(this);
            submit.addActionListener(this);
            accept.addActionListener(this);
            setLayout(new GridLayout(1,7));
            add(start);
            add(lcounter);
            add(counter);
            add(accept);
            add(lchoice);
            add(choice);
            add(submit);
        }
    
        public int getSelected() {
            return this.selected;
        }
    
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                int result = parent.getCount();
                if (result > 1) {
                    selected = choice.getSelectedIndex() + 1;
                    if ((result - selected) < 1) {
                        parent.textField.setText("EEEEK ! Are you crazy ?");
                    } else {
                        parent.textField.setText("Your choice is " + selected +
                                                 ", you can submit it !");
                    }
                }
            }
        }
    
        public void actionPerformed(ActionEvent e) {
            Button button = (Button)e.getSource();
            String ac = button.getActionCommand();
            if (ac.equals("Start")) {
                parent.setCount(0);
                parent.board.repaint();
                parent.textField.setText("Ok...now choose count of matches");
                counter.setEditable(true);
                counter.requestFocus();
            }
            if (ac.equals("Accept")) {
                boolean edit = counter.isEditable();
                if (edit) {
                    content = counter.getText();
                    int count = Integer.valueOf(content).intValue();
                    if ((count > 60) || (count < 2)) {
                        parent.textField.setText("Choose min. 2 and max. " +
                                                 "60 matches");
                        counter.requestFocus();
                    } else {
                        counter.setEditable(false);
                        counter.transferFocus();
                        parent.setCount(count);
                        parent.board.repaint();
                        parent.textField.setText("Now it's your turn");
                    }
                }
            }
            if (ac.equals("Submit")) {
                int newcount = parent.getCount();
                if (newcount > 1) {
                    if ((newcount - selected) < 1) {
                        if (newcount == 3) {
                            parent.textField.setText("Take 2 !!!");
                        } else {
                            parent.textField.setText("Take 1 !!!"); 
                        }
                    } else {
                        newcount -= selected;
                        parent.setCount(newcount);
                        parent.board.repaint();
                        counter.setText((String.valueOf(newcount).toString()));
                        parent.myTurn();
                    }
                }
            }
        }
    }

Similar Threads

  1. getYear deprecated method
    By ravian in forum New To Java
    Replies: 5
    Last Post: 01-05-2011, 08:50 AM
  2. I need help with a deprecated program
    By mikau in forum New To Java
    Replies: 0
    Last Post: 02-13-2008, 09:34 AM
  3. Using Deprecated Methods
    By ravian in forum New To Java
    Replies: 3
    Last Post: 11-23-2007, 07:58 PM
  4. method size is deprecated
    By oregon in forum New To Java
    Replies: 4
    Last Post: 08-05-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •