I need to change Java code set up I want to add a method. What is the best way o
ID: 3891424 • Letter: I
Question
I need to change Java code set up I want to add a method. What is the best way of adding the method?
Existing code
private void LogsubmitActionPerformed(java.awt.event.ActionEvent evt) {
try {
String password = jPassword.getText();
String username = jtxtUsername.getText();
File texting = new File("Log.txt");
//open file in append mode
BufferedWriter writer;
writer = new BufferedWriter(new FileWriter(texting,true));
//date and time
Date currentTime =Calendar.getInstance().getTime();
boolean valid = false;
//used a hard-coded username and password
if(username.equals("anna")&&(password.equals("password")))
{
jtxtUsername.setText(null);
jPassword.setText(null);
JOptionPane.showMessageDialog(null, "success");
writer.write(username + currentTime);
writer.write("success");
valid = true;
}
else if(!valid)
JOptionPane.showMessageDialog(null, "invalid password");
writer.write(password + currentTime);
writer.write("failed");
writer.close();
} catch (IOException ex) {
Logger.getLogger(LoginApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
I would like to add public boolean testUser(String jtxtUsername, String jPassword) after the private void LogsubmitActionPerformed(java.awt.event.ActionEvent evt) method. When I add I get an error of illegal start of expression.
Explanation / Answer
You can add the method just after the LogsubmitActionPerformed method, please share complete class code I would be happy to help.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.