Lab#9 Mesongco
Lab#9 Mesongco
DICT 12M2
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
int found=0;
String logUN="", logPW="", ne="", pn="", bname="", author="";
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);
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");
s++;
if(ae.getSource()==bncan)
tfldun.setText("");
tfpass.setText("");
int c=0;
if(ae.getSource()==brgb)
c++;
if(ae.getSource()==afbs)
int go=0;
String get=aftf1.getText();
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
if(ae.getSource()==afback)
fe.show();
af.hide();
if(ae.getSource()==bab)
fe.hide();
afmp=new JPanel();
afp1=new JPanel();
afp2=new JPanel();
afp3=new JPanel();
afp4=new JPanel();
afp5=new JPanel();
aftf1=new JTextField(10);
aftf2=new JTextField(10);
aftf3=new JTextField(10);
aftf4=new JTextField(10);
afbs.addActionListener(this);
afadd=new JButton("Add");
afadd.addActionListener(this);
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();
brgb.addActionListener(this);
bab.addActionListener(this);
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
if(ae.getSource()==logout)
fe.hide();
f.show();