Program

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Linear search

class LinearSearch
{
public static void main(String args[])

{
int c, n, search, array[];
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt();
array = new int[n];

System.out.println("Enter those " + n + " elements");


for (c = 0; c < n; c++)
array[c] = in.nextInt();
System.out.println("Enter value to find");
search = in.nextInt();
for (c = 0; c < n; c++)

{
if (array[c] == search) /* Searching element is present */
{
System.out.println(search + " is present at location " + (c + 1) + ".");
break;
}

}
if (c == n) /* Element to search isn't present */
System.out.println(search + " isn't present in array.");
}
}
Binary Search

class BinarySearchExample{
public static void binarySearch(int arr[], int first, int last, int key){
int mid = (first + last)/2;
while( first <= last ){
if ( arr[mid] < key ){
first = mid + 1;
}else if ( arr[mid] == key ){
System.out.println("Element is found at index: " + mid);
break;
}else{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last ){
System.out.println("Element is not found!");
}
}
public static void main(String args[]){
int arr[] = {10,20,30,40,50};
int key = 30;
int last=arr.length-1;
binarySearch(arr,0,last,key);
}
}
Selection Sort

import java.util.Scanner;

public class SelectionSortExample2


{
public static void main(String args[])
{
int size, i, j, temp;
int arr[] = new int[50];
Scanner scan = new Scanner(System.in);

System.out.print("Enter Array Size : ");


size = scan.nextInt();

System.out.print("Enter Array Elements : ");


for(i=0; i<size; i++)
{
arr[i] = scan.nextInt();
}

System.out.print("Sorting Array using Selection Sort Technique..\n");


for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

System.out.print("Now the Array after Sorting is :\n");


for(i=0; i<size; i++)
{
System.out.print(arr[i]+ " ");
}
}
}
Insertion Sort

public class InsertionSortExample {


public static void insertionSort(int array[]) {
int n = array.length;
for (int j = 1; j < n; j++) {
int key = array[j];
int i = j-1;
while ( (i > -1) && ( array [i] > key ) ) {
array [i+1] = array [i];
i--;
}
array[i+1] = key;
}
}

public static void main(String a[]){


int[] arr1 = {9,14,3,2,43,11,58,22};
System.out.println("Before Insertion Sort");
for(int i:arr1){
System.out.print(i+" ");
}
System.out.println();

insertionSort(arr1);//sorting array using insertion sort

System.out.println("After Insertion Sort");


for(int i:arr1){
System.out.print(i+" ");
}
}
}
Stack

import java.util.Scanner;

class StackExample {

int number[];

int top;

int limit;

// constructor

public StackExample(int size){

top =-1;

limit =size;

number=new int[size];

// insert an element

void push(int num)

if(isFull())

System.out.println("Stack is full");

else

top=top+1;

number[top]=num;

// popping out the element that is at the top ofstackvoid pop(){

void pop()
{

if(isEmpty())

System.out.println("Stack is Empty");}

else{

top=top-1;

System.out.println("Element popped out");

void peek()

System.out.println("Top most element in Stack="+number[top]);

boolean isFull()

return top >=limit-1;

boolean isEmpty(){

return top==-1;

void print(){

System.out.println("Elements in Stack:-");

for(int i=top;i>=0;i--)

System.out.println(number[i]);
}

public static void main(String[] args) {

Scanner input =new Scanner(System.in) ;

int size,option,element;

char chr;

System.out.print("Enter the maximum size that a stack can have = ");

size=input.nextInt();

StackExample obj= new StackExample(size);

do{

System.out.println("Please press any number from the following operations:-"

+ "\n 1. Insert an element "

+ "\n 2. Pop an element"

+ "\n 3. Peek of the stack"

+ "\n 4. Display the elements ofthestack");

option=input.nextInt();

switch(option){

case 1:

System.out.print("Please enter the element to insert = ");

element=input.nextInt();

obj.push(element);

break;

case 2:

obj.pop();

break;

case 3:
obj.peek();

break;

case 4:

obj.print();

break;

default:

System.out.println("Choose wrongoption");

System.out.println("Want to continue? y or n");

chr=input.next().charAt(0);

}while(chr=='y'||chr=='Y');

}
Queue

import java.io.*;

class QueueMain {

BufferedReader buffread = new BufferedReader(new

InputStreamReader(System.in));

int items[];

int i, front = 0, rear = 0, itemnum, item, count = 0;

void getdata() {

try {

System.out.println("Enter the Limit :");

itemnum = Integer.parseInt(buffread.readLine());

items = new int[itemnum];

} catch (Exception ex) {

System.out.println(ex.getMessage());

void enqueue() {

try {

if (count < itemnum) {

System.out.println("Enter Queue Element :");

item = Integer.parseInt(buffread.readLine());

items[rear] = item;

rear++;

count++;

}
else

System.out.println("Queue Is Full");

} catch (Exception ex) {

System.out.println(ex.getMessage());

void dequeue() {

if (count != 0) {

System.out.println("Deleted Item :" + items[front]); front++;

count--;

} else {

System.out.println("Queue Is Empty");

if (rear == itemnum) {

rear = 0;

void display() {

int m = 0;

if (count == 0) {

System.out.println("Queue Is Empty");

} else {

for (i = front; m < count; i++, m++) {


System.out.println(" " + items[i]);

class QueueProgram {

public static void main(String arg[]) {

DataInputStream instr = new DataInputStream(System.in);

int choice;

QueueMain que = new QueueMain();

que.getdata();

System.out.println("Queue\n\n");

try {

do {

System.out.println("1.Enqueue\n2.Dequeue\n3.Display\n4.Exit\n");

System.out.println("Enter the Choice : ");

choice = Integer.parseInt(instr.readLine());

switch (choice) {

case 1:

que.enqueue();

break;

case 2:

que.dequeue();

break;
case 3:

que.display();

break;

} while (choice != 4);

} catch (Exception ex) {

System.out.println(ex.getMessage());

}
Payslip

package pay;

import java.util.*;

public class Pay

public static void main(String args[])

int choice,cont;

do

System.out.println("PAYROLL");

System.out.println(" 1.PROGRAMMER \t 2.ASSISTANT PROFESSOR \t


3.ASSOCIATEPROFESSOR \t 4.PROFESSOR ");

Scanner c = new Scanner(System.in);

choice=c.nextInt();

switch(choice)

case 1:

programmer p=new programmer();

p.getdata();

p.getprogrammer();

p.display();

p.calculateprog();

break;
}

case 2:

asstprofessor asst=new asstprofessor();

asst.getdata();

asst.getasst();

asst.display();

asst.calculateasst();

break;

case 3:

associateprofessor asso=new associateprofessor();

asso.getdata();

asso.getassociate();

asso.display();

asso.calculateassociate();

break;

case 4:

professor prof=new professor();

prof.getdata();

prof.getprofessor();

prof.display();
prof.calculateprofessor();

break;

System.out.println("Do u want to continue 0 to quit and 1 to continue ");

cont=c.nextInt();

}while(cont==1);

class employee

int empid;

long mobile;

String name, address, mailid;

Scanner get = new Scanner(System.in);

void getdata()

System.out.println("Enter Name of the Employee");

name = get.nextLine();

System.out.println("Enter Mail id");

mailid = get.nextLine();

System.out.println("Enter Address of the Employee:");

address = get.nextLine();

System.out.println("Enter employee id ");


empid = get.nextInt();

System.out.println("Enter Mobile Number");

mobile = get.nextLong();

void display()

System.out.println("Employee Name: "+name);

System.out.println("Employee id : "+empid);

System.out.println("Mail id : "+mailid);

System.out.println("Address: "+address);

System.out.println("Mobile Number: "+mobile);

class programmer extends employee

double salary,bp,da,hra,pf,club,net,gross;

void getprogrammer()

System.out.println("Enter basic pay");

bp = get.nextDouble();

void calculateprog()

da=(0.97*bp);

hra=(0.10*bp);
pf=(0.12*bp);

club=(0.1*bp);

gross=(bp+da+hra);

net=(gross-pf-club);

System.out.println("************************************************");

System.out.println("PAY SLIP FOR PROGRAMMER");

System.out.println("************************************************");

System.out.println("Basic Pay:Rs"+bp);

System.out.println("DA:Rs"+da);

System.out.println("PF:Rs"+pf);

System.out.println("HRA:Rs"+hra);

System.out.println("CLUB:Rs"+club);

System.out.println("GROSS PAY:Rs"+gross);

System.out.println("NET PAY:Rs"+net);

class asstprofessor extends employee

double salary,bp,da,hra,pf,club,net,gross;

void getasst()

System.out.println("Enter basic pay");

bp = get.nextDouble();

void calculateasst()
{

da=(0.97*bp);

hra=(0.10*bp);

pf=(0.12*bp);

club=(0.1*bp);

gross=(bp+da+hra);

net=(gross-pf-club);

System.out.println("************************************************");

System.out.println("PAY SLIP FOR ASSISTANT PROFESSOR");

System.out.println("************************************************");

System.out.println("Basic Pay:Rs"+bp);

System.out.println("DA:Rs"+da);

System.out.println("HRA:Rs"+hra);

System.out.println("PF:Rs"+pf);

System.out.println("CLUB:Rs"+club);

System.out.println("GROSS PAY:Rs"+gross);

System.out.println("NET PAY:Rs"+net);

class associateprofessor extends employee

double salary,bp,da,hra,pf,club,net,gross;

void getassociate()

System.out.println("Enter basic pay");


bp = get.nextDouble();

void calculateassociate()

da=(0.97*bp);

hra=(0.10*bp);

pf=(0.12*bp);

club=(0.1*bp);

gross=(bp+da+hra);

net=(gross-pf-club);

System.out.println("************************************************");

System.out.println("PAY SLIP FOR ASSOCIATE PROFESSOR");

System.out.println("************************************************");

System.out.println("Basic Pay:Rs"+bp);

System.out.println("DA:Rs"+da);

System.out.println("HRA:Rs"+hra);

System.out.println("PF:Rs"+pf);

System.out.println("CLUB:Rs"+club);

System.out.println("GROSS PAY:Rs"+gross);

System.out.println("NET PAY:Rs"+net);

class professor extends employee

double salary,bp,da,hra,pf,club,net,gross;
void getprofessor()

System.out.println("Enter basic pay");

bp = get.nextDouble();

void calculateprofessor()

da=(0.97*bp);

hra=(0.10*bp);

pf=(0.12*bp);

club=(0.1*bp);

gross=(bp+da+hra);

net=(gross-pf-club);

System.out.println("************************************************");

System.out.println("PAY SLIP FOR PROFESSOR");

System.out.println("************************************************");

System.out.println("Basic Pay:Rs"+bp);

System.out.println("DA:Rs"+da);

System.out.println("HRA:Rs"+hra);

System.out.println("PF:Rs"+pf);

System.out.println("CLUB:Rs"+club);

System.out.println("GROSS PAY:Rs"+gross);

System.out.println("NET PAY:Rs"+net);

}
Abstract

import java.util.*;
abstract class shape
{
int a,b;
abstract public void printarea();
}
class rectangle extends shape
{
public int area_rect;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the length and breadth of rectangle");
a=s.nextInt();
b=s.nextInt();
area_rect=a*b;
System.out.println("Length of rectangle "+a +"breadth of rectangle "+b);
System.out.println("The area ofrectangle is:"+area_rect);
}
}
class triangle extends shape
{
double area_tri;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the base and height of triangle");
a=s.nextInt();
b=s.nextInt();
System.out.println("Base of triangle "+a +"height of triangle "+b);
area_tri=(0.5*a*b);
System.out.println("The area of triangle is:"+area_tri);
}
}
class circle extends shape
{
double area_circle;
public void printarea()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the radius of circle");
a=s.nextInt();
area_circle=(3.14*a*a);
System.out.println("Radius of circle"+a);
System.out.println("The area of circle is:"+area_circle);
}
}
public class shapeclass
{
public static void main(String[] args)
{
rectangle r=new rectangle();
r.printarea();
triangle t=new triangle();
t.printarea();
circle r1=new circle();
r1.printarea();
} }
INTERFACE

import java.util.*;

interface shape

public void printarea();

class rectangle implements shape

public int area_rect;

int a,b;

public void printarea()

Scanner s=new Scanner(System.in);

System.out.println("enter the length and breadth of rectangle");

a=s.nextInt();

b=s.nextInt();

area_rect=a*b;

System.out.println("Length of rectangle "+a +"breadth of rectangle "+b);

System.out.println("The area ofrectangle is:"+area_rect);

class triangle implements shape

{
double area_tri;

int a,b;

public void printarea()

Scanner s=new Scanner(System.in);

System.out.println("enter the base and height of triangle");

a=s.nextInt();

b=s.nextInt();

System.out.println("Base of triangle "+a +"height of triangle "+b);

area_tri=(0.5*a*b);

System.out.println("The area of triangle is:"+area_tri);

class circle implements shape

double area_circle;

int a,b;

public void printarea()

Scanner s=new Scanner(System.in);

System.out.println("enter the radius of circle");

a=s.nextInt();

area_circle=(3.14*a*a);
System.out.println("Radius of circle"+a);

System.out.println("The area of circle is:"+area_circle);

public class Abstact

public static void main(String[] args)

rectangle r=new rectangle();

r.printarea();

triangle t=new triangle();

t.printarea();

circle r1=new circle();

r1.printarea();

}
EXCEPTION HANDLING

6A) MULTIPLE CATCH

package multiplecatch;
public class Multiplecatch {
public static void main(String[] args) {

try{
int a[]=new int[5];

System.out.println(a[10]);
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception occurs");

}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occurs");
}
catch(Exception e)
{

System.out.println("Parent Exception occurs");


}
System.out.println("rest of the code");
}
}
6B) USER DEFINED EXCEPTION
package myexception;
import java.util.Scanner;
class NegativeAmtException extends

Exception
{
String msg;
NegativeAmtException(String msg)
{
this.msg=msg;

}
public String toString()
{
return msg;
}
}

public class Myexception


{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.print("Enter Amount:");

int a=s.nextInt();
try
{
if(a<0)
{
throw new NegativeAmtException("Invalid Amount");
}
System.out.println("Amount Deposited");
}

catch(NegativeAmtException e)
{
System.out.println(e);
}
}
}
MULTITHREAD
import java.util.*;
class Even implements Runnable
{

public int x;
public Even(int x)
{
this.x = x;
}
public void run()

{
System.out.println("New Thread "+ x +" is EVEN and Square of " + x + " is: " + x * x);
}
}
class Odd implements Runnable
{

public int x;
public Odd(int x)
{
this.x = x;
}
public void run()

{
System.out.println("New Thread "+ x +" is ODD and Cube of " + x + " is: " + x * x * x);
}
}
class Generate extends Thread
{
public void run()
{
int num = 0;

Random r = new Random();


try
{
for (int i = 0; i < 5; i++)
{
num = r.nextInt(100);

System.out.println("Main Thread Generates Random Integer: " + num);


if (num % 2 == 0)
{
Thread t1 = new Thread(new Even(num));
t1.start();
}

else
{
Thread t2 = new Thread(new Odd(num));
t2.start();
}
Thread.sleep(1000);

System.out.println("--------------------------------------");
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
}

public class Multithread


{
public static void main(String[] args)
{
Generate g = new Generate();
g.start();

}
}
FILE

package file;

import java.io.*;

import java. util.*;

public class FILE {

public static void main(String[] args) throws IOException

Scanner in=new Scanner(System.in);

System.out.print("\nEnter the FileName: ");

String fName = in.next();

File f = new File(fName);

String result = f.exists() ? " exists." : " does not exist.";

System.out.println("\nThe given file " +fName + result);

System.out.println("\nFile Location: "+f.getAbsolutePath());

if(f.exists())

result = f.canRead() ? "readable." : "not readable.";

System.out.println("\nThe file is " + result);

result = f.canWrite() ? "writable." : "not writable.";

System.out.println("\nThe file is " + result);

System.out.println("\nFile length is " + f.length() + " in bytes.");

if (fName.endsWith(".jpg") || fName.endsWith(".gif") || fName.endsWith(".png"))

System.out.println("\nThe given file is an image file.");

}
else if (fName.endsWith(".pdf"))

System.out.println("\nThe given file is an portable document format.");

else if (fName.endsWith(".txt"))

System.out.println("\nThe given file is a text file.");

else

System.out.println("The file type is unknown.");

}
GENERICS CLASS

package generics;

import java.util.*;

public class GENERICS {

public static <T extends Comparable<T>> T max(T... elements)

T max = elements[0];

for (T element : elements) {

if (element.compareTo(max) > 0)

max = element;

return max;

public static void main(String[] args)

System.out.println("Integer Max: " + max(Integer.valueOf(32), Integer.valueOf(89)));

System.out.println("String Max: " + max("GaneshBabu", "Ganesh"));

System.out.println("Double Max: " + max(Double.valueOf(5.6), Double.valueOf(2.9)));

System.out.println("Boolean Max: " + max(Boolean.TRUE, Boolean.FALSE));

System.out.println("Byte Max: " + max(Byte.MIN_VALUE, Byte.MAX_VALUE));

}
JAVAFX

import javafx.application.Application;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.geometry.HPos;

import javafx.geometry.Insets;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.*;

import javafx.scene.layout.*;

import javafx.scene.text.Font;

import javafx.scene.text.FontWeight;

import javafx.stage.Stage;

import javafx.stage.Window;

public class RegistrationFormApplication extends Application {

@Override

public void start(Stage primaryStage) throws Exception {

primaryStage.setTitle("Registration Form JavaFX Application");

// Create the registration form grid pane

GridPane gridPane = createRegistrationFormPane();

// Add UI controls to the registration form grid pane


addUIControls(gridPane);

// Create a scene with registration form grid pane as the root node

Scene scene = new Scene(gridPane, 800, 500);

// Set the scene in primary stage

primaryStage.setScene(scene);

primaryStage.show();

private GridPane createRegistrationFormPane() {

// Instantiate a new Grid Pane

GridPane gridPane = new GridPane();

// Position the pane at the center of the screen, both vertically and horizontally

gridPane.setAlignment(Pos.CENTER);

// Set a padding of 20px on each side

gridPane.setPadding(new Insets(40, 40, 40, 40));

// Set the horizontal gap between columns

gridPane.setHgap(10);

// Set the vertical gap between rows


gridPane.setVgap(10);

// Add Column Constraints

// columnOneConstraints will be applied to all the nodes placed in column one.

ColumnConstraints columnOneConstraints = new ColumnConstraints(100, 100,


Double.MAX_VALUE);

columnOneConstraints.setHalignment(HPos.RIGHT);

// columnTwoConstraints will be applied to all the nodes placed in column two.

ColumnConstraints columnTwoConstrains = new ColumnConstraints(200,200,


Double.MAX_VALUE);

columnTwoConstrains.setHgrow(Priority.ALWAYS);

gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstrains);

return gridPane;

private void addUIControls(GridPane gridPane) {

// Add Header

Label headerLabel = new Label("Registration Form");

headerLabel.setFont(Font.font("Arial", FontWeight.BOLD, 24));

gridPane.add(headerLabel, 0,0,2,1);

GridPane.setHalignment(headerLabel, HPos.CENTER);
GridPane.setMargin(headerLabel, new Insets(20, 0,20,0));

// Add Name Label

Label nameLabel = new Label("Full Name : ");

gridPane.add(nameLabel, 0,1);

// Add Name Text Field

TextField nameField = new TextField();

nameField.setPrefHeight(40);

gridPane.add(nameField, 1,1);

// Add Email Label

Label emailLabel = new Label("Email ID : ");

gridPane.add(emailLabel, 0, 2);

// Add Email Text Field

TextField emailField = new TextField();

emailField.setPrefHeight(40);

gridPane.add(emailField, 1, 2);

// Add Password Label

Label passwordLabel = new Label("Password : ");

gridPane.add(passwordLabel, 0, 3);
// Add Password Field

PasswordField passwordField = new PasswordField();

passwordField.setPrefHeight(40);

gridPane.add(passwordField, 1, 3);

// Add Submit Button

Button submitButton = new Button("Submit");

submitButton.setPrefHeight(40);

submitButton.setDefaultButton(true);

submitButton.setPrefWidth(100);

gridPane.add(submitButton, 0, 4, 2, 1);

GridPane.setHalignment(submitButton, HPos.CENTER);

GridPane.setMargin(submitButton, new Insets(20, 0,20,0));

submitButton.setOnAction(new EventHandler<ActionEvent>() {

@Override

public void handle(ActionEvent event) {

if(nameField.getText().isEmpty()) {

showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form


Error!", "Please enter your name");

return;

if(emailField.getText().isEmpty()) {
showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form
Error!", "Please enter your email id");

return;

if(passwordField.getText().isEmpty()) {

showAlert(Alert.AlertType.ERROR, gridPane.getScene().getWindow(), "Form


Error!", "Please enter a password");

return;

showAlert(Alert.AlertType.CONFIRMATION, gridPane.getScene().getWindow(),
"Registration Successful!", "Welcome " + nameField.getText());

});

private void showAlert(Alert.AlertType alertType, Window owner, String title, String


message) {

Alert alert = new Alert(alertType);

alert.setTitle(title);

alert.setHeaderText(null);

alert.setContentText(message);

alert.initOwner(owner);

alert.show();

}
public static void main(String[] args) {

launch(args);

}
LIBRARY MANAGEMENT

package Library_Management;

import java.awt.Dimension;

import java.awt.Toolkit;

public class Home extends javax.swing.JFrame {

public Home() {

initComponents();

Toolkit toolkit = getToolkit();

Dimension size = toolkit.getScreenSize();

setLocation(size.width/2 - getWidth()/2, size.height/2 - getHeight()/2);

private void initComponents() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

jPanel4 = new javax.swing.JPanel();

jPanel2 = new javax.swing.JPanel();

btnrbook = new javax.swing.JButton();

btnibook = new javax.swing.JButton();

jPanel1 = new javax.swing.JPanel();

btnstatistics = new javax.swing.JButton();

btnnewstudent = new javax.swing.JButton();

btnnewbook = new javax.swing.JButton();

jMenuBar1 = new javax.swing.JMenuBar();


jMenu1 = new javax.swing.JMenu();

miexit = new javax.swing.JMenuItem();

milogout = new javax.swing.JMenuItem();

jMenu2 = new javax.swing.JMenu();

miabout = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("Main Menu");

setBackground(new java.awt.Color(0, 204, 204));

jLabel1.setBackground(new java.awt.Color(0, 255, 255));

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

jLabel1.setText("Library Management System");

jLabel2.setText("Welcome");

jLabel3.setText("to");

jLabel4.setText(" Library");

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineB
order(new java.awt.Color(102, 255, 204)), "Action",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 24), new
java.awt.Color(255, 102, 102))); // NOI18N

btnrbook.setText("Return Book");

btnrbook.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnrbookActionPerformed(evt);

}
});

btnibook.setText("Issue Book");

btnibook.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnibookActionPerformed(evt);

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineB
order(new java.awt.Color(102, 255, 102)), "Operation",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 24), new
java.awt.Color(0, 102, 204))); // NOI18N

btnstatistics.setText("Statistics");

btnstatistics.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnstatisticsActionPerformed(evt);

});

btnnewstudent.setText("New Student");

btnnewstudent.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnnewstudentActionPerformed(evt);

}
});

btnnewbook.setText("New Book");

btnnewbook.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnnewbookActionPerformed(evt);

});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addComponent(btnnewbook, javax.swing.GroupLayout.PREFERRED_SIZE, 175,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addComponent(btnstatistics, javax.swing.GroupLayout.PREFERRED_SIZE, 175,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addComponent(btnnewstudent, javax.swing.GroupLayout.PREFERRED_SIZE, 175,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(62, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btnnewbook, javax.swing.GroupLayout.PREFERRED_SIZE, 65,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(btnstatistics, javax.swing.GroupLayout.PREFERRED_SIZE, 65,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(btnnewstudent, javax.swing.GroupLayout.PREFERRED_SIZE, 62,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(29, Short.MAX_VALUE))

);

jPanel4Layout.setVerticalGroup(

jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel4Layout.createSequentialGroup()

.addGap(32, 32, 32)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(41, 41, 41)

.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(106, Short.MAX_VALUE))

);

jMenu1.setText("File");

miexit.setText("Exit");
miexit.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

miexitActionPerformed(evt);

});

jMenu1.add(miexit);

milogout.setText("Logout");

milogout.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

milogoutActionPerformed(evt);

});

jMenu1.add(milogout);

jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");

miabout.setText("About");

jMenu2.add(miabout);

jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()
.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)

.addComponent(jLabel2)

.addComponent(jLabel3)

.addComponent(jLabel4))

.addContainerGap())))

);

private javax.swing.JButton btnibook;

private javax.swing.JButton btnnewbook;

private javax.swing.JButton btnnewstudent;

private javax.swing.JButton btnrbook;

private javax.swing.JButton btnstatistics;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JMenu jMenu1;


private javax.swing.JMenu jMenu2;

private javax.swing.JMenuBar jMenuBar1;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JPanel jPanel4;

private javax.swing.JMenuItem miabout;

private javax.swing.JMenuItem miexit;

private javax.swing.JMenuItem milogout;

DATABASE

package DAO;

import java.sql.*;

public class DatabaseHelper {

public static Connection getConnection(){

try {

Class.forName("com.mysql.jdbc.Driver");

Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/library_management","root","");

return con;

} catch (Exception e) {

System.err.println("Connection error");

return null;

}}

You might also like