NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Final;

import java.io.Serializable;

public class Story implements Serializable {
private final String title;
private final String author;
private final String content;

public Story(String title, String author, String content) {
this.title = title;
this.author = author;
this.content = content;
}

public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public String getContent() {
return content;
}

@Override
public String toString() {
return title;
}
}
package Final;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;


class StoryManager implements Serializable {
private List<Story> stories;
private static final String FILE_NAME = "stories.ser";

public StoryManager() throws IOException, FileNotFoundException, ClassNotFoundException {
loadStories();
}

public void addStory(Story story) throws IOException {
stories.add(story);
saveStories();
}

public List<Story> getStories() {
return stories;
}

private void saveStories() throws FileNotFoundException, IOException {
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(FILE_NAME))) {
out.writeObject(stories);
} }

private void loadStories() throws FileNotFoundException, IOException, ClassNotFoundException {
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(FILE_NAME))) {
stories = (List<Story>) in.readObject();

} }
void removeStory(Story storyToDelete) throws IOException {
stories.remove(storyToDelete);
saveStories();
}

}
package Final;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class StoryAppGUI {
private final JFrame frame;
private StoryManager storyManager;
private final PrayerTimeReminder prayerTimeReminder;

public StoryAppGUI() {
frame = new JFrame("Islamic Stories and Prayer Times App");
frame.setSize(400, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

try {
storyManager = new StoryManager();
} catch (IOException | ClassNotFoundException ex) {
JOptionPane.showMessageDialog(frame, "Error initializing StoryManager: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1); // Terminate the application if StoryManager initialization fails
}

JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0, 1, 10, 10)); // Vertical layout with some spacing
panel.setBackground(new Color(0, 153, 153)); // Cool background color

// Button to show prayer times
JButton showPrayerTimesButton = new JButton("Show Prayer Times");
panel.add(showPrayerTimesButton);

// Button to set reminders for prayer times
JButton setRemindersButton = new JButton("Set Reminders");
panel.add(setRemindersButton);

// Button to add a new story
JButton addButton = new JButton("Add New Story");
panel.add(addButton);

// Button to delete a story
JButton deleteButton = new JButton("Delete Story");
panel.add(deleteButton);

// Button to show stored stories
JButton showStoriesButton = new JButton("Show Stored Stories");
panel.add(showStoriesButton);

frame.add(panel);
frame.setVisible(true);

// Initialize PrayerTimeReminder and add button functionality
JTextArea prayerTextArea = new JTextArea();
prayerTimeReminder = new PrayerTimeReminder(prayerTextArea);

showPrayerTimesButton.addActionListener((ActionEvent e) -> {
prayerTimeReminder.showPrayerTimes();
JOptionPane.showMessageDialog(frame, prayerTextArea.getText(), "Prayer Times", JOptionPane.INFORMATION_MESSAGE);
});

setRemindersButton.addActionListener((ActionEvent e) -> {
prayerTimeReminder.setReminders();
});

addButton.addActionListener((ActionEvent e) -> {
try {
addNewStory();
} catch (IOException ex) {
JOptionPane.showMessageDialog(frame, "Error adding new story: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
});

deleteButton.addActionListener((ActionEvent e) -> {
try {
deleteSelectedStory();
} catch (IOException ex) {
Logger.getLogger(StoryAppGUI.class.getName()).log(Level.SEVERE, null, ex);
}
});

showStoriesButton.addActionListener((ActionEvent e) -> {
showStoredStories();
});
}

private void addNewStory() throws IOException {
String title = JOptionPane.showInputDialog(frame, "Enter Title:");
String author = JOptionPane.showInputDialog(frame, "Enter Author:");
String content = JOptionPane.showInputDialog(frame, "Enter Content:");

if (title != null && author != null && content != null && !title.isEmpty() && !author.isEmpty() && !content.isEmpty()) {
Story newStory = new Story(title, author, content);
storyManager.addStory(newStory);
JOptionPane.showMessageDialog(frame, "Story added successfully.");
} else {
JOptionPane.showMessageDialog(frame, "Please fill in all fields.", "Error", JOptionPane.ERROR_MESSAGE);
}
}

private void deleteSelectedStory() throws IOException {
String title = JOptionPane.showInputDialog(frame, "Enter Title of the Story to Delete:");
if (title != null && !title.isEmpty()) {
Story storyToDelete = null;
for (Story story : storyManager.getStories()) {
if (story.getTitle().equals(title)) {
storyToDelete = story;
break;
}
}
if (storyToDelete != null) {
storyManager.removeStory(storyToDelete);
JOptionPane.showMessageDialog(frame, "Story deleted successfully.");
} else {
JOptionPane.showMessageDialog(frame, "Story not found.", "Error", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(frame, "Please enter a title.", "Error", JOptionPane.ERROR_MESSAGE);
}
}

private void showStoredStories() {
JFrame storiesFrame = new JFrame("Stored Stories");
storiesFrame.setSize(400, 600);
storiesFrame.setLayout(new GridLayout(0, 1, 10, 10));
storiesFrame.setBackground(new Color(0, 153, 153));

List<Story> stories = storyManager.getStories();
for (Story story : stories) {
JButton storyButton = new JButton(story.getTitle());
storyButton.addActionListener((ActionEvent e) -> {
showStoryInNewFrame(story.getTitle(), story.getAuthor(), story.getContent());
});
storiesFrame.add(storyButton);
}

storiesFrame.setVisible(true);
}

private void showStoryInNewFrame(String title, String author, String content) {
JFrame storyDisplayFrame = new JFrame("Story: " + title);
storyDisplayFrame.setSize(400, 300);
storyDisplayFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(new Color(0, 0, 51)); // Dark melody background

JLabel authorLabel = new JLabel("Author: " + author);
authorLabel.setForeground(Color.WHITE); // White text color for author label
authorLabel.setFont(new Font("SansSerif", Font.BOLD, 12)); // Bold sans-serif font for author label
authorLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); // Add padding
panel.add(authorLabel, BorderLayout.NORTH);

JTextArea storyText = new JTextArea(content);
storyText.setEditable(false);
storyText.setBackground(new Color(25, 25, 112)); // Dark blue text area background
storyText.setForeground(Color.WHITE); // White text color
storyText.setFont(new Font("Serif", Font.BOLD, 14)); // Bold serif font
storyText.setBorder(BorderFactory.createLineBorder(Color.WHITE)); // White border

// Adjusting JTextArea properties for top-to-bottom display
storyText.setLineWrap(true);
storyText.setWrapStyleWord(true);

JScrollPane scrollPane = new JScrollPane(storyText);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

panel.add(scrollPane, BorderLayout.CENTER);

storyDisplayFrame.add(panel);
storyDisplayFrame.setVisible(true);
}

public static void main(String[] args) {
SwingUtilities.invokeLater(StoryAppGUI::new);
}
}
package Final;

import java.time.LocalTime;

public class PrayerTime {
private final PrayerType type;
private final LocalTime time;

public PrayerTime(PrayerType type, LocalTime time) {
this.type = type;
this.time = time;
}

public PrayerType getType() {
return type;
}

public LocalTime getTime() {
return time;
}

@Override
public String toString() {
return type.getName() + " at " + time;
}
}
package Final;

public enum PrayerType {
FAJR("Fajr"),
DHUHR("Dhuhr"),
ASR("Asr"),
MAGHRIB("Maghrib"),
ISHA("Isha");

private final String name;

PrayerType(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
package Final;

import javax.swing.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class PrayerTimeReminder {
private final List<PrayerTime> prayerTimes;
private final JTextArea textArea;

public PrayerTimeReminder(JTextArea textArea) {
this.prayerTimes = new ArrayList<>();
this.textArea = textArea;
loadPrayerTimes();
}

private void loadPrayerTimes() {
prayerTimes.add(new PrayerTime(PrayerType.FAJR, LocalTime.of(5, 0)));
prayerTimes.add(new PrayerTime(PrayerType.DHUHR, LocalTime.of(13, 23)));
prayerTimes.add(new PrayerTime(PrayerType.ASR, LocalTime.of(16, 30)));
prayerTimes.add(new PrayerTime(PrayerType.MAGHRIB, LocalTime.of(19, 45)));
prayerTimes.add(new PrayerTime(PrayerType.ISHA, LocalTime.of(20, 0)));
}

public void showPrayerTimes() {
StringBuilder sb = new StringBuilder();
sb.append("Today's Prayer Times:n");
for (PrayerTime prayer : prayerTimes) {
sb.append(prayer).append("n");
}
textArea.setText(sb.toString());
}

public void setReminders() {
Timer timer = new Timer();
for (PrayerTime prayer : prayerTimes) {
LocalTime now = LocalTime.now();
long delay = java.time.Duration.between(now, prayer.getTime()).toMillis();
if (delay > 0) {
timer.schedule(new TimerTask() {
@Override
public void run() {
showReminder(prayer.getType().getName());
playAlarm();
}
}, delay);
}
}
JOptionPane.showMessageDialog(null, "Reminders set.");
}

private void showReminder(String prayerName) {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null, "Reminder: It's time for " + prayerName + " prayer.");
});
}

private void playAlarm() {
try {
FileInputStream fileInputStream = new FileInputStream("C:\Users\Kazi\Desktop\azan2.mp3");
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
Player player = new Player(bufferedInputStream);
player.play();
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Error playing the alarm sound.");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error playing the alarm sound.");
}
}
}

package Final;

import javax.swing.*;

public class MainApp {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new StoryAppGUI());
}
}

##
Project Description: Islamic Stories and Prayer Times Application
Overview
The Islamic Stories and Prayer Times Application is a Java Swing-based desktop application designed to provide users with access to Islamic stories and help them track prayer times with reminders. The application features an intuitive graphical user interface (GUI) for managing stories and viewing prayer times.

Features
Story Management

Add New Stories: Users can add stories by providing a title, author, and content.
View Stored Stories: Displays a list of stored stories. Clicking a story title shows its full content.
Delete Stories: Allows users to delete stories by title.
Prayer Time Management

Display Prayer Times: Shows the current day's prayer times for Fajr, Dhuhr, Asr, Maghrib, and Isha.
Set Prayer Reminders: Sets notifications for prayer times with an alarm sound.
User Interface

Main Window: Buttons for viewing prayer times, setting reminders, adding, deleting, and viewing stories.
Story Details Window: Displays story details in a reader-friendly format.
Prayer Time Display: Text area for showing prayer times with a notification system.
Technical Details
Programming Language: Java
GUI Framework: Swing
Serialization: Saves and loads stories using Java serialization (stories.ser).
Prayer Time Management: Uses predefined prayer times and Java’s Timer for reminders.
Audio Playback: Uses JLayer library for MP3 playback of the alarm sound.
Classes and Their Responsibilities
Story (Final.Story)

Represents a story with a title, author, and content. Implements Serializable.
StoryManager (Final.StoryManager)

Manages the collection of stories and handles their persistence using serialization.
StoryAppGUI (Final.StoryAppGUI)

Provides the GUI for the application, allowing interaction with stories and prayer times.
PrayerTime (Final.PrayerTime)

Represents a prayer time with a type and specific time.
PrayerType (Final.PrayerType)

Enum for different types of prayers.
PrayerTimeReminder (Final.PrayerTimeReminder)

Manages prayer times and sets reminders with notifications and alarm sounds.
MainApp (Final.MainApp)

Entry point of the application, launching the GUI.
Usage
Running the Application

Compile and run Final.MainApp.
The main window will appear with buttons to interact with the application.
Adding a New Story

Click "Add New Story", fill in the details, and confirm.
Viewing Stored Stories

Click "Show Stored Stories" to view a list of stories. Click a title to see details.
Deleting a Story

Click "Delete Story", enter the title, and confirm deletion.
Displaying Prayer Times

Click "Show Prayer Times" to display the prayer times.
Setting Prayer Reminders

Click "Set Reminders" to activate prayer time notifications.
This application provides a practical way for users to read Islamic stories and keep track of daily prayer times with reminders.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.