Skip to content

Commit

Permalink
Completed Project
Browse files Browse the repository at this point in the history
  • Loading branch information
redisitic committed Oct 24, 2023
1 parent 897c6c7 commit 869052e
Show file tree
Hide file tree
Showing 31 changed files with 390 additions and 53 deletions.
Binary file modified bin/AddBook.class
Binary file not shown.
Binary file added bin/AddBookFailure.class
Binary file not shown.
Binary file added bin/AddBookSuccess.class
Binary file not shown.
Binary file modified bin/App.class
Binary file not shown.
Binary file modified bin/Authenticate.class
Binary file not shown.
Binary file modified bin/Dashboard.class
Binary file not shown.
Binary file added bin/IssueFailure.class
Binary file not shown.
Binary file added bin/IssueSuccess.class
Binary file not shown.
Binary file modified bin/Library.class
Binary file not shown.
Binary file modified bin/Login.class
Binary file not shown.
Binary file added bin/ReturnSuccess.class
Binary file not shown.
Binary file added bin/SearchBook.class
Binary file not shown.
Binary file added bin/SearchBookFailure.class
Binary file not shown.
Binary file added bin/ShowBook.class
Binary file not shown.
Binary file modified bin/TreeNode.class
Binary file not shown.
25 changes: 19 additions & 6 deletions src/AddBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.awt.event.*;

public class AddBook extends JFrame implements ActionListener {
Library lib = Library.getInstance();
JButton backDash;
JButton add;
TextField title;
TextField author;
TextField quantity;
TextField description;

AddBook(){
super("Dashboard");
setLayout(new GridLayout(5,2,8,8));
Expand Down Expand Up @@ -66,16 +67,28 @@ public void actionPerformed(ActionEvent e) {
dispose();
}
if(e.getSource() == add){
if(title.getText().equals("") || author.getText().equals("") || quantity.getText().equals("") || description.getText().equals("")){
new AddBookFailure();
return;
}
String title = this.title.getText();
String author = this.author.getText();
try{
Integer.parseInt(this.quantity.getText());
}catch(NumberFormatException nfe){
new AddBookFailure();
this.quantity.setText("");
return;
}
int quantity = Integer.parseInt(this.quantity.getText());
String description = this.description.getText();
Book book = new Book(title, author, quantity, description);
new Dashboard();
dispose();
lib.insert(book);
new AddBookSuccess();
this.title.setText("");
this.author.setText("");
this.quantity.setText("");
this.description.setText("");
}
}
public static void main(String[] args) {
new AddBook();
}
}
34 changes: 34 additions & 0 deletions src/AddBookFailure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class AddBookFailure extends JFrame implements ActionListener{
JButton okButton;
public AddBookFailure(){
super("Failure to add book");
setLayout(new GridLayout(2,1,8,8));
setSize(300, 600);
Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);

JLabel failLabel = new JLabel("Please fill all the fields correctly");
failLabel.setFont(fontRegular);

okButton = new JButton("OK");
okButton.addActionListener(this);
okButton.setFont(fontRegular);

add(failLabel);
add(okButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == okButton){
dispose();
}
}

}
33 changes: 33 additions & 0 deletions src/AddBookSuccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class AddBookSuccess extends JFrame implements ActionListener{
JButton okButton;
public AddBookSuccess(){
super("Success");
setLayout(new GridLayout(2,1,8,8));
setSize(300, 600);
Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);

JLabel failLabel = new JLabel("Book added successfully");
failLabel.setFont(fontRegular);

okButton = new JButton("OK");
okButton.addActionListener(this);
okButton.setFont(fontRegular);

add(failLabel);
add(okButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == okButton){
dispose();
}
}
}
5 changes: 2 additions & 3 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public class App {
public static Library lib = new Library();
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
new Login();
}
}
}
8 changes: 4 additions & 4 deletions src/Authenticate.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import java.util.HashMap;
import java.util.*;
public class Authenticate {
HashMap<String, String> userDatabase = new HashMap<>();

boolean Check(String enteredUsername, String enteredPassword) {
userDatabase.put("rhythm", "077");
userDatabase.put("zayaan", "058");
userDatabase.put("nilansh", "069");
userDatabase.put("Rhythm", "077");
userDatabase.put("Zayaan", "058");
userDatabase.put("Nilansh", "069");

if (userDatabase.containsKey(enteredUsername)) {
String storedPassword = userDatabase.get(enteredUsername);
Expand Down
21 changes: 14 additions & 7 deletions src/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ public class Dashboard extends JFrame implements ActionListener {
JLabel welcomeLabel;
JButton addBook;
JButton searchBook;
JButton issueBook;
JButton returnBook;
JButton logOutButton;

public Dashboard() {
super("Dashboard");
Expand All @@ -22,14 +21,14 @@ public Dashboard() {
searchBook = new JButton("Search Book");
searchBook.addActionListener(this);
searchBook.setFont(new Font("Segoe UI", Font.PLAIN, 20));
issueBook = new JButton("Issue Book");
issueBook.setFont(new Font("Segoe UI", Font.PLAIN, 20));
issueBook.addActionListener(this);
logOutButton = new JButton("Log Out");
logOutButton.addActionListener(this);
logOutButton.setFont(new Font("Segoe UI", Font.PLAIN, 20));

add(welcomeLabel);
add(addBook);
add(searchBook);
add(issueBook);
add(logOutButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
Expand All @@ -42,5 +41,13 @@ public void actionPerformed(ActionEvent e) {
new AddBook();
dispose();
}
if (e.getSource() == searchBook) {
new SearchBook();
dispose();
}
if(e.getSource() == logOutButton){
new Login();
dispose();
}
}
}
}
33 changes: 33 additions & 0 deletions src/IssueFailure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class IssueFailure extends JFrame implements ActionListener{
JButton okButton;
public IssueFailure(){
super("Failure to issue book");
setLayout(new GridLayout(2,1,8,8));
setSize(300, 600);
Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);

JLabel failLabel = new JLabel("Book not available");
failLabel.setFont(fontRegular);

okButton = new JButton("OK");
okButton.addActionListener(this);
okButton.setFont(fontRegular);

add(failLabel);
add(okButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == okButton){
dispose();
}
}
}
33 changes: 33 additions & 0 deletions src/IssueSuccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class IssueSuccess extends JFrame implements ActionListener{
JButton okButton;
public IssueSuccess(){
super("Success");
setLayout(new GridLayout(2,1,8,8));
setSize(300, 600);
Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);

JLabel failLabel = new JLabel("Book issued successfully");
failLabel.setFont(fontRegular);

okButton = new JButton("OK");
okButton.addActionListener(this);
okButton.setFont(fontRegular);

add(failLabel);
add(okButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == okButton){
dispose();
}
}
}
13 changes: 10 additions & 3 deletions src/Library.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import java.io.*;
public class Library implements Serializable {
public class Library{
private static Library instance;
private TreeNode root;

public Library() {
private Library() {
root = null;
}

public static Library getInstance() {
if (instance == null) {
instance = new Library();
}
return instance;
}

public void insert(Book book) {
root = insertNode(root, book);
}
Expand Down
34 changes: 8 additions & 26 deletions src/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ public class Login extends JFrame implements ActionListener {
public static String username;
JButton loginButton1;
JButton loginButton2;
JButton quitButton;
JTextField userText;
JTextField passText;
JTextField adminText;
JTextField pass2Text;
public Login(){
super("Login");
setLayout(new GridLayout(3,1,8,8));
setLayout(new GridLayout(4,1,8,8));
setSize(400, 300);

Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);
Expand Down Expand Up @@ -44,24 +43,14 @@ public Login(){
loginButton1.setFont(fontRegular);
loginButton1.addActionListener(this);

JPanel loginPanel2 = new JPanel();
loginPanel2.setLayout(new GridLayout(2, 2, 8, 8));
JLabel adminLabel = new JLabel("Username: ");
adminLabel.setFont(fontRegular);
adminText = new JTextField("");
adminText.setFont(fontRegular);
JLabel pass2Label = new JLabel("Password: ");
pass2Label.setFont(fontRegular);
pass2Text = new JTextField("");
pass2Text.setFont(fontRegular);

loginButton2 = new JButton("Login");
loginButton2.addActionListener(this);
loginButton2.setFont(fontRegular);
quitButton = new JButton("Quit");
quitButton.addActionListener(this);
quitButton.setFont(fontRegular);

add(titlePanel1);
add(loginPanel1);
add(loginButton1);
add(quitButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
Expand Down Expand Up @@ -91,15 +80,8 @@ public void actionPerformed(ActionEvent e) {
new LoginFailure();
}
}
if(e.getSource() == loginButton2){
try{
@SuppressWarnings("unused")
String user = adminText.getText();
@SuppressWarnings("unused")
String pass = passText.getText();
}catch(NullPointerException npe){
new LoginFailure();
}
if(e.getSource() == quitButton){
dispose();
}
}
}
2 changes: 1 addition & 1 deletion src/LoginFailure.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public void actionPerformed(ActionEvent e){
}
}

}
}
33 changes: 33 additions & 0 deletions src/ReturnSuccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ReturnSuccess extends JFrame implements ActionListener{
JButton okButton;
public ReturnSuccess(){
super("Success");
setLayout(new GridLayout(2,1,8,8));
setSize(300, 600);
Font fontRegular = new Font("Segoe UI", Font.PLAIN, 20);

JLabel failLabel = new JLabel("Book returned successfully");
failLabel.setFont(fontRegular);

okButton = new JButton("OK");
okButton.addActionListener(this);
okButton.setFont(fontRegular);

add(failLabel);
add(okButton);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setResizable(true);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == okButton){
dispose();
}
}
}
Loading

0 comments on commit 869052e

Please sign in to comment.