Avatar billede japlex Nybegynder
02. april 2003 - 00:21 Der er 3 kommentarer og
1 løsning

Deprecated - Hvad skal jeg bruge i stedet og hvordan!

Jeg har følgende stump programkode, som jeg anvender en metode HandleEvent() der er "deprecated". Jeg har fundet ud af at jeg skal bruge ProcessEvent(), men hvordan retter jeg koden til

KODEN:

public boolean handleEvent(Event evt) {

// The standard format for this method includes the Event class where
// all the properties are set.

  if (evt.target == NameField)
    {char c=(char)evt.key;
// Look for the Enter key pressed in the NameField.
      if (c  == '\n')
          { Name=NameField.getText();
// Set the global Name variable to the contents in the NameField.
          return true;
        }
      else { return false; }
    }

if (evt.target == DBurl)
      {char c=(char)evt.key;
// Look for the enter key pressed in the DBurl TextArea.
    if (c  == '\n')
          { url=DBurl.getText();
// Set the global url variable to the contents of the DBurl TextArea.
          return true;
        }
      else { return false; }
    }

if (evt.target  ==  QueryField)
      {char c=(char)evt.key;
//  Look for the Enter key pressed in the QueryField.
      if (c  == '\n')
        {
                OutputField.setText(Select(QueryField.getText()));
// Get the contents of the QueryField, and pass them to the Select
// method that is defined in Listing 4.7. The Select method executes the
// entered query, and returns the results. These results are shown in the
// OutputField using the setText method.
            return true;
        }
      else { return false; }
    }

if (evt.target == ConnectBtn)
  {
// If the user clicks the "Connect" button, connect to the database
// specified in the DBurl TextArea and the user name specified in the
// NameField TextArea.

        url=DBurl.getText();
      Name=NameField.getText();
    try {
        //new imaginary.sql.iMsqlDriver();
// This creates a new instance of the Driver we want to use. There are a
// number of ways to specify which driver you want to use, and there is
// even a way to let the JDBC DriverManager choose which driver it thinks
// it needs to connect to the data source.
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(url, Name, "");
// Actually make the connection. Use the entered URL and the entered
// user name when making the connection. We haven't specified a password,
// so just send nothing ("").
      ConnectBtn.setLabel("Reconnect to Database");
// Finally, change what the ConnectBtn  to show "Reconnect to Database".
    }
    catch( Exception e ) {
        e.printStackTrace();
        OutputField.setText(e.getMessage());
    }
// The creation of the connection throws an exception if there was a
// problem connecting using the specified parameters. We have to enclose
// the getConnection method in a try-catch block to catch any
// exceptions that may be thrown. If there is a problem and an exception
// thrown, print it out to the console, and to the OutputField.

  return true;
  }
return false;
} // handleEvent() end
Avatar billede mosquito Nybegynder
02. april 2003 - 07:45 #1
prøv med interface ActionListener kræver du opretter metoden actionPerformed(ActionEvent e) som håndterer dine events
Avatar billede arne_v Ekspert
02. april 2003 - 20:42 #2
Du kan læse hvordan du erstatter handlEvent på:
  http://java.sun.com/docs/books/tutorial/post1.0/converting/convertingAWT.html
Avatar billede arne_v Ekspert
13. april 2003 - 20:29 #3
japlex>

Er du kommet videre ?
Avatar billede arne_v Ekspert
22. maj 2003 - 22:33 #4
??
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester