Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop and Revise the code below from the MainForm Class for when the user clicks on the friendsTab, it lists the friends the user has

Develop and Revise the code below from the MainForm Class for when the user clicks on the friendsTab, it lists the friends the user has from the database (friends table) into the friendsScroll in the GUI so the user can scroll through the list of friends they have. Similarily, also for the favoritesTab where it lists the user's favorites from the friends table and displays the favoritesScroll.

import com.mysql.cj.jdbc.StatementImpl;import javax.swing.*;import javax.xml.transform.Result;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.StringWriter;import java.sql.*;public class MainForm extends JDialog{ private JPanel friendPanel; private JPanel friendsTab; private JPanel onlineTab; private JPanel groupsTab; private JPanel allUsersTab; private JPanel favoritesTab; private JPanel socialTab; private JPanel accountTab; private JScrollPane friendsScroll; private JScrollPane favoritesScroll; private JScrollPane onlineScroll; private JScrollPane groupsScroll; private JScrollPane allUsersScroll; private JScrollPane socialScroll; private JScrollPane accountScroll; private JButton registerButton; private JTextArea allUsersArea; private JTextField textField1; private JButton enterButton; private JTextArea testArea; private JButton testButton; public MainForm() { setContentPane(friendPanel); setTitle("Home Screen"); setContentPane(friendPanel); setMinimumSize(new Dimension(450, 474)); setModal(true); setDefaultCloseOperation(DISPOSE_ON_CLOSE); public void displayFriends() { final String databaseName = ""; final String DB_URL = "" + databaseName + ""; String DB_USERNAME = ""; String DB_PASSWORD = ""; try { Connection connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT * FROM friends"); while (resultSet.next()) { String name = resultSet.getString("name"); int id = resultSet.getInt("id"); String username = resultSet.getString("username"); } statement.close(); connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } } public void displayFavorites() { Statement statement; try { ResultSet resultSet = statement.executeQuery("SELECT * FROM friends WHERE favorite = 1"); while (resultSet.next()) { String name = resultSet.getString("name"); String id = String.valueOf(resultSet.getInt("id")); String username = resultSet.getString("username"); } statement.close(); connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } } setVisible(true); } public static void main(String[] args) { MainForm mainForm = new MainForm(); }}

Preview of the GUI Window where Friends = friendsTab and Favorites = favoritesTab. The space below is the JScroll Pane (friendsScroll, favoritesScroll) where the user can scroll through the list of friends or favorites based from the database (friends table)

image text in transcribedimage text in transcribed
\f\f

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_2

Step: 3

blur-text-image_3

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

3. What sort of competitive pricing strategy does Harley use?

Answered: 1 week ago