// PROGRAMMER:JOHN CHAMDIMBA
// BSc.MATHEMATICAL SCIENCES EDUCATION-STATISTICS AND COMPUTING
// PROGRAM:UNIMA LIBRARY SYSTEM(c)2010
// JAVA PROGRAMMING LANGUAGE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.io.*;
import javax.swing.JOptionPane;
public class Lib4 extends JFrame implements ActionListener
{
JFrame aFrame;
JFrame bFrame;
JFrame cFrame;
JFrame dFrame;
String cName;
String dName;
String eName;
String fName;
String gName;
public static void main(String[] args)
{
new Lib4();
}
JPanel viewPanel = new JPanel();
JTextArea pub = new JTextArea(100,200);
JTextField textf1 = new JTextField(25);
JTextField textf2 = new JTextField(25);
JTextField textf3 = new JTextField(25);
JTextField textf4 = new JTextField(25);
JTextField textf5 = new JTextField(25);
JTextField textf6 = new JTextField(25);
JTextField textf7 = new JTextField(25);
ImageIcon idIcon = new ImageIcon("D:\\Picture2.png");
JButton idButton = new JButton(idIcon);
JButton clear = new JButton("Clear");
JButton exitBtton = new JButton("Exit");
JButton save = new JButton("Save");
JButton viewInfoEntered = new JButton("View Info Entered");
JButton booking = new JButton("Bookings");
JButton back = new JButton("Return Book");
JButton BviewInfoEntered = new JButton("View Info Entered");
JButton Bsave = new JButton("Save");
JButton Bclear = new JButton("Clear");
JButton Bexit = new JButton("Exit");
JButton Cclear = new JButton("ClearName In File");
JButton Ccal = new JButton("Calculate Fine");
JButton Cexit = new JButton("Exit");
JButton exitButton = new JButton("Exit");
JLabel author = new JLabel("Enter Author/s");
JLabel serialNo = new JLabel("Enter Serial No.");
JLabel book = new JLabel("Enter Book Title");
JLabel publisher = new JLabel("Enter Publisher");
JLabel dateOfArrival = new JLabel("Date of arrival");
JLabel id = new JLabel("Received by");
JLabel tittle = new JLabel("WELCOME TO UNIMA LIBRARY");
JComboBox backCo;
JComboBox dalCo;
JComboBox item;
JComboBox dur;
JComboBox due;
JComboBox progCo;
JComboBox yearCo;
public Lib4()
{ this.setTitle("UNIMA LIBRARY SYSTEM");
this.setLocation(50,50);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(true);
this.setVisible(true);
JPanel myPanel = new JPanel();
author.setFont(new Font("Algerian",Font.BOLD,22));
serialNo.setFont(new Font("Algerian",Font.BOLD,22));
book.setFont(new Font("Algerian",Font.BOLD,22));
publisher.setFont(new Font("Algerian",Font.BOLD,22));
dateOfArrival.setFont(new Font("Algerian",Font.BOLD,22));
id.setFont(new Font("Algerian",Font.BOLD,22));
tittle.setFont(new Font("Algerian",Font.BOLD,22));
textf1.setFont(new Font("Venderna",Font.BOLD,15));
textf2.setFont(new Font("Venderna",Font.BOLD,15));
textf3.setFont(new Font("Venderna",Font.BOLD,15));
textf4.setFont(new Font("Venderna",Font.BOLD,15));
textf5.setFont(new Font("Venderna",Font.BOLD,15));
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
panel2.setBackground(Color.white);
myPanel.setBackground(Color.blue);
myPanel.setLayout(new GridBagLayout());
panel3.setLayout(new BorderLayout());
viewPanel.setLayout(new BorderLayout());
textf4.setEditable(true);
panel2.add(tittle);
panel2.add(idButton);
idButton.setBackground(Color.BLUE);
idButton.setBorderPainted(false);
idButton.setContentAreaFilled(true);
clear.addActionListener(this);
exitBtton.addActionListener(this);
save.addActionListener(this);
viewInfoEntered.addActionListener(this);
booking.addActionListener(this);
back.addActionListener(this);
Bclear.addActionListener(this);
BviewInfoEntered.addActionListener(this);
Bexit .addActionListener(this);
Cclear.addActionListener(this);
Ccal.addActionListener(this);
Cexit .addActionListener(this);
exitButton .addActionListener(this);
addItem(myPanel,author, 0, 0, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf1, 1, 0, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,serialNo, 0, 1, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf2, 1, 1, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,book, 0, 2, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf3, 1, 2, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,publisher, 0, 3, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf4, 1, 3, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,dateOfArrival, 0, 4, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf5, 1, 4, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,clear, 0, 6, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,exitBtton, 1,6 , 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,save, 1, 7, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,viewInfoEntered, 0, 7, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,booking, 0, 8, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,back, 1, 8, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
save.addMouseListener (new SaveListener());
Bsave.addMouseListener (new SaveListener());
panel3.add(panel2,BorderLayout.NORTH);
panel3.add(myPanel,BorderLayout.CENTER);
this.add(panel3);
this.pack();
this.setSize(600,600);
}
public void actionPerformed(ActionEvent event)
{
JButton mybutton = (JButton)event.getSource();
if (mybutton == clear)
{
textf1.setText("");
textf2.setText("");
textf3.setText("");
textf4.setText("");
textf5.setText("");
}
else if(mybutton == exitBtton)
{
System.exit(0);
}
else if(mybutton == save)
{
}
else if(mybutton == viewInfoEntered)
{
aFrame = new JFrame();
JButton exitButton = new JButton("Exit");
ImageIcon idIcon = new ImageIcon("D:\\Picture2.png");
JButton idButtonn = new JButton(idIcon);
idButtonn.setBackground(Color.BLUE);
idButtonn.setBorderPainted(false);
JPanel myPanel = new JPanel ();
JPanel wholePanel = new JPanel ();
myPanel.setLayout(new BorderLayout(5,5));
JLabel wholeLabel = new JLabel("INFORMATION ENTERED");
addItem(wholePanel,wholeLabel, 0,0, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(wholePanel,idButtonn, 0,1, 0, 0,GridBagConstraints.WEST,GridBagConstraints.NONE);
aFrame.setTitle("UNIMA LIBRARY SYSTEM");
JTextArea myArea = new JTextArea(12,20);
myArea.setText("AUTHOR/S:\t\t"+textf1.getText()+"\n\n");
myArea.append("SERIAL NUMBER:\t"+textf2.getText()+"\n\n");
myArea.append("BOOK TITLE:\t\t"+textf3.getText()+"\n\n");
myArea.append("PUBLISHER:\t\t"+textf4.getText()+"\n\n");
myArea.append("DATE OF ARRIVAL:\t"+textf5.getText()+"\n\n");
myArea.setEditable(true);
myArea.setFont(new Font("algerian",Font.BOLD,16));
myPanel.add(myArea,BorderLayout.CENTER);
myPanel.add(wholePanel,BorderLayout.NORTH);
myPanel.add(exitButton,BorderLayout.SOUTH);
wholePanel.setBackground(Color.BLUE);
myArea.setBackground(Color.WHITE);
aFrame.setContentPane(myPanel);
aFrame.setLocation(700,200);
aFrame.setSize(700,600);
aFrame.setVisible(true);
aFrame.setResizable(true);
wholeLabel.setFont(new Font("Algerian",Font.BOLD,22));
}
else if(mybutton == booking)
{ JButton mybuttonn = (JButton)event.getSource();
bFrame = new JFrame();
bFrame.setTitle("UNIMA LIBRARY SYSTEM");
JPanel myPanel = new JPanel ();
JPanel barPanel = new JPanel ();
JPanel bothPanel=new JPanel();
JLabel barLabel = new JLabel("INFORMATION ENTERED");
barPanel.setLayout(new BorderLayout());
bothPanel.setLayout(new BorderLayout(5,5));
barPanel.add(barLabel,BorderLayout.NORTH);
bothPanel.add(barPanel,BorderLayout.NORTH);
bothPanel.add(myPanel,BorderLayout.CENTER);
myPanel.setLayout(new GridBagLayout());
myPanel.setBackground(Color.WHITE);
bFrame.setContentPane(myPanel);
bFrame.setLocation(700,200);
bFrame.setSize(700,600);
bFrame.setVisible(true);
bFrame.setResizable(true);
item= new JComboBox();
item.addItem("ShortLoan");
item.addItem("LongLoan");
item.setEditable(true);
dur=new JComboBox();
dur.addItem("1Week");
dur.addItem("2Weeks");
dur.addItem("3Weeks");
dur.addItem("4Weeks");
dur.setEditable(true);
due=new JComboBox();
due.addItem("1Week");
due.addItem("2Weeks");
due.addItem("3Weeks");
due.addItem("4Weeks");
due.setEditable(true);
progCo=new JComboBox();
progCo.addItem("MSE");
progCo.addItem("BIT");
progCo.addItem("BAC");
progCo.addItem("TED");
progCo.setEditable(true);
yearCo=new JComboBox();
yearCo.addItem("one");
yearCo.addItem("two");
yearCo.addItem("three");
yearCo.addItem("four");
yearCo.setEditable(true);
JLabel nameOfStud = new JLabel("Name of Student");
JLabel regNo = new JLabel("Registration No.");
JLabel prog = new JLabel("Program");
JLabel yearr = new JLabel("Year");
JLabel dayOfBook = new JLabel("Borrow Duration");
JLabel typeOfBook = new JLabel("Type of Booking");
JLabel duration = new JLabel("Duration");
JLabel submit = new JLabel("Submission Date");
JLabel terms = new JLabel("Terms and Conditions");
JLabel term1 = new JLabel("Late Submission:Fine of Mk100/day");
JLabel term2 = new JLabel("Lost Book:Buy new one and replace");
dayOfBook.setFont(new Font("Algerian",Font.BOLD,22));
typeOfBook.setFont(new Font("Algerian",Font.BOLD,22));
duration.setFont(new Font("Algerian",Font.BOLD,22));
submit.setFont(new Font("Algerian",Font.BOLD,22));
terms.setFont(new Font("Algerian",Font.BOLD,22));
prog.setFont(new Font("Algerian",Font.BOLD,22));
nameOfStud.setFont(new Font("Algerian",Font.BOLD,22));
regNo.setFont(new Font("Algerian",Font.BOLD,22));
yearr.setFont(new Font("Algerian",Font.BOLD,22));
addItem(myPanel,nameOfStud, 0, 0, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf6, 1, 0, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,regNo, 0, 1, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf7, 1, 1, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,prog, 0, 2, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,progCo, 1, 2, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,yearr, 0,3, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,yearCo, 1,3, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,dayOfBook, 0,4, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,dur, 1,4, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,typeOfBook, 0,5, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,item, 1,5, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,submit, 0,6, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,due, 1,6, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,terms, 0,13, 3, 3,GridBagConstraints.CENTER,GridBagConstraints.NONE);
addItem(myPanel,term1, 0,18, 3, 3,GridBagConstraints.CENTER,GridBagConstraints.NONE);
addItem(myPanel,term2, 0,25, 5, 5,GridBagConstraints.SOUTH,GridBagConstraints.NONE);
addItem(myPanel,BviewInfoEntered, 0, 30, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,Bsave, 1, 30, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,Bclear, 0, 34, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,Bexit, 1, 34, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
}
else if(mybutton == back)
{
cFrame = new JFrame();
JPanel myPanel = new JPanel ();
myPanel.setLayout(new GridBagLayout());
myPanel.setBackground(Color.WHITE);
cFrame.setTitle("UNIMA LIBRARY SYSTEM");
cFrame.setContentPane(myPanel);
cFrame.setLocation(700,200);
cFrame.setSize(500,400);
cFrame.setVisible(true);
cFrame.setResizable(true);
backCo=new JComboBox();
backCo.addItem("Yes");
backCo.addItem("No");
backCo.setEditable(true);
dalCo=new JComboBox();
dalCo.addItem("2days");
dalCo.addItem("3days");
dalCo.addItem("4days");
dalCo.addItem("5days");
dalCo.addItem("6days");
dalCo.addItem("Week");
dalCo.addItem("2Weeks");
dalCo.setEditable(true);
JLabel nameOfStud2 = new JLabel("Name of Student");
JLabel regNo2 = new JLabel("Student Registration No.");
JLabel back1 = new JLabel("Return On Time");
JLabel dalLab = new JLabel("Duration Delayed");
nameOfStud2.setFont(new Font("Algerian",Font.BOLD,15));
regNo2.setFont(new Font("Algerian",Font.BOLD,15));
back1.setFont(new Font("Algerian",Font.BOLD,15));
dalLab.setFont(new Font("Algerian",Font.BOLD,15));
JTextField textf10 = new JTextField(15);
JTextField textf11 = new JTextField(15);
addItem(myPanel,nameOfStud2, 0, 0, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf10, 1,0 , 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,regNo2, 0, 1, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,textf11, 1, 1, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,back1, 0, 2, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,backCo, 1, 2, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,dalLab, 0, 3, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
addItem(myPanel,dalCo, 1, 3, 1, 1,GridBagConstraints.WEST,GridBagConstraints.NONE);
addItem(myPanel,Cclear, 0, 4, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,Ccal, 1, 4, 1, 1,GridBagConstraints.EAST,GridBagConstraints.HORIZONTAL);
addItem(myPanel,Cexit, 0, 5, 1, 1,GridBagConstraints.EAST,GridBagConstraints.NONE);
}
else if(mybutton == BviewInfoEntered)
{
aFrame = new JFrame();
ImageIcon idIcon = new ImageIcon("D:\\Picture2.png");
JButton idButtonn = new JButton(idIcon);
idButtonn.setBackground(Color.BLUE);
idButtonn.setBorderPainted(false);
JPanel myPanel = new JPanel ();
JPanel wholePanel = new JPanel ();
myPanel.setLayout(new BorderLayout(5,5));
JLabel wholeLabel = new JLabel("INFORMATION ENTERED");
addItem(wholePanel,wholeLabel, 0,0, 1, 1,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL);
addItem(wholePanel,idButtonn, 0,1, 0, 0,GridBagConstraints.WEST,GridBagConstraints.NONE);
aFrame.setTitle("UNIMA LIBRARY SYSTEM");
JTextArea myArea = new JTextArea(12,20);
myArea.append("STUDENT NAME:"+textf6.getText()+"\t\t"+"\n\n");
myArea.append("REGISRATION NUMBER:\t"+textf7.getText()+"\n\n");
myArea.append("PROGRAM:\t\t");
myArea.append(fName+"\n\n");
myArea.append("YEAR:\t\t");
myArea.append(eName+"\n\n");
myArea.append("BORROW DURATION:\t");
myArea.append(dName+"\n\n");
myArea.append("TYPE OF BOOKING:\t");
myArea.append(cName+"\n\n");
myArea.append("SUBMISSION DATE:\t");
myArea.append(gName+"\n\n");
myArea.append("\t\t\tTERMS AND CONDITION:\t"+textf5.getText()+"\n\n");
myArea.append("\t\tLATE SUBMISSION: FINE OF MK100/DAY\t"+textf5.getText()+"\n\n");
myArea.append("\t\tLOST BOOK: BUY NEW ONE AND REPLACE\t"+textf5.getText()+"\n\n");
myArea.setEditable(true);
myArea.setFont(new Font("algerian",Font.BOLD,16));
myPanel.add(myArea,BorderLayout.CENTER);
myPanel.add(wholePanel,BorderLayout.NORTH);
myPanel.add(exitButton,BorderLayout.SOUTH);
wholePanel.setBackground(Color.BLUE);
myArea.setBackground(Color.WHITE);
aFrame.setContentPane(myPanel);
aFrame.setLocation(700,200);
aFrame.setSize(700,600);
aFrame.setVisible(true);
aFrame.setResizable(true);
wholeLabel.setFont(new Font("Algerian",Font.BOLD,22));
}
else if (mybutton == Cclear)
{ JOptionPane.showMessageDialog(null, "YOUR NAME HAS BEEN CLEARED FROM FILE");
}
else if (mybutton == Ccal)
{ JOptionPane.showMessageDialog(null, "YOUR FINE=MK200");
}
else if(mybutton == Cexit)
{
System.exit(0);
}
else if(mybutton == Bexit)
{
System.exit(0);
}
else if (mybutton == Bclear)
{
textf6.setText("");
textf7.setText("");
}
if(mybutton == exitButton)
{
System.exit(0);
}
}
private static void addItem(JPanel p, JComponent c, int x, int y, int width, int height, int align,int space)
{
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = x;
gc.gridy = y;
gc.gridwidth = width;
gc.gridheight = height;
gc.weightx = 100.0;
gc.weighty = 100.0;
gc.insets = new Insets(10, 10, 10, 10);
gc.anchor = align;
gc.fill = space;
p.add(c, gc);
}
public class SaveListener extends MouseAdapter{
public void mouseClicked(MouseEvent evnt){
saving();
}
}
public void saving(){
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showSaveDialog(this);
if(result==JFileChooser.APPROVE_OPTION){
File outFile = null;
outFile=fileChooser.getSelectedFile();
if (outFile.exists()){
JOptionPane.showMessageDialog(null, "THE FILE ARLEADY EXISTS");
}
else
try{
FileOutputStream fileStream = new FileOutputStream(outFile);
DataOutputStream dataStream = new DataOutputStream(fileStream);
dataStream.writeUTF(textf1.getText());
dataStream.writeUTF(textf2.getText());
dataStream.writeUTF(textf3.getText());
dataStream.writeUTF(textf4.getText());
dataStream.writeUTF(textf5.getText());
fileStream.close();
}
catch(IOException e){
//JOptionPane.showMessageDialog(null, "Error in Opening");
}
if(result==JFileChooser.ERROR_OPTION){
JOptionPane.showMessageDialog(null, "ERROR OCCURS IN SAVING");
}
}
}
public class CCComboListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
int pos= item.getSelectedIndex();
if(pos==0) cName="ShortLoan";
else if(pos==1) cName="LongLoan";
}
}
public class CCCComboListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
int pos= dur.getSelectedIndex();
if(pos==0) dName="1week";
else if(pos==1) dName="2weeks";
else if(pos==2) dName="3weeks";
else if(pos==3) dName="4weeks";
}
}
public class KomboListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
int pos= yearCo.getSelectedIndex();
if(pos==0) eName="one";
else if(pos==1) eName="two";
else if(pos==2) eName="three";
else if(pos==3) eName="four";
}
}
public class KKomboListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
int pos= progCo.getSelectedIndex();
if(pos==0) fName="MSE";
else if(pos==1) fName="BIT";
else if(pos==2) fName="BAC";
else if(pos==3) fName="TED";
}
}
public class KKKomboListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
int pos= due.getSelectedIndex();
if(pos==0) gName="1week";
else if(pos==1) gName="2week";
else if(pos==2) gName="3weeks";
else if(pos==3) gName="4weeks";
}
}
}