0% found this document useful (0 votes)
22 views11 pages

Lab#9 Mesongco

This document contains the code for a Java library management system. It includes classes and methods for a login frame, registration frame, adding and searching for books. It allows users to login, register, add books to the system, and search for books by title.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views11 pages

Lab#9 Mesongco

This document contains the code for a Java library management system. It includes classes and methods for a login frame, registration frame, adding and searching for books. It allows users to login, register, add books to the system, and search for books by title.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Sandra Mesongco

DICT 12M2

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class LOA_LIB implements ActionListener

private JFrame f, fe, af;

private JPanel afmp, afp1, afp2, afp3, afp4, afp5;

private JPanel mp,p1,p2,p3,p4,mnpl,pl1,pl2,pl3,pl4,pl5;

private JLabel labun,labpw, llS,llL,llW,lly;

private JLabel afl1, afl2, afl3, afl4;

private JTextField tfldun, td;

private JTextField aftf1, aftf2, aftf3, aftf4;

private JButton bnlog,bncan,bnreg,bab,brgb,brwb,retb,vbavial,vbrwb,logout;

private JButton afback, afadd, afbs;

private JPasswordField tfpass;

String regUN[]=new String[5];

String regPW[]=new String[5];

String name[]=new String[5];

String position[]=new String[5];

String bktitle[]=new String[5];

String bkauthor[]=new String[5];

int found=0;
String logUN="", logPW="", ne="", pn="", bname="", author="";

public static void main(String [] args)

new LOA_LIB();

public LOA_LIB()

f=new JFrame("Login");

p1=new JPanel();

p2=new JPanel();

p3=new JPanel();

p4=new JPanel();

mp=new JPanel();

labun=new JLabel("Username");

labpw=new JLabel("Password");

tfpass=new JPasswordField(10);

tfldun=new JPasswordField(10);

bnlog=new JButton("Login");

bnlog.addActionListener(this);

bncan=new JButton("Cancel");

bncan.addActionListener(this);

bnreg=new JButton("Register");

bnreg.addActionListener(this);

p1.setLayout(new GridLayout(1,2));

p1.add(labun);

p1.add(tfldun);

p2.setLayout(new GridLayout(1,2));
p2.add(labpw);

p2.add(tfpass);

p3.setLayout(new GridLayout(1,2));

p3.add(bnlog);

p3.add(bncan);

p4.setLayout(new GridLayout(1,1));

p4.add(bnreg);

mp.setLayout(new GridLayout(4,1));

mp.add(p1);

mp.add(p2);

mp.add(p3);

mp.add(p4);

f.setContentPane(mp);

f.show();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

f.setSize(300,300);

f.setResizable(true);

public void actionPerformed(ActionEvent ae)

int s=0;

if(ae.getSource()==bnreg)

JOptionPane.showMessageDialog(null,"Registration of Account!");

regUN[s]=JOptionPane.showInputDialog(null,"Enter Username");
regPW[s]=JOptionPane.showInputDialog(null,"Enter Password");

name[s]=JOptionPane.showInputDialog(null,"Enter your name");

position[s]=JOptionPane.showInputDialog(null,"Enter your position");

s++;

JOptionPane.showMessageDialog(null,"Successfully Registered Account!");

if(ae.getSource()==bncan)

tfldun.setText("");

tfpass.setText("");

int c=0;

if(ae.getSource()==brgb)

bktitle[c]=JOptionPane.showInputDialog(null,"Enter Book Title");

bkauthor[c]=JOptionPane.showInputDialog(null,"Enter Book Author");

c++;

JOptionPane.showMessageDialog(null,"Your book has been successfully


registered!");

if(ae.getSource()==afbs)

int go=0;

String get=aftf1.getText();

for(int i=0; i<5; i++)

if(get.equals(bktitle[i]))

{
go=1;

bname=bktitle[i];

author=bkauthor[i];

i=i+5;

if(go==1)

aftf2.setText(""+bname);

aftf3.setText(""+author);

else

JOptionPane.showMessageDialog(null,"Book Not Found!");

if(ae.getSource()==afback)

fe.show();

af.hide();

if(ae.getSource()==bab)

fe.hide();

af=new JFrame("Add Book:");

afmp=new JPanel();
afp1=new JPanel();

afp2=new JPanel();

afp3=new JPanel();

afp4=new JPanel();

afp5=new JPanel();

afl1=new JLabel("Enter Book Title to Begin Search");

afl2=new JLabel("Book Title:");

afl3=new JLabel("Book Author:");

afl4=new JLabel("Number of Books to be Added:");

aftf1=new JTextField(10);

aftf2=new JTextField(10);

aftf3=new JTextField(10);

aftf4=new JTextField(10);

afbs=new JButton("Search Now");

afbs.addActionListener(this);

afadd=new JButton("Add");

afadd.addActionListener(this);

afback=new JButton("Go Back");

afback.addActionListener(this);

afp1.setLayout(new GridLayout(1,2));

afp1.add(afl1);

afp1.add(aftf1);

afp2.setLayout(new GridLayout(1,2));

afp2.add(afl2);
afp2.add(aftf2);

afp3.setLayout(new GridLayout(1,2));

afp3.add(afl3);

afp3.add(aftf3);

afp4.setLayout(new GridLayout(1,2));

afp4.add(afl4);

afp4.add(aftf4);

afp5.setLayout(new GridLayout(1,3));

afp5.add(afbs);

afp5.add(afadd);

afp5.add(afback);

afmp.setLayout(new GridLayout(5,1));

afmp.add(afp1);

afmp.add(afp2);

afmp.add(afp3);

afmp.add(afp4);

afmp.add(afp5);

af.setContentPane(afmp);

af.setSize(400,400);

af.show();

af.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

af.setResizable(true);

}
if(ae.getSource()==afadd)

JOptionPane.showMessageDialog(null,"Books added!");

if(ae.getSource()==bnlog)

logUN=tfldun.getText();

logPW=tfpass.getText();

for(int m=0;m<5;m++)

if(logUN.equalsIgnoreCase(regUN[m])&&logPW.equalsIgnoreCase(regPW[m]));

found=1;

ne=name[m];

pn=position[m];

m=m+5;

if(found==1)

JOptionPane.showMessageDialog(null,"Sucessfully logged-in!");

f.hide();

fe=new JFrame("Login");

pl1=new JPanel();

pl2=new JPanel();

pl3=new JPanel();
pl4=new JPanel();

pl5=new JPanel();

mnpl=new JPanel();

llS=new JLabel("LYCEUM OF ALABANG");

llL=new JLabel("Library System");

llW=new JLabel("Welcome , "+ne);

lly=new JLabel("You're logged-in as: "+pn);

brgb=new JButton("Register Book");

brgb.addActionListener(this);

bab=new JButton("Add Book");

bab.addActionListener(this);

brwb=new JButton("Borrow Book");

retb=new JButton("Return Book");

vbavial=new JButton("View Book Available");

vbrwb=new JButton("View Borrowed Book");

logout=new JButton("LOGOUT");

logout.addActionListener(this);

pl1.setLayout(new GridLayout(1,3));

pl1.add(llS);

pl1.add(llL);

pl1.add(logout);

pl2.setLayout(new GridLayout(1,2));

pl2.add(llW);

pl2.add(lly);

pl3.setLayout(new GridLayout(1,4));

pl3.add(brgb);
pl3.add(bab);

pl3.add(brwb);

pl3.add(retb);

pl4.setLayout(new GridLayout(1,1));

pl4.add(vbavial);

pl5.setLayout(new GridLayout(1,1));

pl5.add(vbrwb);

mnpl.setLayout(new GridLayout(5,1));

mnpl.add(pl1);

mnpl.add(pl2);

mnpl.add(pl3);

mnpl.add(pl4);

mnpl.add(pl5);

fe.setContentPane(mnpl);

fe.show();

fe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

fe.setSize(400,400);

fe.setResizable(true);

else

JOptionPane.showMessageDialog(null,"Invalid Username or Password");

if(ae.getSource()==logout)

fe.hide();
f.show();

You might also like