Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change this code so that it uses preparedStatements to connect to JDBC and be able to login with multiple accounts in the database ______________________________________ import

Change this code so that it uses preparedStatements to connect to JDBC and be able to login with multiple accounts in the database ______________________________________

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*;

final class LoginFrame extends JFrame implements ActionListener { Container container = getContentPane(); JLabel userLabel = new JLabel("USERNAME"); JLabel passwordLabel = new JLabel("PASSWORD"); JTextField userTextField = new JTextField(); JTextField passwordField = new JTextField(); JButton loginButton = new JButton("LOGIN"); int i = 0; LoginFrame() { setLayoutManager(); setLocationAndSize(); addComponentsToContainer(); addActionEvent(); } public void setLayoutManager() { container.setLayout(null); } public void setLocationAndSize() { userLabel.setBounds(50, 50, 100, 30); passwordLabel.setBounds(50, 120, 100, 30); userTextField.setBounds(150, 50, 150, 30); passwordField.setBounds(150, 120, 150, 30); loginButton.setBounds(120, 180, 100, 30); } public void addComponentsToContainer() { container.add(userLabel); container.add(passwordLabel); container.add(userTextField); container.add(passwordField); container.add(loginButton); } public void addActionEvent() { loginButton.addActionListener(this); }

@Override public void actionPerformed(ActionEvent e) { //Coding Part of LOGIN button if (e.getSource() == loginButton) { String userText; String pwdText; userText = userTextField.getText(); pwdText = passwordField.getText(); if (userText.equalsIgnoreCase("mehtab") && pwdText.equalsIgnoreCase("12345")) { JOptionPane.showMessageDialog(this, "Login Successful"); } else { JOptionPane.showMessageDialog(this, "Invalid Username or Password"); } } //Coding Part of RESET button if (e.getSource() == resetButton) { userTextField.setText(""); passwordField.setText(""); } //Coding Part of showPassword JCheckBox if (e.getSource() == showPassword) { if (showPassword.isSelected()) { passwordField.setEchoChar((char) 0); } else { passwordField.setEchoChar('*'); } } } } public class Login { public static void main(String[] a) { LoginFrame frame = new LoginFrame(); frame.setTitle("Login Screen"); frame.setVisible(true); frame.setBounds(10, 10, 350, 350); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

4. What decision would you make and why?

Answered: 1 week ago

Question

3. Review the evidence. Do you believe the testimony presented?

Answered: 1 week ago