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 tilKODEN:
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
