Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / study / engineering / computer science / questions and answers / java hel

ID: 3572690 • Letter: H

Question

home / study / engineering / computer science / questions and answers / java help make my program: 1. verifiy the user ...

Your question has expired and been refunded.

We were unable to find a Chegg Expert to answer your question.

Question: Java help make my program: 1. Verifiy the user nam...

Bookmark

Java help make my program:

1. Verifiy the user name and password against hard-coded values
  
2. Show a match or non-match message using text from the resource bundle
  
3.Store the results to a file, the name of which is stored in the Resource
   Bundle.
  
4. File values are labeled using labels from the resource bundle

LoginTwo(Main)
------------
import java.util.Locale;
import java.util.ResourceBundle;

public class LoginTwo {
public static void main(String[] args) {
String bundleName = "duffy.Example";
ResourceBundle labels = ResourceBundle.getBundle(bundleName, Locale.ENGLISH);
MyGui myGui = new MyGui(new User(), labels);
System.out.println("Starting program: " + labels.getString("program_name"));
System.out.println("Greeting: " + labels.getString("greeting"));
labels = ResourceBundle.getBundle(bundleName, Locale.CHINESE);
System.out.println("Starting program: " + labels.getString("program_name"));
System.out.println("Greeting: " + labels.getString("greeting"));
}
}

UserThing
------------
public class UserThing {
private int aNumber;
private String aString;
public int getaNumber() {
return aNumber;
}
public void setaNumber(int aNumber) {
this.aNumber = aNumber;
}
public String getaString() {
return aString;
}
public void setaString(String aString) {
this.aString = aString;
}
}


MyGui
--------------------
import java.awt.HeadlessException;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class MyGui extends JFrame{
private final int WINDOW_WIDTH = 400;
private final int WINDOW_HEIGHT = 400;
private final User user;
private final ResourceBundle labels;
private JPanel panel;
private JLabel username;
private JTextField numberField;
private JLabel password;
private JTextField stringField;
private JButton submit_button;
public MyGui(User user, ResourceBundle labels) throws HeadlessException {
super();
this.user = user;
this.labels = labels;
initialize();
}
private void initialize(){
setTitle(labels.getString("program_name"));
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
username = new JLabel();
username.setText(labels.getString("username"));
panel.add(username);
numberField = new JTextField(40);
numberField.setText("" + user.getaNumber());
panel.add(numberField);
password = new JLabel();
password.setText(labels.getString("password"));
panel.add(password);
stringField = new JTextField(40);
panel.add(stringField);
submit_button = new JButton();
submit_button.setText(labels.getString("submit_button"));
panel.add(submit_button);
add(panel);
setVisible(true);
}
}

Example.properties
------------------------
program_name = Example
greeting = Hello
username = Username
password = Password
submit_button = Submit

Example_zh.properties
---------------------------
program_name = lizhi
greeting = nihao
number_label = haoma
string_label = nideshuzhi
submit_button = queding

Explanation / Answer

<%
String loginbuttonClicked = request.getParameter("submit");
//This is done to check whether the "Login" button is clicked
if(loginbuttonClicked != null)
{
//now we will be retrieving the username & password typed in by the user from the submitted form
String username = request.getParameter("username");
String password = request.getParameter("password");

String user;
String pass;
//
String query = "SELECT * from login";
dbselect.rs = dbselect.executeQuery(query);
while ((dbselect.rs).next())
{
user = (dbselect.rs).getString("login");
pass = (dbselect.rs).getString("password");
//this is done to verify whether the username & password entered by the user match any of the
entries in the login table of the movies database
if((user.equals(username)) && (pass.equals(password)))
{
//finally we will be redirecting to the page that can do shopping
response.sendRedirect("AddCART.jsp");
}