0% found this document useful (0 votes)
2 views37 pages

IT61J

The document is a project report for a News Portal System developed in Java by R Navin Prasath as part of the requirements for a Bachelor of Technology degree. It outlines the project's objectives, methodology, and features, including user and admin functionalities, article management, and a user-friendly interface created with Java Swing. The report also includes acknowledgments, institutional vision and mission statements, and educational objectives related to the project.

Uploaded by

h2328
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views37 pages

IT61J

The document is a project report for a News Portal System developed in Java by R Navin Prasath as part of the requirements for a Bachelor of Technology degree. It outlines the project's objectives, methodology, and features, including user and admin functionalities, article management, and a user-friendly interface created with Java Swing. The report also includes acknowledgments, institutional vision and mission statements, and educational objectives related to the project.

Uploaded by

h2328
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

NEWS PORTAL SYSTEM

A PROJECT REPORT

Submitted by

R NAVIN PRASATH (8115U23IT061)

in partial fulfillment of requirements for the award of the course of


CGB1201 – JAVA PROGRAMMING
in

DEPARTMENT OF INFORMATION TECHNOLOGY

K. RAMAKRISHNAN COLLEGE OF ENGINEERING


(An Autonomous Institution, affiliated to Anna University Chennai andApproved
by,AICTE, New Delhi)

SAMAYAPURAM – 621 112

DECEMBER - 2024

i
K. RAMAKRISHNAN COLLEGE OF ENGINEERING
(An Autonomous Institution, affiliated to Anna University Chennai and Approved by AICTE, New Delhi)

SAMAYAPURAM – 621 112

BONAFIDE CERTIFICATE

Certified that this project report titled “NEWS PORTAL SYSTEM IN JAVA” is
the bonafide work of R NAVIN PRASATH (8115U23IT061), who carried out the
project work under my supervision. Certified further, that to the best of my knowledge
the work reported here in does not form part of any other project report or dissertation
onthe basis of which a degree or awardwas conferred on an earlier occasion on this
or any other candidate.

SIGNATURE SIGNATURE
Dr.S.Manikandan M.E., Ph.D., Mrs. S. SathyaPriya, M.E,

HEAD OF THE DEPARTMENT SUPERVISOR


PROFESSOR, ASSISTAN PROFESSOR,
Department of Information Technology, Department of Information Technology,

K. Ramakrishnan College of Engineering K. Ramakrishnan College of Engineering


(Autonomous) (Autonomous)
Samayapuram – 621 112 Samayapuram – 621 112

Submitted for the End Semester Examination held on …………

INTERNAL EXAMINER EXTERNAL EXAMINER

ii
DECLARATION

I declare that the project report on “NEWS PORTAL SYSTEM IN JAVA” is the
result of original work done by me and to the best of my knowledge, similar work has
not been submitted to “ANNA UNIVERSITY CHENNAI” for the requirement of
Degree of BACHELOR OF TECHNOLOGY. This project report is submitted on the
partial fulfillment of the requirement of the award of the degree of BACHELOR OF
TECHNOLOGY.

Signature

R NAVIN
PRASATH

Place: Samayapuram
Date:

iii
ACKNOWLEDGEMENT

It is with great pride that I express my gratitude and indebtedness to my


instituion, “K. Ramakrishnan College of Engineering (Autonomous)”,
for providing me the opportunity to do this project.

I extend my sincere acknowledgment and appreciation to the esteemed and


honorable Chairman, Dr. K. RAMAKRISHNAN, for having provided the
facilities during the course of my study in college.

I would like to express my sincere thanks to my beloved Executive Director,


Dr. S. KUPPUSAMY, MBA, Ph.D., for forwarding my project and
offeringan adequate duration to complete it.

I would like to thank Dr. D. SRINIVASAN, B.E, M.E., Ph.D., Principal,


who gave the opportunity to frame the project to full satisfaction.

I thank Dr.S.MANIKANDAN M.E., Ph.D., Head of the Department of


Information Technology, for providing his encouragement in pursuing this
project.

I wish to convey my profound and heartfelt gratitude to my esteemed project


guide Mrs S. SathyaPriya, M.E., Department of Information Technology,
for his incalculable suggestions, creativity, assistance and patience, which
motivated me to carry out this project.

I render my sincere thanks to the Course Coordinator and other staff


members for providing valuable information during the course.
I wish to express my special thankst to the officials &Lab Technicians of my
departments who rendered their help during the period of the work progress

iv
VISION OF THE INSTITUTION

To achieve a prominent position among the top technical institutions

MISSION OF THE INSTITUTION

• To bestow standard technical education par excellence through state of


the art infrastructure,competent faculty and high ethical standards.

• To nurture research and entrepreneurial skills among students in cutting edge


technologies.

• To provide education for developing high-quality professionals to transform


the society.

DEPARTMENT VISION AND MISSION

VISION

To create technically efficient and quality IT professional with competent and


innovation skills, inculcatingmoral values and societal concerns.

MISSION

• To strengthen the fundamental understanding of Information Technology.

• To produce successful graduates who can adapt to the challenges of the


changing corporate world.

• To build necessary skills in Information Technology to serve the


Industry,Government ,society.

v
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)

PEO1: To expose students to tools and techniques of Information Technology so that


they can utilize their fundamental knowledge in innovative computing and building
solutions for real life problems.

PEO2: To promote collaborative learning, think logically and develop the spirit of
teamwork to understandand solve technical issues and to build optimal solutions.

PEO3: To equip students with better knowledge on hardware and software systems
by applying theirtechnical skills to solve real world problems.

PROGRAM OUTCOMES (POs)

Engineering students will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science,

engineeringfundamentals,andanengineeringspecializationtothesolutionofcomplex
engineeringproblems.
2. Problem analysis: Identify, formulate, review research literature, and analyze

complex engineering problems reaching substantiated conclusions using first


principles of mathematics, natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering

problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge

andresearchmethodsincludingdesignofexperiments,analysisandinterpretationofdat
a,andsynthesisofthe information to provide valid conclusions.

vi
5. Modern tool usage: Create, select, and apply appropriate techniques, resources,

andmodernengineeringandITtoolsincludingpredictionandmodelingtocomplexengi
neeringactivitieswith an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual

knowledgetoassesssocietal,health,safety,legalandculturalissuesandtheconsequentr
esponsibilitiesrelevanttothe professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional

engineeringsolutionsinsocietalandenvironmentalcontexts,anddemonstratetheknow
ledgeof,andneedfor sustainable development.
8. Ethics:Applyethicalprinciplesandcommittoprofessionalethicsandresponsibilitiesa

ndnorms of the engineering practice.


9. Individualand team work: Function effectively as an individual, and as amember

or leader in diverse teams, and in multidisciplinary settings.


10. Communication: Communicate effectively on complex engineering activities

with the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding
of the engineering and management principles and apply these to one’s own work, as
a member and leader in a team, to manage projects and in multidisciplinary
environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability
to engage in independent and life-long learning in the broadest context of
technological change.

vii
PROGRAM SPECIFIC OUTCOMES (PSOs)

PSO1: To understand, analyze, develop, select and apply suitable computer


techniques in the complex engineering algorithms for efficient design of
information technology systems of varying complexity.

PSO2: To utilize modern techniques by considering human, financial, ethical and


environmental factors increating innovative career paths to be an entrepreneur and
leadership qualities.

viii
ABSTRACT

The News Portal System is a Java-based application designed to provide a


dynamic platform for users to access and manage news articles. It facilitates two
main roles: admin and regular users. The system allows users to register, log in,
and view articles, while admins can post, view, and delete articles, as well as
manage article categories. The user interface is created using Java Swing,
providing an interactive environment for users to navigate. The application
supports features such as user authentication, article management, dynamic
category selection (with custom category input for admins), and a user-friendly
article display system. The system ensures data security and user accessibility
through efficient password management and role-based access. The backend
utilizes basic data structures such as HashMaps and ArrayLists to store user data,
admin status, and articles. This project aims to simulate a fully functional news
portal system with fundamental features suited for a small scale news
management platform.

ix
ABSTRACT WITH Pos AND PSOMAPG
ABSTRACT POs PSOs
MAPPED MAPPED
The News Portal System is a Java-
PO 6 -2 PSO 1-3
based application designed to provide a PO 8 -3 PSO 2-3
PO 9 -3
dynamic platform for users to access
PO 10 -2
and manage news articles. It facilitates PO 11- 3
two main roles: admin and regular
users. The system allows users to
register, log in, and view articles, while
admins can post, view, and delete
articles, as well as manage article
categories. The user interface is created
using Java Swing, providing an
interactive environment for users to
navigate. The application supports
features such as user authentication,
article management, dynamic category
selection (with custom category input
for admins), and a user-friendly article
display system. The system ensures
data security and user accessibility
through efficient password
management and role-based access.
The backend utilizes basic data
structures such as HashMaps and
ArrayLists to store user data, admin
status, and articles.
Note: 1- Low, 2-Medium, 3- High

x
TABLE OF CONTENTS

CHAPTER NO . TITLE PAGE NO.

ABSTRACT X

1 INTRODUCTION 1

1.1 Objective 1

1.2 Overview 3

1.3 Java Programming concepts 4

2 PROJECT METHODOLOGY 5

2.1 Proposed Work 5

2.2 Block Diagram 6

3 MODULE DESCRIPTION 7

3.1 ADMIN DASHBOARD MODULE 7

3.2 ARTICLE MANAGEMENT MODULE 7

3.3 CATEGORY MANAGEMENT MODULE 7

3.4 USER LOGIN AND VIEW MODULE 7

3.5 DATA STORAGE MODULE 7

4 CONCLUSION & FUTURE SCOPE 8

4.1 Conclusion 8

4.2 Future Scope 9

REFERENCES 10

APPENDIX A (SOURCE CODE) 11

APPENDIX B (SCREENSHOTS) 25

xi
CHAPTER 1
INTRODUCTION
1.1 Objective

The objective of the News Portal System project is to develop a robust and user-
friendly platform that enables efficient management and distribution of articles and
news content. This project aims to cater to both administrators and users, providing
a seamless experience for creating, editing, and viewing articles. Designed with
scalability and functionality in mind, the system serves as a practical application
of core programming and design concepts in Java. By working on this project,
developers can enhance their understanding of object-oriented programming, GUI
development, and event-driven design while building a real-world application.

1. System Design and Development:


To design and develop a fully functional news portal system that allows
administrators to manage articles and users to view content effortlessly.
2. User Management:
To create a secure login and registration system distinguishing between
administrators and general users, ensuring appropriate access to features.
3. Article Management:
To enable administrators to add, edit, categorize, and delete articles while
maintaining a structured content database.
4. User Dashboard:
To develop a user dashboard that allows registered users to view articles in an
organized and visually appealing format.

1
5. Category Integration:
To implement an article categorization system, including a custom category
option, ensuring effective content organization and searchability.
6. Responsive Event Handling:
utilize Java's event handling capabilities for dynamic interaction and smooth
operation across all user actions.
7. User Interface Design:
To design a clean and intuitive interface using Java Swing, ensuring easy
navigation and an engaging user experience.
8. Scalability and Flexibility:
To ensure the system can accommodate additional features like advanced
search, filters, or multi-language support in the future.
9. Code Quality and Documentation:
To write well-structured, optimized, and documented code that adheres to
programming best practices, making it easy to maintain and expand.
10. Testing and Debugging:
To thoroughly test the system for functionality, usability, and security,
ensuring a bug-free and seamless user experience.
11. User Feedback and Improvement:
To incorporate feedback from users to refine the system and introduce
enhancements based on real-world use cases.

1
1.2 Overview

The News Portal System in Java is a comprehensive application that allows


administrators to manage articles and categories efficiently while enabling users to
access and view content seamlessly. The project leverages Java Swing for the
graphical user interface, providing components like JFrame for the main window,
JPanel for content layout, and event listeners for interactive elements such as
buttons and text fields.
The admin dashboard facilitates article creation with fields for the title, category
selection, and content entry. A special feature in the category section enables a
custom input text box to appear when "Other" is selected, allowing flexibility in
categorization. The admin can also view and manage all articles through a dedicated
window.
On the user side, the system offers a streamlined interface for viewing articles, with
access restricted to ensure data integrity. The application employs event-driven
programming for responsive navigation and interaction, using features like
ActionListener for button actions and real-time form validation.
The overall structure of the system is modular, with classes handling the core
functionalities of article management, user authentication, and UI components. A
robust database backend ensures reliable storage and retrieval of articles,
categories, and user roles.
The News Portal System provides a practical and interactive solution for news
management while demonstrating the application of object-oriented programming,
GUI development, and event handling in Java.

1
1.3 Java Programming Concepts

1. Object-Oriented Programming (OOP):


The News Portal System is built using Java's Object-Oriented Programming
principles, ensuring modularity, reusability, and maintainability. Represents the core
functionalities available to administrators, such as adding articles, managing
categories, and viewing published articles. It ensures encapsulation by keeping fields
like articleList and categoryList private, with controlled access through getter and
setter methods. Article Class Represents an article object with attributes such as title,
content, category, and timestamp. Private access modifiers are used to protect these
fields, with public methods (getTitle(), getCategory()) allowing controlled data
access. User View Class Handles the user-facing functionalities, providing options to
browse and search articles. It inherits certain features from a common BaseView
class, demonstrating inheritance.

2. GUI programming (Swing):

The News Portal System employs Swing, a robust library for building graphical
user interfaces in Java, to create an intuitive and responsive user experience. JButton
and ActionListener, Dynamic Components, Interactive Feedback.
3. Collection(ArrayList):

The News Portal System utilizes JAVA collection to manage and organize data
efficiently. ArrayList for article Storage ,HashMap for category management and
Efficient search through the ArrayList of articles.

4
1
CHAPTER 2
PROJECT METHODOLOGY

2.1 Proposed Work

System architecture refers to the foundational blueprint that defines the structure,
behavior, and interconnections of various components within a system. In the context
of the News Portal System, the architecture ensures seamless integration of content
management, user interaction, and data handling, enabling a robust platform for
delivering news and updates.

2.1.1 High-LevelSystemArchitecture
The high-level system architecture of the News Portal System
consists of the following primary components:

(i) UserInterface(UI)
(ii) Application Logic

2.1.2 Componentsof theSystem Architecture

a. UserInterface (UI)

The User Interface serves as the interaction point between users (admins and
viewers) and the system. Tools to create and manage articles, categorize news, and
update content. dynamic section to add or customize article categories, including
support for custom category creation.

b. ApplicationLogic

The Application Logic handles the core operations of the system, ensuring that all
functionalities work seamlessly Processing and storing articles added by
administrators. Dynamic addition and customization of categories, ensuring flexible
content organization. Role-based access, allowing administrators to manage content
and viewers to browse articles.

1
5
2.2 Block Diagram

Include a diagram that visually represents the system architecture. The diagram
should depict how each component interactswith the others. For example, it can show
the User Interface sending requests to the Application Logic, which in turn interacts
with the DataManagement Layer and the Storage Layer.

16
CHAPTER 3
MODULE DESCRIPTION

3.1 ADMIN DASHBOARD MODULE:


This module provides the administrator with a centralized interface for
managing the news portal. It allows functionalities like adding articles,
managing categories, and viewing all published content
3.2 ARTICLE MANAGEMENT MODULE

This module handles the lifecycle of articles, from creation to deletion.


It ensures data integrity and categorization. Collects inputs for article details such
as title, category, and content. Validates article input fields to ensure no empty
fields or duplicate titles.

3.3 CATEGORY MANAGEMENT MODULE

Allows administrators to manage content categories dynamically,


ensuring organized classification of articles. Create new categories or
subcategories for articles. Validate category names to avoid duplicates.
Dynamically update category dropdowns across the system.

3.4 USER LOGIN AND VIEW MODULE

This module handles user-specific access, allowing users to browse


and search articles without administrative privileges. Provides a secure login
interface for users. Restricts users to viewing access only. Offers a search bar for
users to search articles by title or category.

3.5 DATA STORAGE MODULE

This module manages the persistent storage of articles and categories


using a database or in-memory collections. Utilizes ArrayList for article
storage and HashMap for category-article mapping. Provides methods for
retrieving, updating, and deleting records.

17
CHAPTER 4
CONCLUSION & FUTURE SCOPE

4.1 CONCLUSION

In conclusion, the News Portal System demonstrates immense


potential for future advancements aimed at providing users with
a seamless and enriched experience while ensuring robust
content management. By incorporating advanced technologies
such as Artificial Intelligence (AI) and Machine Learning, the
system can enable features like personalized article
recommendations, trend analysis, and automated content
categorization. Transitioning to a cloud-based infrastructure
would enhance scalability, allowing the system to handle
increased traffic and data with ease, while ensuring remote
accessibility for both administrators and users.The
implementation of mobile applications could further enhance
user convenience, allowing access to news articles, category
management, and search functionalities on the go. Contactless
content submission and approval mechanisms can simplify
workflows for contributors and editors, fostering an efficient
editorial process. Integration with external APIs, such as social
media and real-time news feeds, would provide a broader reach
and enrich the content diversity on the platform. Enhanced
security features, such as role-based access controls and
encrypted data storage, ensure the safety of sensitive user and
content data.These enhancements would not only solidify the
News Portal System’s position as a reliable platform for news
dissemination but also pave the way for it to adapt and thrive in
a rapidly evolving digital landscape.

8
1
4.2 FUTURE SCOPE
The future scope of the News Portal System focuses on leveraging emerging
technologies to improve functionality, scalability, and user engagement.
Incorporating Artificial Intelligence (AI) can facilitate personalized article
recommendations based on user preferences and reading habits, while Machine
Learning algorithms can analyze user behavior to optimize content delivery.
Transitioning to a cloud-based platform would ensure seamless data
synchronization and accessibility for both users and administrators across
different devices and locations.Mobile application development is another area of
growth, enabling users to access articles, manage categories, and perform searches
effortlessly on their smartphones. Integration with external APIs, such as those
from social media platforms and live news feeds, can broaden the platform's
content base and improve real-time updates. The implementation of advanced
analytics tools would provide insights into user engagement, article popularity,
and emerging trends, helping administrators make data-driven decisions..

9
1
REFERENCES:

1. Anurag Gupta, IPS Jharkhand, GP Biswass, “ Java


Programming, Problem Solving, Packages and
Libraries”,McGraw Hill Education (India) Private Limited,
2019 ISBN-13:978-93-5316-800-1
2. Reema Theraja , “Java Programming: Using Problem
Solving Approach” Oxford Higher Education,2017.
3. Gowrishankar S, Veena A, “Introduction to Java
Programming”, 1st Edition, CRC Press/Taylor & Francis,
2018. ISBN-13: 978-0815394372
4.https//:w3schools.com

10 1
APPENDIX A(SOURCE CODE)

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;

public class NewsPortalSystem {


private JFrame frame;
private JPanel loginPanel, registerPanel, adminPanel, userPanel,
articleViewPanel;
private JTextField usernameField, registerUsernameField,
customCategoryField, articleTitleField;
private JPasswordField passwordField, registerPasswordField;
private JButton loginButton, registerButton, registerRedirectButton,
loginRedirectButton, logoutButton, postButton, viewArticlesButton,
deleteArticleButton;
private JTextArea articleTextArea;
private JComboBox<String> categoryComboBox;
private JCheckBox isAdminCheckBox;
private String loggedInUser ;
private boolean isAdmin;

private HashMap<String, String> userDatabase;


private HashMap<String, Boolean> adminDatabase;
private ArrayList<String> articles;
public static void main(String[] args) {
EventQueue.invokeLater(() -> {

11
try {
NewsPortalSystem window = new NewsPortalSystem();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}

public NewsPortalSystem() {
userDatabase = new HashMap<>();
adminDatabase = new HashMap<>();
articles = new ArrayList<>();
initialize();
}

private void initialize() {


frame = new JFrame("News Portal System");
frame.setBounds(100, 100, 600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initializeLoginPage();
}
private void initializeLoginPage() {
loginPanel = new JPanel();
loginPanel.setLayout(new GridBagLayout());
loginPanel.setBackground(Color.WHITE);

JLabel titleLabel = new JLabel("News Portal System");


titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color(0, 102, 204));
12
JLabel usernameLabel = new JLabel("Username:");
JLabel passwordLabel = new JLabel("Password:");

usernameField = new JTextField(15);


passwordField = new JPasswordField(15);

loginButton = new JButton("Login");


registerRedirectButton = new JButton("Don't have an account? Register -
>");

loginButton.setBackground(new Color(51, 153, 255));


loginButton.setForeground(Color.WHITE);
loginButton.setFocusPainted(false);
loginButton.setBorder(BorderFactory.createLineBorder(new Color(51,
153, 255), 2));

registerRedirectButton.setBackground(new Color(255, 69, 0));


registerRedirectButton.setForeground(Color.WHITE);
registerRedirectButton.setFocusPainted(false);
registerRedirectButton.setBorder(BorderFactory.createLineBorder(new
Color(255, 69, 0), 2));
loginButton.addActionListener(e -> handleLogin());
registerRedirectButton.addActionListener(e -> initializeRegisterPage());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);

13
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
loginPanel.add(titleLabel, gbc);

gbc.gridwidth = 1;
gbc.gridy = 1;
loginPanel.add(usernameLabel, gbc);

gbc.gridx = 1;
loginPanel.add(usernameField, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
loginPanel.add(passwordLabel, gbc);

gbc.gridx = 1;
loginPanel.add(passwordField, gbc);

gbc.gridx = 0;
gbc.gridy = 3;
loginPanel.add(loginButton, gbc);
gbc.gridx = 1;
gbc.gridy = 3;
loginPanel.add(registerRedirectButton, gbc);
frame.getContentPane().removeAll();
frame.getContentPane().add(loginPanel);
frame.revalidate();
frame.repaint();
14
}

private void initializeRegisterPage() {


registerPanel = new JPanel();
registerPanel.setLayout(new GridBagLayout());
registerPanel.setBackground(Color.WHITE);

JLabel titleLabel = new JLabel("Register");


titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color( 0, 102, 204));

JLabel usernameLabel = new JLabel("Username:");


JLabel passwordLabel = new JLabel("Password:");

registerUsernameField = new JTextField(15);


registerPasswordField = new JPasswordField(15);

registerButton = new JButton("Register");


loginRedirectButton = new JButton("Back to Login");

isAdminCheckBox = new JCheckBox("Register as Admin");

registerButton.setBackground(new Color(51, 153, 255));


registerButton.setForeground(Color.WHITE);
registerButton.setFocusPainted(false);
registerButton.setBorder(BorderFactory.createLineBorder(new Color(51,
153, 255), 2));
loginRedirectButton.setBackground(new Color(255, 69, 0));
loginRedirectButton.setForeground(Color.WHITE);
15
loginRedirectButton.setFocusPainted(false);
loginRedirectButton.setBorder(BorderFactory.createLineBorder(new
Color(255, 69, 0), 2));

registerButton.addActionListener(e -> handleRegister());


loginRedirectButton.addActionListener(e -> initializeLoginPage());

GridBagConstraints gbc = new GridBagConstraints();


gbc.insets = new Insets(10, 10, 10, 10);

gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
registerPanel.add(titleLabel, gbc);

gbc.gridwidth = 1;
gbc.gridy = 1;
registerPanel.add(usernameLabel, gbc);

gbc.gridx = 1;
registerPanel.add(registerUsernameField, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
registerPanel.add(passwordLabel, gbc);

gbc.gridx = 1;
registerPanel.add(registerPasswordField, gbc);
gbc.gridx = 0;

16 gbc.gridy = 3;
registerPanel.add(isAdminCheckBox, gbc);

gbc.gridx = 1;
registerPanel.add(registerButton, gbc);

gbc.gridx = 1;
gbc.gridy = 4;
registerPanel.add(loginRedirectButton, gbc);

frame.getContentPane().removeAll();
frame.getContentPane().add(registerPanel);
frame.revalidate();
frame.repaint();
}

private void initializeAdminPage() {


adminPanel = new JPanel();
adminPanel.setLayout(new GridBagLayout());
adminPanel.setBackground(Color.WHITE);

JLabel titleLabel = new JLabel("Admin Dashboard");


titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color(0, 102, 204));

JLabel articleTitleLabel = new JLabel("Article Title:");


articleTitleField = new JTextField(15);
JLabel categoryLabel = new JLabel("Category:");

17
categoryComboBox = new JComboBox<>(new String[]{"Politics",
"Sports", "Technology", "Other"});
customCategoryField = new JTextField(15);
customCategoryField.setVisible(false);

articleTextArea = new JTextArea(10, 40);


articleTextArea.setLineWrap(true);
articleTextArea.setWrapStyleWord(true);
articleTextArea.setBackground(Color.WHITE);

postButton = new JButton("Post Article");


postButton.setBackground(new Color(51, 153, 255));
postButton.setForeground(Color.WHITE);
postButton.setFocusPainted(false);
postButton.setBorder(BorderFactory.createLineBorder(new Color(51, 153,
255), 2));
postButton.addActionListener(e -> handlePostArticle());

viewArticlesButton = new JButton("View Articles");


viewArticlesButton.addActionListener(e -> initializeArticleView());

deleteArticleButton = new JButton("Delete Article");


deleteArticleButton.addActionListener(e -> handleDeleteArticle());

categoryComboBox.addActionListener(e -> {
if (categoryComboBox.getSelectedItem().equals("Other")) {
customCategoryField.setVisible(true);
} else {
customCategoryField.setVisible(false);
}

});
18 19
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10, 10, 10, 10);

gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
adminPanel.add(titleLabel, gbc);

gbc.gridwidth = 1;
gbc.gridy = 1;
adminPanel.add(articleTitleLabel, gbc);

gbc.gridx = 1;
adminPanel.add(articleTitleField, gbc);

gbc.gridx = 0;
gbc.gridy = 2;
adminPanel.add(categoryLabel, gbc);

gbc.gridx = 1;
adminPanel.add(categoryComboBox, gbc);

gbc.gridx = 1;
gbc.gridy = 3;
adminPanel.add(customCategoryField, gbc);
gbc.gridx = 0;
gbc.gridy = 4;

adminPanel.add(new JScrollPane(articleTextArea), gbc);


gbc.gridx = 0;
20
gbc.gridy = 5;
adminPanel.add(postButton, gbc);

gbc.gridx = 1;
adminPanel.add(viewArticlesButton, gbc);

gbc.gridx = 0;
gbc.gridy = 6;
adminPanel.add(deleteArticleButton, gbc);

logoutButton = new JButton("Logout");


logoutButton.setBackground(new Color(255, 69, 0));
logoutButton.setForeground(Color.WHITE);
logoutButton.setFocusPainted(false);
logoutButton.setBorder(BorderFactory.createLineBorder(new Color(255,
69, 0), 2));
logoutButton.addActionListener(e -> initializeLoginPage());

gbc.gridx = 1;
gbc.gridy = 7;
adminPanel.add(logoutButton, gbc);

frame.getContentPane().removeAll();
frame.getContentPane().add(adminPanel);
frame.revalidate();
frame.repaint();

private void initializeArticleView() {


articleViewPanel = new JPanel();
articleViewPanel.setLayout(new BorderLayout());
articleViewPanel.setBackground(Color.WHITE);

JLabel titleLabel = new JLabel("Articles");


titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color(0, 102, 204));

JTextArea articlesArea = new JTextArea(15, 50);


articlesArea.setEditable(false);

for (String article : articles) {


articlesArea.append(article + "\n\n");
}

JScrollPane scrollPane = new JScrollPane(articlesArea);


articleViewPanel.add(titleLabel, BorderLayout.NORTH);
articleViewPanel.add(scrollPane, BorderLayout.CENTER);

JButton backButton = new JButton("Back");


backButton.addActionListener(e -> initializeAdminPage());
articleViewPanel.add(backButton, BorderLayout.SOUTH);

frame.getContentPane().removeAll();
frame.getContentPane().add(articleViewPanel);
frame.revalidate();
21
}

private void handleLogin() {


loggedInUser = usernameField.getText();
String password = new String(passwordField.getPassword());

if (userDatabase.containsKey(loggedInUser ) &&
userDatabase.get(loggedInUser ).equals(password)) {
isAdmin = adminDatabase.getOrDefault(loggedInUser , false);
if (isAdmin) {
initializeAdminPage();
} else {
initializeUserPage();
}
} else {
JOptionPane.showMessageDialog(frame, "Invalid login credentials.");
}
}

private void handleRegister() {


String username = registerUsernameField.getText();
String password = new String(registerPasswordField.getPassword());

if (!username.isEmpty() && !password.isEmpty()) {


userDatabase.put(username, password);
if (isAdminCheckBox.isSelected()) {
adminDatabase.put(username, true);
}
JOptionPane.showMessageDialog(frame, "Registration successful!");
initializeLoginPage();

} else {
JOptionPane.showMessageDialog(frame, "Please fill in both fields.");
}
}
private void 22
23 handlePostArticle() {
String title = articleTitleField.getText();
String article = articleTextArea.getText();
String category = (String) categoryComboBox.getSelectedItem();

if (category.equals("Other")) {
category = customCategoryField.getText();
}

if (!title.isEmpty() && !article.isEmpty()) {


articles.add("Title: " + title + "\nCategory: " + category + "\n" + article);
JOptionPane.showMessageDialog(frame, "Article posted
successfully.");
articleTextArea.setText(""); // Clear article area
articleTitleField.setText(""); // Clear title field
} else {
JOptionPane.showMessageDialog(frame, "Please fill in both title and
article content.");
}
}

private void handleDeleteArticle() {


String titleToDelete = JOptionPane.showInputDialog(frame, "Enter the
title of the article to delete:");
if (titleToDelete != null && !titleToDelete.isEmpty()) {
boolean found = false;
for (int i = 0; i < articles.size(); i++) {
if (articles.get(i).startsWith("Title: " + titleToDelete)) {
articles.remove(i);
found = true;
JOptionPane.showMessageDialog(frame, "Article deleted
successfully.");
break;
}
}
if (!found) {
JOptionPane.showMessageDialog(frame, "Article not found.");
}
}

private void initializeUserPage() {


userPanel = new JPanel();
userPanel.setLayout(new BorderLayout());
userPanel.setBackground(Color.WHITE);
JLabel titleLabel = new JLabel("User Dashboard");
titleLabel.setFont(new Font("Arial", Font.BOLD, 24));
titleLabel.setForeground(new Color(0, 102, 204));

JTextArea articlesArea = new JTextArea(15, 50);


articlesArea.setEditable(false);

for (String article : articles) {


articlesArea.append(article + "\n\n");
}

JScrollPane scrollPane = new JScrollPane(articlesArea);


userPanel.add(titleLabel, BorderLayout.NORTH);
userPanel.add(scrollPane, BorderLayout.CENTER);

logoutButton = new JButton("Logout");


logoutButton.setBackground(new Color(255, 69, 0));
logoutButton.setForeground(Color.WHITE);
logoutButton.setFocusPainted(false);
logoutButton.setBorder(BorderFactory.createLineBorder(new Color(255,
69, 0), 2));
logoutButton.addActionListener(e -> initializeLoginPage());

userPanel.add(logoutButton, BorderLayout.SOUTH);

frame.getContentPane().removeAll();
frame.getContentPane().add(userPanel);
frame.revalidate();
frame.repaint();
}
}

24
APPENDIX B (SCREEN SHOT)

25
26

You might also like