SlideShare a Scribd company logo
https://www.facebook.com/Oxus20
oxus20@gmail.com
Fal-e Hafez
(Omens of Hafez)
Cards in Persian
Using JAVA
File I/O Concept
Random Concept
Scanner Concept
Component Orientation Concept
Prepared By: Fereshteh Nourooziyan
Edited By: Abdul Rahman Sherzad
Topics
» Introduction to Hafez Omen
» File I/O Concept
» Random Concept
» Scanner Concept
» Component Orientation Concept
» Hafez Omen Implementation
2
https://www.facebook.com/Oxus20
Hafez Biography
» Khajeh Shamseddin Mohammad Hafez Shirazi
(Persian: ‫شمس‬ ‫خواجه‬‫الدین‬‫شیرازی‬ ‫حافظ‬ ‫محمد‬ ‎ )‎, known by his
pen name Hafez (‫حافظ‬ also Hafiz) was a Persian poet.
» His collected works composed of series of Persian
literature are to be found in the homes of most people
in Afghanistan and Iran who learn his poems by heart
and use them as proverbs and sayings to this day.
» His life and poems have been the subject of much
analysis, commentary and interpretation, influencing
post-fourteenth century Persian writing more than any
other author.
3
https://www.facebook.com/Oxus20
Omens of Hafez
» In the Persian tradition, whenever one faces a
difficulty or a fork in the road, or even if one
has a general question in mind, one would hold
that question in mind, and then ask the Oracle
of "Khajeh Shamseddin Mohammad Hafez-s
Shirazi" for guidance.
4
https://www.facebook.com/Oxus20
Omens of Hafez
» There are several applications which are coded
by different programming languages such as:
˃ Java languages for Desktops and Mobiles
˃ HTML and CSS and PHP for Web Pages
» that it shows the importance of Omens of Hafez
among the Persian people.
5
https://www.facebook.com/Oxus20
Omens of Hafez Interface
6
https://www.facebook.com/Oxus20
Omens of Hafez Interface
» This application is made by using Java
Language with the help of following classes:
˃ File I/O Class
˃ Random Class
˃ Scanner Class
˃ Exception Handling
7
https://www.facebook.com/Oxus20
Streams
» A stream is an object that enables the flow of
data between a program and some I/O device
or file
˃ If the data flows into a program, then the stream is called an
input stream
˃ If the data flows out of a program, then the stream is called an
output stream
https://www.facebook.com/Oxus20
8
Streams
» Input streams can flow from the keyboard or from a file
˃ System.in is an input stream that connects to the
keyboard
Scanner keyboard = new Scanner(System.in);
» Output streams can flow to a screen or to a file
˃ System.out is an output stream that connects to the
screen
System.out.println("Output stream");
https://www.facebook.com/Oxus20
9
Text Files
» Files that are designed to be read by human beings,
and that can be read or written with an editor are
called text files
˃ Text files can also be called ASCII files because the data they
contain uses an ASCII encoding scheme
˃ An advantage of text files is that the are usually the same on
all computers, so that they can move from one computer to
another
https://www.facebook.com/Oxus20
10
File and Directory Management
» In Java Language we use an object belongs to Java.io
package.
» The object is used to store the name of the file or directory
and also the pathname.
» In addition, this object can be used to create, rename, or
delete the file or directory it represents.
» Important point to remember is that java.io.File object can
represent both File and Directory in Java.
11
https://www.facebook.com/Oxus20
File Class Constructors
» The File object represents the actual file / directory on
the disk.
» There are following constructors to create a File object:
12
https://www.facebook.com/Oxus20
File(File parent, String child); // Creates a new File instance from a parent abstract pathname
and a child pathname string.
File(String pathname); // Creates a new File instance by converting the given pathname string
into an abstract pathname.
File(String parent, String child); // Creates a new File instance from a parent pathname string
and a child pathname string.
File(URI uri); // Creates a new File instance by converting the given file: URI into an abstract
pathname.
File Class Methods Summary I
13
https://www.facebook.com/Oxus20
S.N. Method & Description
1 boolean canExecute()
This method tests whether the application can execute the file denoted by this abstract pathname.
2 boolean canRead()
This method tests whether the application can read the file denoted by this abstract pathname.
3 boolean canWrite()
This method tests whether the application can modify the file denoted by this abstract pathname.
4 int compareTo(File pathname)
This method compares two abstract pathnames lexicographically.
5 boolean createNewFile()
This method atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does
not yet exist.
6 static File createTempFile(String prefix, String suffix)
This method creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its
name.
7 static File createTempFile(String prefix, String suffix, File directory)
This method Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
8 boolean delete()
This method deletes the file or directory denoted by this abstract pathname.
9 void deleteOnExit()
This method requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine
terminates.
10 boolean equals(Object obj)
This method tests this abstract pathname for equality with the given object.
File Class Methods Summary II
14
https://www.facebook.com/Oxus20
S.N. Method & Description
11 boolean exists()
This method tests whether the file or directory denoted by this abstract pathname exists..
12 File getAbsoluteFile()
This method returns the absolute form of this abstract pathname.
13 String getAbsolutePath()
This method returns the absolute pathname string of this abstract pathname.
14 File getCanonicalFile()
This method returns the canonical form of this abstract pathname.
15 String getCanonicalPath()
This method returns the canonical pathname string of this abstract pathname.
16 long getFreeSpace()
This method returns the number of unallocated bytes in the partition named by this abstract path name.
17 String getName()
This method returns the name of the file or directory denoted by this abstract pathname.
18 String getParent()
This method returns the pathname string of this abstract pathname's parent, or null if this pathname does not
name a parent directory.
19 File getParentFile()
This method returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not
name a parent directory.
48 …
File Creation Demo
15
https://www.facebook.com/Oxus20
import java.io.File;
public class FileCreationDemo {
public static void main(String[] args) {
File f = null;
boolean bool = false;
try {
// create new file
f = new File("E:FileDemomyFile.txt");
// tries to create new file in the system
bool = f.createNewFile();
// prints
System.out.println("File created: " + bool);
} catch (Exception e) {
System.err.println("Error creating the file!");
}
}
}
File Creation Output
16
https://www.facebook.com/Oxus20
Direction Creation Demo
17
https://www.facebook.com/Oxus20
import java.io.File;
public class DirectoryCreationDemo {
public static void main(String[] args) {
File file = new File("E:FileDemomyDirectory");
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
}
}
Direction Creation Output
18
https://www.facebook.com/Oxus20
File Methods Demo
import java.io.File;
public class FileMethodsDemo {
public static void main(String[] args) {
File f = new File("E:FileDemomyFile.txt");
if (f.exists()) {
System.out.println(f.getName() + " exists.");
System.out.println(f.getName() + " size is " + f.length() + " bytes");
if (f.canRead())
System.out.println(f.getName() + " can be read.");
if (f.canWrite())
System.out.println(f.getName() + " can be write.");
if (f.isFile())
System.out.println(f.getName() + " is a file.");
} else {
System.out.println(f.getName() + " does not exists!");
}
}
}
19
https://www.facebook.com/Oxus20
File Methods Output
» myFile.txt exists.
» myFile.txt size is 0 bytes
» myFile.txt can be read.
» myFile.txt can be write.
» myFile.txt is a file.
20
https://www.facebook.com/Oxus20
Introduction to Random
» java.util.Random class generates a stream of pseudo-
random numbers.
» To create a new random number generator, use one of
the following methods:
˃ new Random(); //This creates a new random number generator
˃ new Random(long seed); //This creates a new random number generator
using a single long seed
» Using of Random Class:
˃ Random class has many usages in many programs and application which need
selecting randomly without prior planning, such as:
+ Lottery Games and Applications
+ Quotes and Speech of the Day
+ Random Advertisements 21
https://www.facebook.com/Oxus20
Some Methods of Random Class
» protected int next(int bits)
˃ This method generates the next pseudorandom number.
» Boolean nextBoolean()
˃ This method returns the next pseudorandom, uniformly distributed Boolean value
from this random number generator's sequence.
» void nextBytes(byte[] bytes)
˃ This method generates random bytes and places them into a user-supplied byte
array.
» double nextDouble()
˃ This method returns the next pseudorandom, uniformly distributed double value
between 0.0 and 1.0 from this random number generator's sequence.
» loat nextFloat()
˃ This method returns the next pseudorandom, uniformly distributed float value
between 0.0 and 1.0 from this random number generator's sequence
» long nextLong()
˃ This method returns the next pseudorandom, uniformly distributed long value
from this random number generator's sequence. 22
https://www.facebook.com/Oxus20
Random Demo
import java.util.Random;
public class RandomDemo {
public static void main(String args[]) {
Random r = new Random();
int arr[] = new int[25];
for (int i = 0; i < 1000; i++) {
arr[r.nextInt(25)]++;
}
for (int i = 0; i < 25; i++) {
System.out.println(i + " was generated " + arr[i] + " times.");
}
} //end of main
} //end of class
23
https://www.facebook.com/Oxus20
Random Demo Output
24
https://www.facebook.com/Oxus20
Scanner Class
» The java.util.Scanner class is a simple text scanner
which can parse primitive types and strings using
Regular Expressions.
» Following are the important points about Scanner
class:
˃ A Scanner breaks its input into tokens using a delimiter pattern, which by default
matches whitespace (blanks, tabs, and newline).
˃ A scanning operation may block waiting for input.
˃ A Scanner is not safe for multithreaded use without external synchronization.
25
https://www.facebook.com/Oxus20
Scanner Read File Demo
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ScannerReadFileDemo {
public static void main(String[] args) {
String output = "";
Scanner in = null;
String fn = "E:FileDemomyFile.txt";
try {
in = new Scanner(new File(fn));
while (in.hasNext()) {
output += in.nextLine();
output += "n";
}
} catch (FileNotFoundException e) {
System.out.println("File does not exist !");
} finally {
in.close();
}
System.out.println(output);
}
}
26
https://www.facebook.com/Oxus20
Scanner Read File Demo Output
27
https://www.facebook.com/Oxus20
Scanner Read Keyboard Demo
import java.util.Scanner;
public class ScannerReadKeyboardDemo {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the subject:");
String subject = keyboard.nextLine();
System.out.println("Enter the score:");
double score = keyboard.nextDouble();
System.out.println("Subject: " + subject);
System.out.println("Score: " + score);
}
}
28
https://www.facebook.com/Oxus20
Scanner Read Keyboard Output
29
https://www.facebook.com/Oxus20
Introduction to ComponentOrientation
» java.awt.ComponentOrientation allows components to
encapsulate language-sensitive orientation information.
» Followings are the capability of this Class is:
˃ Vertically alignment
˃ Horizontally alignment
˃ Left-to-right
˃ Right-to-left
» Therefore, by using this class capabilities we can make and
develop multi-lingual applications in JAVA.
30
https://www.facebook.com/Oxus20
ComponentOrientation Demo
import java.awt.ComponentOrientation;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class ComponentOrintationDemo extends JFrame {
JTextArea txtArea;
public ComponentOrintationDemo() {
setTitle("Component Orintation Demo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(300, 300);
txtArea = new JTextArea();
txtArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txtArea.setFont(new Font("arial", Font.BOLD, 27));
add(txtArea);
setVisible(true);
}
public static void main(String[] args) {
new ComponentOrintationDemo();
}
}
31
https://www.facebook.com/Oxus20
ComponentOrientation Output
Lift to Right Right to Lift
32
https://www.facebook.com/Oxus20
Omens of Hafez Implementation
package OmensOfHafez;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class OmensOfHafez {
private JFrame win;
private JTextArea txtContent;
private JScrollPane scroll;
private JLabel lblCloseImage, lblCloseHover, lblBackground, lblChooser, lblBack;
private String filenames[] = { "1", "2", "3", "4", "5" }; 33
https://www.facebook.com/Oxus20
public OmensOfHafez() {
win = new JFrame();
win.setUndecorated(true);
win.setLayout(null);
win.setSize(480, 605);
win.setLocationRelativeTo(null);
lblBackground = new JLabel(new ImageIcon(getClass().getResource("Interface.PNG")));
lblCloseImage = new JLabel(new ImageIcon(getClass().getResource("btnClose.PNG")));
lblCloseHover = new JLabel(new ImageIcon(getClass().getResource("btncloseHover.PNG")));
lblBack = new JLabel(new ImageIcon(getClass().getResource("lblBack.PNG")));
win.add(lblCloseHover).setBounds(455, 0, 20, 20);
win.add(lblCloseImage).setBounds(455, 0, 20, 20);
lblBackground.add(lblBack).setBounds(0, 535, 59, 45);
lblBack.setVisible(false);
lblBack.setToolTipText("Back");
lblCloseHover.setVisible(false);
lblCloseHover.setToolTipText("Close");
txtContent = new JTextArea();
txtContent.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
txtContent.setFont(new Font("Traditional Arabic", Font.BOLD, 15));
txtContent.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txtContent.setLineWrap(true);
txtContent.setWrapStyleWord(true);
txtContent.setOpaque(false);
scroll = new JScrollPane(txtContent);
scroll.setOpaque(false);
scroll.getViewport().setOpaque(false);
scroll.setVisible(false);
lblBackground.add(scroll).setBounds(15, 57, 440, 470);
34
https://www.facebook.com/Oxus20
lblChooser = new JLabel(new ImageIcon(getClass().getResource("lblchooser.png")));
lblBackground.add(lblChooser).setBounds(275, 520, 230, 100);
MouseListener l = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.getSource() == lblCloseHover) {
System.exit(0);
} else if (e.getSource() == lblChooser) {
lblBackground.setIcon(new ImageIcon(getClass().getResource("BackroundImage.PNG")));
scroll.setVisible(true);
Random random = new Random();
int t = random.nextInt(filenames.length);
txtContent.setText(getContent(filenames[t]));
lblChooser.setVisible(false);
lblBack.setVisible(true);
// Fix the scroll area for the JTextArea
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
scroll.getVerticalScrollBar().setValue(0);
}
});
} else if (e.getSource() == lblBack) {
lblBackground.setIcon(new ImageIcon(getClass().getResource("Interface.PNG")));
scroll.setVisible(false);
lblBack.setVisible(false);
lblChooser.setVisible(true);
}
}
35
https://www.facebook.com/Oxus20
public void mouseEntered(MouseEvent e) {
if (e.getSource() == lblCloseImage) {
lblCloseHover.setVisible(true);
} else if (e.getSource() == lblBack) {
lblBack.setIcon(new ImageIcon(getClass().getResource("lblBackHover.PNG")));
}
}
public void mouseExited(MouseEvent e) {
if (e.getSource() == lblBack) {
lblBack.setIcon(new ImageIcon(getClass().getResource("lblBack.PNG")));
}
}
};
lblCloseImage.addMouseListener(l);
lblCloseImage.setCursor(new Cursor(Cursor.HAND_CURSOR));
lblCloseHover.addMouseListener(l);
lblCloseHover.setCursor(new Cursor(Cursor.HAND_CURSOR));
lblBack.addMouseListener(l);
lblBack.setCursor(new Cursor(Cursor.HAND_CURSOR));
lblChooser.addMouseListener(l);
lblChooser.setCursor(new Cursor(Cursor.HAND_CURSOR));
win.getContentPane().setBackground(Color.BLACK);
win.add(lblBackground).setBounds(5, 20, 470, 580);
win.setVisible(true);
}
36
https://www.facebook.com/Oxus20
private String getContent(Object filename) {
String output = "";
Scanner in = null;
String fn = filename.toString() + ".txt";
try {
in = new Scanner(new File(fn));
while (in.hasNext()) {
output += in.nextLine();
output += "n";
}
} catch (FileNotFoundException e) {
System.out.println(filename + ".txt does not exist !");
} finally {
in.close();
}
return output;
}
public static void main(String[] args) {
new OmensOfHafez();
}
}
37
https://www.facebook.com/Oxus20
Omens of Hafiz Output
https://www.facebook.com/Oxus20
38

More Related Content

PDF
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
PPTX
Cs1123 10 file operations
PPTX
[Java] #7 - Input & Output Stream
PPTX
Filesin c++
PPTX
pointer, structure ,union and intro to file handling
PPTX
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
PPTX
File handling in c++
PPTX
Files in php
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Cs1123 10 file operations
[Java] #7 - Input & Output Stream
Filesin c++
pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
File handling in c++
Files in php

What's hot (20)

PDF
12th computer-application-unit-8-study-material-english-medium
PPTX
basics of file handling
PPT
Files in c++ ppt
PPTX
Data file handling
PPT
File handling in C++
PPTX
File Handling in C
PPT
File handling in_c
PPT
17 files and streams
PDF
PHP file handling
PDF
Filehadnling
PPT
File Handling In C++(OOPs))
PPTX
Python files / directories part15
PDF
I/O in java Part 1
PPT
Filehandlinging cp2
DOCX
File handling in c++
PPT
Cpp file-handling
PPTX
Data file handling in c++
12th computer-application-unit-8-study-material-english-medium
basics of file handling
Files in c++ ppt
Data file handling
File handling in C++
File Handling in C
File handling in_c
17 files and streams
PHP file handling
Filehadnling
File Handling In C++(OOPs))
Python files / directories part15
I/O in java Part 1
Filehandlinging cp2
File handling in c++
Cpp file-handling
Data file handling in c++
Ad

Viewers also liked (19)

PPTX
Zacharis-presentation
PPT
Unlocking the content dungeon
PPT
Impacto de las tic en los destinos turisticos. Destinos turísticos inteligentes
PDF
CreateJS最新情報〜Adobe MAX 2013より〜 / CreateJS勉強会(第3回)発表資料
PDF
The Emotions of Packaging, Online and In-Store - DRS, 1/25/16
PDF
Dropbox: The Perfect Home for Your Stuffs
PDF
Social with SharePoint 2013
PDF
Buenasaludenel trabajo
PPTX
Universidad nacional del centro del perú
PPT
Share point saturday baltimore welcome
PPTX
Molly Smith Thompson House
PDF
Lit Mgmt Winter 2015
PPSX
Happy Halloween
PPT
SharePoint 2013 - Why, How and What? - Session #SPCon13
PDF
Designing experiences, not just features
PDF
Huellaecologica
PDF
Social media for brands.pdf
PPTX
NLA CU Cardboard Conundrum
PDF
Informática forense
Zacharis-presentation
Unlocking the content dungeon
Impacto de las tic en los destinos turisticos. Destinos turísticos inteligentes
CreateJS最新情報〜Adobe MAX 2013より〜 / CreateJS勉強会(第3回)発表資料
The Emotions of Packaging, Online and In-Store - DRS, 1/25/16
Dropbox: The Perfect Home for Your Stuffs
Social with SharePoint 2013
Buenasaludenel trabajo
Universidad nacional del centro del perú
Share point saturday baltimore welcome
Molly Smith Thompson House
Lit Mgmt Winter 2015
Happy Halloween
SharePoint 2013 - Why, How and What? - Session #SPCon13
Designing experiences, not just features
Huellaecologica
Social media for brands.pdf
NLA CU Cardboard Conundrum
Informática forense
Ad

Similar to Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java (20)

PPTX
File system node js
PPTX
Files that are designed to be read by human beings
PPTX
chapter 2(IO and stream)/chapter 2, IO and stream
PDF
Recursively Searching Files and DirectoriesSummaryBuild a class .pdf
PDF
File handling
DOCX
Php files
PPTX
FS_module_functions.pptx
DOCX
Files nts
PPTX
Input/Output Exploring java.io
PPTX
C++17 std::filesystem - Overview
PDF
My History
PPT
Chapter 5 Class File
PDF
CS215 - Lec 2 file organization
PDF
PPTX
Input output files in java
PPTX
PPTX
Module 5_Reading and Writing Files.pptx.
PDF
Java I/O Part 1
PPTX
Chap 5 php files part 1
PDF
Input File dalam C++
File system node js
Files that are designed to be read by human beings
chapter 2(IO and stream)/chapter 2, IO and stream
Recursively Searching Files and DirectoriesSummaryBuild a class .pdf
File handling
Php files
FS_module_functions.pptx
Files nts
Input/Output Exploring java.io
C++17 std::filesystem - Overview
My History
Chapter 5 Class File
CS215 - Lec 2 file organization
Input output files in java
Module 5_Reading and Writing Files.pptx.
Java I/O Part 1
Chap 5 php files part 1
Input File dalam C++

More from Abdul Rahman Sherzad (20)

PDF
Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
PDF
PHP Unicode Input Validation Snippets
PDF
Iterations and Recursions
PDF
Sorting Alpha Numeric Data in MySQL
PDF
PHP Variable variables Examples
PDF
Cross Join Example and Applications
PDF
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
PDF
Web Application Security and Awareness
PDF
Database Automation with MySQL Triggers and Event Schedulers
PDF
Mobile Score Notification System
PDF
Herat Innovation Lab 2015
PDF
Evaluation of Existing Web Structure of Afghan Universities
PDF
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PDF
Java Applet and Graphics
PDF
Fundamentals of Database Systems Questions and Answers
PDF
Everything about Database JOINS and Relationships
PDF
Create Splash Screen with Java Step by Step
PDF
Web Design and Development Life Cycle and Technologies
PDF
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
PDF
Java Unicode with Live GUI Examples
Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
PHP Unicode Input Validation Snippets
Iterations and Recursions
Sorting Alpha Numeric Data in MySQL
PHP Variable variables Examples
Cross Join Example and Applications
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Web Application Security and Awareness
Database Automation with MySQL Triggers and Event Schedulers
Mobile Score Notification System
Herat Innovation Lab 2015
Evaluation of Existing Web Structure of Afghan Universities
PHP Basic and Fundamental Questions and Answers with Detail Explanation
Java Applet and Graphics
Fundamentals of Database Systems Questions and Answers
Everything about Database JOINS and Relationships
Create Splash Screen with Java Step by Step
Web Design and Development Life Cycle and Technologies
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Unicode with Live GUI Examples

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
advance database management system book.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Trump Administration's workforce development strategy
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
1_English_Language_Set_2.pdf probationary
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Indian roads congress 037 - 2012 Flexible pavement
Final Presentation General Medicine 03-08-2024.pptx
Practical Manual AGRO-233 Principles and Practices of Natural Farming
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
advance database management system book.pdf
RMMM.pdf make it easy to upload and study
Paper A Mock Exam 9_ Attempt review.pdf.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Trump Administration's workforce development strategy
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
1_English_Language_Set_2.pdf probationary
Digestion and Absorption of Carbohydrates, Proteina and Fats
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Indian roads congress 037 - 2012 Flexible pavement

Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java

  • 1. https://www.facebook.com/Oxus20 [email protected] Fal-e Hafez (Omens of Hafez) Cards in Persian Using JAVA File I/O Concept Random Concept Scanner Concept Component Orientation Concept Prepared By: Fereshteh Nourooziyan Edited By: Abdul Rahman Sherzad
  • 2. Topics » Introduction to Hafez Omen » File I/O Concept » Random Concept » Scanner Concept » Component Orientation Concept » Hafez Omen Implementation 2 https://www.facebook.com/Oxus20
  • 3. Hafez Biography » Khajeh Shamseddin Mohammad Hafez Shirazi (Persian: ‫شمس‬ ‫خواجه‬‫الدین‬‫شیرازی‬ ‫حافظ‬ ‫محمد‬ ‎ )‎, known by his pen name Hafez (‫حافظ‬ also Hafiz) was a Persian poet. » His collected works composed of series of Persian literature are to be found in the homes of most people in Afghanistan and Iran who learn his poems by heart and use them as proverbs and sayings to this day. » His life and poems have been the subject of much analysis, commentary and interpretation, influencing post-fourteenth century Persian writing more than any other author. 3 https://www.facebook.com/Oxus20
  • 4. Omens of Hafez » In the Persian tradition, whenever one faces a difficulty or a fork in the road, or even if one has a general question in mind, one would hold that question in mind, and then ask the Oracle of "Khajeh Shamseddin Mohammad Hafez-s Shirazi" for guidance. 4 https://www.facebook.com/Oxus20
  • 5. Omens of Hafez » There are several applications which are coded by different programming languages such as: ˃ Java languages for Desktops and Mobiles ˃ HTML and CSS and PHP for Web Pages » that it shows the importance of Omens of Hafez among the Persian people. 5 https://www.facebook.com/Oxus20
  • 6. Omens of Hafez Interface 6 https://www.facebook.com/Oxus20
  • 7. Omens of Hafez Interface » This application is made by using Java Language with the help of following classes: ˃ File I/O Class ˃ Random Class ˃ Scanner Class ˃ Exception Handling 7 https://www.facebook.com/Oxus20
  • 8. Streams » A stream is an object that enables the flow of data between a program and some I/O device or file ˃ If the data flows into a program, then the stream is called an input stream ˃ If the data flows out of a program, then the stream is called an output stream https://www.facebook.com/Oxus20 8
  • 9. Streams » Input streams can flow from the keyboard or from a file ˃ System.in is an input stream that connects to the keyboard Scanner keyboard = new Scanner(System.in); » Output streams can flow to a screen or to a file ˃ System.out is an output stream that connects to the screen System.out.println("Output stream"); https://www.facebook.com/Oxus20 9
  • 10. Text Files » Files that are designed to be read by human beings, and that can be read or written with an editor are called text files ˃ Text files can also be called ASCII files because the data they contain uses an ASCII encoding scheme ˃ An advantage of text files is that the are usually the same on all computers, so that they can move from one computer to another https://www.facebook.com/Oxus20 10
  • 11. File and Directory Management » In Java Language we use an object belongs to Java.io package. » The object is used to store the name of the file or directory and also the pathname. » In addition, this object can be used to create, rename, or delete the file or directory it represents. » Important point to remember is that java.io.File object can represent both File and Directory in Java. 11 https://www.facebook.com/Oxus20
  • 12. File Class Constructors » The File object represents the actual file / directory on the disk. » There are following constructors to create a File object: 12 https://www.facebook.com/Oxus20 File(File parent, String child); // Creates a new File instance from a parent abstract pathname and a child pathname string. File(String pathname); // Creates a new File instance by converting the given pathname string into an abstract pathname. File(String parent, String child); // Creates a new File instance from a parent pathname string and a child pathname string. File(URI uri); // Creates a new File instance by converting the given file: URI into an abstract pathname.
  • 13. File Class Methods Summary I 13 https://www.facebook.com/Oxus20 S.N. Method & Description 1 boolean canExecute() This method tests whether the application can execute the file denoted by this abstract pathname. 2 boolean canRead() This method tests whether the application can read the file denoted by this abstract pathname. 3 boolean canWrite() This method tests whether the application can modify the file denoted by this abstract pathname. 4 int compareTo(File pathname) This method compares two abstract pathnames lexicographically. 5 boolean createNewFile() This method atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. 6 static File createTempFile(String prefix, String suffix) This method creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name. 7 static File createTempFile(String prefix, String suffix, File directory) This method Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. 8 boolean delete() This method deletes the file or directory denoted by this abstract pathname. 9 void deleteOnExit() This method requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. 10 boolean equals(Object obj) This method tests this abstract pathname for equality with the given object.
  • 14. File Class Methods Summary II 14 https://www.facebook.com/Oxus20 S.N. Method & Description 11 boolean exists() This method tests whether the file or directory denoted by this abstract pathname exists.. 12 File getAbsoluteFile() This method returns the absolute form of this abstract pathname. 13 String getAbsolutePath() This method returns the absolute pathname string of this abstract pathname. 14 File getCanonicalFile() This method returns the canonical form of this abstract pathname. 15 String getCanonicalPath() This method returns the canonical pathname string of this abstract pathname. 16 long getFreeSpace() This method returns the number of unallocated bytes in the partition named by this abstract path name. 17 String getName() This method returns the name of the file or directory denoted by this abstract pathname. 18 String getParent() This method returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory. 19 File getParentFile() This method returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory. 48 …
  • 15. File Creation Demo 15 https://www.facebook.com/Oxus20 import java.io.File; public class FileCreationDemo { public static void main(String[] args) { File f = null; boolean bool = false; try { // create new file f = new File("E:FileDemomyFile.txt"); // tries to create new file in the system bool = f.createNewFile(); // prints System.out.println("File created: " + bool); } catch (Exception e) { System.err.println("Error creating the file!"); } } }
  • 17. Direction Creation Demo 17 https://www.facebook.com/Oxus20 import java.io.File; public class DirectoryCreationDemo { public static void main(String[] args) { File file = new File("E:FileDemomyDirectory"); if (!file.exists()) { if (file.mkdir()) { System.out.println("Directory is created!"); } else { System.out.println("Failed to create directory!"); } } } }
  • 19. File Methods Demo import java.io.File; public class FileMethodsDemo { public static void main(String[] args) { File f = new File("E:FileDemomyFile.txt"); if (f.exists()) { System.out.println(f.getName() + " exists."); System.out.println(f.getName() + " size is " + f.length() + " bytes"); if (f.canRead()) System.out.println(f.getName() + " can be read."); if (f.canWrite()) System.out.println(f.getName() + " can be write."); if (f.isFile()) System.out.println(f.getName() + " is a file."); } else { System.out.println(f.getName() + " does not exists!"); } } } 19 https://www.facebook.com/Oxus20
  • 20. File Methods Output » myFile.txt exists. » myFile.txt size is 0 bytes » myFile.txt can be read. » myFile.txt can be write. » myFile.txt is a file. 20 https://www.facebook.com/Oxus20
  • 21. Introduction to Random » java.util.Random class generates a stream of pseudo- random numbers. » To create a new random number generator, use one of the following methods: ˃ new Random(); //This creates a new random number generator ˃ new Random(long seed); //This creates a new random number generator using a single long seed » Using of Random Class: ˃ Random class has many usages in many programs and application which need selecting randomly without prior planning, such as: + Lottery Games and Applications + Quotes and Speech of the Day + Random Advertisements 21 https://www.facebook.com/Oxus20
  • 22. Some Methods of Random Class » protected int next(int bits) ˃ This method generates the next pseudorandom number. » Boolean nextBoolean() ˃ This method returns the next pseudorandom, uniformly distributed Boolean value from this random number generator's sequence. » void nextBytes(byte[] bytes) ˃ This method generates random bytes and places them into a user-supplied byte array. » double nextDouble() ˃ This method returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence. » loat nextFloat() ˃ This method returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence » long nextLong() ˃ This method returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. 22 https://www.facebook.com/Oxus20
  • 23. Random Demo import java.util.Random; public class RandomDemo { public static void main(String args[]) { Random r = new Random(); int arr[] = new int[25]; for (int i = 0; i < 1000; i++) { arr[r.nextInt(25)]++; } for (int i = 0; i < 25; i++) { System.out.println(i + " was generated " + arr[i] + " times."); } } //end of main } //end of class 23 https://www.facebook.com/Oxus20
  • 25. Scanner Class » The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using Regular Expressions. » Following are the important points about Scanner class: ˃ A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace (blanks, tabs, and newline). ˃ A scanning operation may block waiting for input. ˃ A Scanner is not safe for multithreaded use without external synchronization. 25 https://www.facebook.com/Oxus20
  • 26. Scanner Read File Demo import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ScannerReadFileDemo { public static void main(String[] args) { String output = ""; Scanner in = null; String fn = "E:FileDemomyFile.txt"; try { in = new Scanner(new File(fn)); while (in.hasNext()) { output += in.nextLine(); output += "n"; } } catch (FileNotFoundException e) { System.out.println("File does not exist !"); } finally { in.close(); } System.out.println(output); } } 26 https://www.facebook.com/Oxus20
  • 27. Scanner Read File Demo Output 27 https://www.facebook.com/Oxus20
  • 28. Scanner Read Keyboard Demo import java.util.Scanner; public class ScannerReadKeyboardDemo { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the subject:"); String subject = keyboard.nextLine(); System.out.println("Enter the score:"); double score = keyboard.nextDouble(); System.out.println("Subject: " + subject); System.out.println("Score: " + score); } } 28 https://www.facebook.com/Oxus20
  • 29. Scanner Read Keyboard Output 29 https://www.facebook.com/Oxus20
  • 30. Introduction to ComponentOrientation » java.awt.ComponentOrientation allows components to encapsulate language-sensitive orientation information. » Followings are the capability of this Class is: ˃ Vertically alignment ˃ Horizontally alignment ˃ Left-to-right ˃ Right-to-left » Therefore, by using this class capabilities we can make and develop multi-lingual applications in JAVA. 30 https://www.facebook.com/Oxus20
  • 31. ComponentOrientation Demo import java.awt.ComponentOrientation; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JTextArea; public class ComponentOrintationDemo extends JFrame { JTextArea txtArea; public ComponentOrintationDemo() { setTitle("Component Orintation Demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setSize(300, 300); txtArea = new JTextArea(); txtArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); txtArea.setFont(new Font("arial", Font.BOLD, 27)); add(txtArea); setVisible(true); } public static void main(String[] args) { new ComponentOrintationDemo(); } } 31 https://www.facebook.com/Oxus20
  • 32. ComponentOrientation Output Lift to Right Right to Lift 32 https://www.facebook.com/Oxus20
  • 33. Omens of Hafez Implementation package OmensOfHafez; import java.awt.Color; import java.awt.ComponentOrientation; import java.awt.Cursor; import java.awt.Font; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.File; import java.io.FileNotFoundException; import java.util.Random; import java.util.Scanner; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextArea; public class OmensOfHafez { private JFrame win; private JTextArea txtContent; private JScrollPane scroll; private JLabel lblCloseImage, lblCloseHover, lblBackground, lblChooser, lblBack; private String filenames[] = { "1", "2", "3", "4", "5" }; 33 https://www.facebook.com/Oxus20
  • 34. public OmensOfHafez() { win = new JFrame(); win.setUndecorated(true); win.setLayout(null); win.setSize(480, 605); win.setLocationRelativeTo(null); lblBackground = new JLabel(new ImageIcon(getClass().getResource("Interface.PNG"))); lblCloseImage = new JLabel(new ImageIcon(getClass().getResource("btnClose.PNG"))); lblCloseHover = new JLabel(new ImageIcon(getClass().getResource("btncloseHover.PNG"))); lblBack = new JLabel(new ImageIcon(getClass().getResource("lblBack.PNG"))); win.add(lblCloseHover).setBounds(455, 0, 20, 20); win.add(lblCloseImage).setBounds(455, 0, 20, 20); lblBackground.add(lblBack).setBounds(0, 535, 59, 45); lblBack.setVisible(false); lblBack.setToolTipText("Back"); lblCloseHover.setVisible(false); lblCloseHover.setToolTipText("Close"); txtContent = new JTextArea(); txtContent.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); txtContent.setFont(new Font("Traditional Arabic", Font.BOLD, 15)); txtContent.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); txtContent.setLineWrap(true); txtContent.setWrapStyleWord(true); txtContent.setOpaque(false); scroll = new JScrollPane(txtContent); scroll.setOpaque(false); scroll.getViewport().setOpaque(false); scroll.setVisible(false); lblBackground.add(scroll).setBounds(15, 57, 440, 470); 34 https://www.facebook.com/Oxus20
  • 35. lblChooser = new JLabel(new ImageIcon(getClass().getResource("lblchooser.png"))); lblBackground.add(lblChooser).setBounds(275, 520, 230, 100); MouseListener l = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getSource() == lblCloseHover) { System.exit(0); } else if (e.getSource() == lblChooser) { lblBackground.setIcon(new ImageIcon(getClass().getResource("BackroundImage.PNG"))); scroll.setVisible(true); Random random = new Random(); int t = random.nextInt(filenames.length); txtContent.setText(getContent(filenames[t])); lblChooser.setVisible(false); lblBack.setVisible(true); // Fix the scroll area for the JTextArea javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { scroll.getVerticalScrollBar().setValue(0); } }); } else if (e.getSource() == lblBack) { lblBackground.setIcon(new ImageIcon(getClass().getResource("Interface.PNG"))); scroll.setVisible(false); lblBack.setVisible(false); lblChooser.setVisible(true); } } 35 https://www.facebook.com/Oxus20
  • 36. public void mouseEntered(MouseEvent e) { if (e.getSource() == lblCloseImage) { lblCloseHover.setVisible(true); } else if (e.getSource() == lblBack) { lblBack.setIcon(new ImageIcon(getClass().getResource("lblBackHover.PNG"))); } } public void mouseExited(MouseEvent e) { if (e.getSource() == lblBack) { lblBack.setIcon(new ImageIcon(getClass().getResource("lblBack.PNG"))); } } }; lblCloseImage.addMouseListener(l); lblCloseImage.setCursor(new Cursor(Cursor.HAND_CURSOR)); lblCloseHover.addMouseListener(l); lblCloseHover.setCursor(new Cursor(Cursor.HAND_CURSOR)); lblBack.addMouseListener(l); lblBack.setCursor(new Cursor(Cursor.HAND_CURSOR)); lblChooser.addMouseListener(l); lblChooser.setCursor(new Cursor(Cursor.HAND_CURSOR)); win.getContentPane().setBackground(Color.BLACK); win.add(lblBackground).setBounds(5, 20, 470, 580); win.setVisible(true); } 36 https://www.facebook.com/Oxus20
  • 37. private String getContent(Object filename) { String output = ""; Scanner in = null; String fn = filename.toString() + ".txt"; try { in = new Scanner(new File(fn)); while (in.hasNext()) { output += in.nextLine(); output += "n"; } } catch (FileNotFoundException e) { System.out.println(filename + ".txt does not exist !"); } finally { in.close(); } return output; } public static void main(String[] args) { new OmensOfHafez(); } } 37 https://www.facebook.com/Oxus20
  • 38. Omens of Hafiz Output https://www.facebook.com/Oxus20 38