Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


viji
java
1 Answer(s)      4 years and 2 months ago
Posted in : Development process


1.Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.
2.Develop multi-threaded echo server and a corresponding GUI client in Java.reply me sir

Advertisement
View Answers

September 12, 2010 at 10:25 PM


// OPAC system for Library program by WHITMAN KUMARESH for my sister DHANA

// And dedicated to my java Professor. Bhuvaneshwari mam

// Any queries -> kumareshwhitman@gmail.com

// Five programs and one database, main program is Library.java

// Any doubt in configuring database then mail me.

FIRST PROGRAM


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;

public class Library extends JFrame implements ActionListener {

JTextField bId, bName, bAuth, bpub;
JTextField Isbn, qt;
JList blst;

JButton Member;
JButton NewMem;
JButton Books;
JButton NewBook;
JButton Exit;

JMenu fMenu;
JMenu hMenu;
JMenuItem hMen, abt;
JMenuItem eMen;
JMenuBar menuBar;
JButton BooksEntry;
String memName, Address, Desig;
int memId;
String bookName, Author, publisher;
int ISBN, qty;
Container cont;
JPanel memp, butmainp, bookp, butbookp;

Library() {

cont = getContentPane();
menuBar = new JMenuBar();

fMenu = new JMenu("File");
hMen = new JMenuItem("Help", KeyEvent.VK_F1);
hMen.addActionListener(this);
fMenu.add(hMen);

hMenu = new JMenu("Library");
abt = new JMenuItem("About");
eMen = new JMenuItem("Exit", KeyEvent.VK_E);
abt.addActionListener(this);
eMen.addActionListener(this);
hMenu.add(abt);
hMenu.addSeparator();
hMenu.add(eMen);

menuBar.add(fMenu);
menuBar.add(hMenu);
setJMenuBar(menuBar);
butmainp = new JPanel();
butmainp.setLayout(new GridLayout(4, 4, 30, 30));

NewMem = new JButton("New Member");
NewMem.addActionListener(this);
butmainp.add(NewMem);

NewBook = new JButton("New Book Entry");
NewBook.addActionListener(this);
butmainp.add(NewBook);

Member = new JButton("Member Details");
Member.addActionListener(this);
butmainp.add(Member);

Books = new JButton("Book Details");
Books.addActionListener(this);
butmainp.add(Books);


cont.add("Center", butmainp);


}

public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
if (s.equals("Exit")) {
System.exit(0);
} else if (s.equalsIgnoreCase("Help")) {
JOptionPane.showMessageDialog(null, "This is a application for OPAC.\nFor more information:\n\tContact cse Innovators", "Help...!", JOptionPane.PLAIN_MESSAGE);
} else if (s.equalsIgnoreCase("About")) {
JOptionPane.showMessageDialog(null, "By Whitman Kumaresh - NPSB CSE Innovators.\nUnder the guidence of BHUVANESHWARI Mam.", "About", JOptionPane.PLAIN_MESSAGE);
}
if (s.equals("New Member")) {
NewMem nm1 = new NewMem();
nm1.setTitle("New Member");
nm1.setSize(370, 240);
nm1.setVisible(true);
}
if (s.equals("Member Details")) {
Member m1 = new Member();
m1.setTitle("Member Details");
m1.setSize(330, 280);
m1.setVisible(true);
}
if (s.equals("New Book Entry")) {
NewBook nb1 = new NewBook();
nb1.setTitle("New Book Entry");
nb1.setSize(370, 240);
nb1.setVisible(true);
}
if (s.equals("Book Details")) {
Book b1 = new Book();
b1.setTitle("Book Details");
b1.setSize(800, 420);
b1.setVisible(true);
}
}

public static void main(String args[]) {
Library main = new Library();
main.setTitle("Library");
main.setSize(640, 480);
main.setResizable(false);
main.setVisible(true);
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

SECOND PROGRAM


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;

class Book extends JFrame {

JButton clos;
JList mem;
JLabel desp;
JPanel membp;
Container cont;
Connection con;
ResultSet rs;
String n1, n2, n3, n4, n5, n6, n7;

Book() {
cont = getContentPane();
membp = new JPanel();
membp.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
desp.setToolTipText("Books available in library.\nShort description on every book.");
disp();
cont.add(membp);
}

public void disp() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Lib", "", "");
String table = "Book";
Statement st = con.createStatement();
rs = st.executeQuery("SELECT * FROM " + table);
while (rs.next()) {
n1 = rs.getString("bName");
n2 = rs.getString("bNo");
n3 = rs.getString("bAuthor");
n4 = rs.getString("bPub");
n5 = rs.getString("bYear");
desp = new JLabel("Name: " + n1 + " Book No: " + n2 + " Author: " + n3 + " Publisher: " + n4 + " Year: " + n5);
membp.add(desp);
}
} catch (Exception q) {
JOptionPane.showMessageDialog(null, " Error..", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}
}
}

THIRD PROGRAM


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;

class Member extends JFrame implements ActionListener {

JButton b1, b2;
JList mem;
JLabel desp, l1, l2;
JLabel mb1, mb2, mb3, mb4, mb5, mb6, mb7;
JPanel membp;
Container cont;
Connection con;
ResultSet rs;
JTextField t1, m1, m2, m3, m4, m5, m6, m7;
String n1, n2, n3, n4, n5, n6, n7, m;

Member() {
cont = getContentPane();
membp = new JPanel();
membp.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

l1 = new JLabel("Enter Member ID:");
t1 = new JTextField(10);

b1 = new JButton("View");
b1.addActionListener(this);
b2 = new JButton("Save");
b2.addActionListener(this);

m1 = new JTextField(20);
m2 = new JTextField(20);
m3 = new JTextField(20);
m4 = new JTextField(20);
m5 = new JTextField(20);
m6 = new JTextField(20);
m7 = new JTextField(20);

mb1 = new JLabel("Name: ");
mb2 = new JLabel("Address: ");
mb3 = new JLabel("Designation: ");
mb4 = new JLabel("Member ID: ");
mb5 = new JLabel("Book 1: ");
mb6 = new JLabel("Book 2: ");
mb7 = new JLabel("Book 3: ");
membp.add(l1);
membp.add(t1);
membp.add(b1);

membp.add(mb1);
membp.add(m1);
membp.add(mb2);
membp.add(m2);
membp.add(mb3);
membp.add(m3);
membp.add(mb4);
membp.add(m4);
membp.add(mb5);
membp.add(m5);
membp.add(mb6);
membp.add(m6);
membp.add(mb7);
membp.add(m7);

membp.add(b2);
cont.add(membp);
}

public void disp() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Lib", "", "");
String table = "Member";
PreparedStatement st = con.prepareStatement("SELECT i.* FROM Member i WHERE i.mId=?");
m = t1.getText().toString();
st.setString(1, m);
rs = st.executeQuery();
while (rs.next()) {
m1.setText(rs.getString("mName"));
m2.setText(rs.getString("mAdd"));
m3.setText(rs.getString("mDesig"));
m4.setText(rs.getString("mId"));
m5.setText(rs.getString("bBord1"));
m6.setText(rs.getString("bBord2"));
m7.setText(rs.getString("bBord3"));
}
} catch (Exception q) {
JOptionPane.showMessageDialog(null, "Server busy.\nTry after some time. ", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}
}

public void update() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Lib");
String table = "Member";
PreparedStatement ps = con.prepareStatement("UPDATE " + table + " SET bBord1=?,bBord2=?,bBord3=? WHERE mId=?");
ps.setString(1, m5.getText());
ps.setString(2, m6.getText());
ps.setString(3, m7.getText());
m = t1.getText().toString();
ps.setString(4, m);
ps.executeUpdate();
ps.close();
JOptionPane.showMessageDialog(null, m1.getText() + " details has been updated.", "Member Notification", JOptionPane.PLAIN_MESSAGE);
} catch (Exception q) {
JOptionPane.showMessageDialog(null, m1.getText() + ", sorry for inconvenience.\nServer busy.\nTry after some time. ", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}
}

public void actionPerformed(ActionEvent e) {
String a = e.getActionCommand();
if (a.equals("View")) {
disp();
}
if (a.equals("Save")) {
update();
}
}
}

FOURTH PROGRAM


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;

class NewBook extends JFrame implements ActionListener {

JTextField bName, bNo, bAuth, bPub, bYr;
JButton addBook;
JPanel memp;
Container cont;
Connection con;
ResultSet rs;
Statement st;

NewBook() {
cont = getContentPane();
memp = new JPanel();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
memp.setLayout(new FlowLayout(FlowLayout.RIGHT));
JLabel nm1 = new JLabel("Name:", JLabel.RIGHT);
bName = new JTextField(25);
JLabel nm2 = new JLabel("Book No:", JLabel.RIGHT);
bNo = new JTextField(25);
JLabel nm3 = new JLabel("Author:", JLabel.RIGHT);
bAuth = new JTextField(25);
JLabel nm4 = new JLabel("Publisher:", JLabel.RIGHT);
bPub = new JTextField(10);
JLabel nm5 = new JLabel("Year:", JLabel.RIGHT);
bYr = new JTextField(10);

bName.setToolTipText("Enter book name");
bNo.setToolTipText("Enter book no");
bAuth.setToolTipText("Enter author name");
bPub.setToolTipText("Enter publisher name");
bYr.setToolTipText("Enter year of the book being published");

addBook = new JButton("Add Book");
addBook.addActionListener(this);
memp.add(nm1);
memp.add(bName);
memp.add(nm2);
memp.add(bNo);
memp.add(nm3);
memp.add(bAuth);
memp.add(nm4);
memp.add(bPub);
memp.add(nm5);
memp.add(bYr);
memp.add(addBook);
cont.add(memp);
}

public void actionPerformed(ActionEvent e) {
String a = e.getActionCommand();
if (a.equals("Add Book")) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Lib");
String table = "Book";
PreparedStatement ps = con.prepareStatement("insert into " + table + " values(?,?,?,?,?)");
ps.setString(1, bName.getText());
ps.setString(2, bNo.getText());
ps.setString(3, bAuth.getText());
ps.setString(4, bPub.getText());
ps.setString(5, bYr.getText());
ps.executeUpdate();
ps.close();
JOptionPane.showMessageDialog(null, bName.getText() + " has been added to Book list", "Member Notification", JOptionPane.PLAIN_MESSAGE);
} catch (Exception q) {
}

} else {
JOptionPane.showMessageDialog(null, bName.getText() + "is not added to book list, sorry for inconvenience.\nServer busy.\nTry after some time. ", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}
}
}

FIFTH PROGRAM


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPanel.*;
import javax.swing.event.*;
import java.util.*;
import java.sql.*;

class NewMem extends JFrame implements ActionListener {

JTextField mName, mAdd, mDesig, mId;
JButton addMem;
JPanel memp;
Container cont;
Connection con;
ResultSet rs;
Statement st;

NewMem() {
cont = getContentPane();
memp = new JPanel();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
memp.setLayout(new FlowLayout(FlowLayout.RIGHT));
JLabel nm1 = new JLabel("Name:", JLabel.RIGHT);
mName = new JTextField(25);
JLabel nm2 = new JLabel("Address:", JLabel.RIGHT);
mAdd = new JTextField(25);
JLabel nm3 = new JLabel("Designation:", JLabel.RIGHT);
mDesig = new JTextField(20);
JLabel nm4 = new JLabel("Member ID:", JLabel.RIGHT);
mId = new JTextField(10);

mName.setToolTipText("Enter your name. ");
mAdd.setToolTipText("Enter your address.");
mDesig.setToolTipText("Enter your Designation.");
mId.setToolTipText("Enter your Mem ID.\nTo be provided while borrowing books.");

addMem = new JButton("Add Member");
addMem.addActionListener(this);
memp.add(nm1);
memp.add(mName);
memp.add(nm2);
memp.add(mAdd);
memp.add(nm3);
memp.add(mDesig);
memp.add(nm4);
memp.add(mId);
memp.add(addMem);
cont.add(memp);
}

public void actionPerformed(ActionEvent e) {
String a = e.getActionCommand();
if (a.equals("Add Member")) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Lib");
String table = "Member";
PreparedStatement ps = con.prepareStatement("insert into " + table + " values(?,?,?,?,?,?,?)");
ps.setString(1, mName.getText());
ps.setString(2, mAdd.getText());
ps.setString(3, mDesig.getText());
ps.setString(4, mId.getText());
ps.setString(5, "-");
ps.setString(6, "-");
ps.setString(7, "-");
ps.executeUpdate();
ps.close();
JOptionPane.showMessageDialog(null, mName.getText() + " has been added as a member", "Member Notification", JOptionPane.PLAIN_MESSAGE);

} catch (Exception q) {
JOptionPane.showMessageDialog(null, mName.getText() + ", sorry for inconvenience.\nServer busy.\nTry after some time. ", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}

} else {
JOptionPane.showMessageDialog(null, mName.getText() + ", sorry for inconvenience.\nServer busy.\nTry after some time. ", "Member Notification", JOptionPane.PLAIN_MESSAGE);
}
}
}

// Enjoy..!



Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
 

 

 

DMCA.com