Professional Documents
Culture Documents
Java
Java
E-mail : gyankoshprokashoni@gmail.com
gk_tarafder@yahoo.com
ISBN : 978-984-8812-91-4
:
বইটির ববশিষ্ট্য:
বইটির মাধ্যমম হমে পামর আপনার প্রাগ্রাশমিং এর শুরু।
রশেটি শবষয় ধামপ ধামপ সহজ ভামব উপস্থাপন হময়মে ।
কময়কটি রাকটিকযাল রমজক্ট কমর প্েখামনা হময়মে ।
গ্রাশিকযাল ইউজার ইন্টারমিইস এর ব্যবহার প্েখামনা হময়মে ।
প্নটশবনস, প্জশিময়টর এবিং ই-শিপস এর ব্যবহার প্েখামনা হময়মে ।
বইটি পড়ার জন্য প্কান প্রাগ্রাশমিং জ্ঞান থাকার রময়াজন প্নই ।
রশেটি অধ্যাময় এবিং শিশভশিমে রচুর রযাকটিস প্রাগ্রাম প্েওয়া হময়মে ।
শবশ্বশবদ্যালয় এবিং শবশভন্ন শিক্ষা রশেষ্ঠামনর শসমলবাস অনুযায়ী রণীে ।
infobook7@gmail.com|
www.bookbd.info
Jcreator, Netbeans E-
clipse
infobook7@gmail.com
www.bookbd.info
facebook.com/mmr.sinha
infobook7@gmail.com
www.bookbd.info
facebook.com/ebookbd
Environment
(String)
(Inheritance)
(Lexical Elements)
Environment
Environment
(Java IDE)
(JDK)
(Command Prompt)
(Jcreator)
(Netbeans)
(Eclipse)
(Setting up your Computer)
Prompt
(Error)
Numerical Data
History)
Charcteristic
(JDK & JVM)
(Expresssion)
(Operator Types)
(Arithmetic Operator)
(Assignment Operator)
(Comparision Operators)
(&&/and) (Logical Operator)
(Precedence of Arithmatic Operator)
(Bitwise Operator)
Decesion Making
:
:
: Conditional Statement
: If statement
: Multiple If statement
: Nested If
: If----Else
Switch
:
:
(Loop)
:
:
:
: Loop
: Type of Loop
: For Loop
(While Loop)
(Do-While Loop)
(Break)
(Break Syntax)
(Continue)
Statement
(Array)
(Array)
Syntax
Intialization
(Arguments)
(Over Loading)
(Constructor)
Constructor (Characteristic)
Constructor
Constructor
(String)
(String)
(String Class)
(String Operation)
Console
Scanner
(Modifier)
(Access Control Modifier)
(Non Access Modifier)
(public)
(Default)
(Private)
(Protected)
(Non Access Modifier)
(Inheritance)
(Inheritance)
(Syntax of Inheritance)
(this)
(Type of Inheritance)
(Abstruct)
(Encapsulation)
(Interface)
(Java Pakage)
(Client Server Computing)
(Java Applet)
(Input Stream Class)
(Data Stream)
(Thread)
(Exception)
(Swing & GUI)
(Graphical User Interface & Netbeans)
Netbeans Installation
(File Menu)
(Edit Menu)
(View Menu)
(J-Frame Form)
Palette
(Message Display)
(Message Display Using Button Click)
(Create User Interface of Calculator)
(Calculator)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Run the project)
(Make Invoice)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Run the project)
(Age Calculator)
(Name of project)
(Purpose of this project)
(Feature of this project)
(Input and Output)
(Create project)
(Project source code)
(Temparature Converter)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Run the project)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Run the project)
(Point of Sale System)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Run the project)
(Temparature Converter)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Phone Book Record System)
(Translator)
(Java):
C (Intermediate)
PHP
(JavaScript):
C
(Cobol)
(HTML)
(Python)
(Prolog)
(QBasic)
(Ruby)
(SQL)
(Visual Basic)
Application
(Application)
1.10
(OS)
mp3
Low Level
(High Level)
(Lexical Elements)
Public, This, Private, Static, class
Reserve [Reserve
Word That One Predefined in Language].
Abstract Break Transient
Class
Default Else Short
Float
If Instanceof Interface
New
Package Protect Catch
Super
Synchronized Throws Long
volatile
Assert Ed Final
const
Do Exten Try
for
Implements Int Static
null
Private Ds True
switch
This Return Char
while
Boolean Public Finally
continue
Import False Native
goto
Double Byte Strictfp
Throw Case Void
Lexical Elements
White Space
Comments
Identifier)
Reserved Words)
Literals)
Delimiters)
Operators
Space
Forword Slash
//Dhaka;
Dhaka
//Dhaka;
Bangladesh;
//Comilla;
Dhaka Comilla Bangladesh
/* text */
/* Dhaka;
Bangladesh */
Dhaka Bangladesh
(External)
/** text */
/** Dhaka;
Bangladesh */
Dhaka Bangladesh
Letter,
Numbers and Underscore
name
dog
p
xm
nima
$pu
-2ah
bd
Applet
black&white
A+
Java
www.bookbd.info
phone#
grade_report
Class
instructor's name
99bottles
false
theBuyFigureForTheFiscalYear2014
$865
Instance
Blue Print
Translate
.java .class
JDK Java Development Kit
Editor Textpad, JCreator, Netbeans, Eclips
a, p, p5, dom
+(Addition), -(Subtraction),
++(Increment), ==(equal), >(is greater than), && (and)
JCreator
do, else, private, public, null, new
Oak
Environment
Environment
(Java IDE)
(JDK)
(Command Prompt)
(Jcreator)
(Netbeans)
(Eclipse)
Environment
Java
Run
Confirmation Message
www.java.com/getjava/
(Java IDE)
A Java IDE (Integrated Development Environment) software application
debug IDE
syntax highlighting and code completion
IDE
Ecilpse, NetBeans, JCreator, BlueJ, Processing, Kawa, JBuilder, DrJava
(JDK)
Java JDK(Java Development Kit)
JDK
JDK-7 JDK (JRE), (Java),
(Javac), (Javadoc) JRE
JDK JRE JDK
JDK
(http://www.oracle.com/technetwork/java/javase/downloads/index.html)
JDK
SE
(Command Prompt)
Run Program in Black Screen
এ
JDK install program files C:\Program
Files\Java\jdk1.7.0_51\bin Address
My Computer -> properties ->Advance System Setting -> Environment Variable
I love Java
Programming .
.java)
JavaRun.java
Start+R RUN cmd
javac Enter
java Class (dir)
(filename.class)
java Enter
java javaRun (“I love Java
Programming”)
cmd
(J creat or)
program Java IDE (Integrated Development Environment)
software application debug
IDE syntax highlighting and code
completion Jcreato
Java IDE
Jcreator
Jcreator CD Software JDK
Jcreator Yes
setup
Yes Next
Jcreator
Jcreator 1.5
File
File Name Class Name
Compile
Jcreator program
(Netbeans)
Netbeans ?
C, C++, JAVA IDE
IDE Netbeans NetBean
NetBean GUI(Graphical
User Interface) NetBean
https://netbeans.org/downloads/]
NetBean NetBean
NetBean
NetBean Finish
NetBean NetBean
File New Project
Java Application Next
Pakage explorer
Run File| RUN Run
File Menu
New Project:
New option
Shortcut: Ctrl+Shift+N
New File:
New File option
Shortcut: Ctrl+N
. Open Project:
Shortcut: Ctrl+Shift+O
. Open Recent Project:
. Close Project:
. Open File:
. Project Group:
group
. Project Properties:
. ImportProject:
zip import
. ExportProject:
export
. Save:
Shortcut: Ctrl+S
. SaveAll:
Shortcut: Ctrl+Shift+S
. Page Setup:
. Print:
Shortcut: Ctrl+Alt+Shift+P
. Print:
Shortcut: Ctrl+Alt+Shift+P
. Print to HTML:
HTML
. Exit:
D³
(Eclipse)
Eclipse ?
program JAVA IDE Java IDE (Integrated Development
Environment) software application
debug IDE syntax
highlighting and code completion
Eclipse Java IDE eclipse open-source community
Eclipse
Eclipse download http://www.eclipse.org/downloads
Google eclipse download
Google
Eclipse
windows bit bit Windows
bit computer menu mouse right button click
Eclipse Download
eclipse eclipse.exe
workspace location workspace
Eclipse workspace
Eclipse
eclipse Cross
Platform IDE prospective JAVA, Android
Dev., C/C++, XML JAVA prospective
software Menubar
Menu option
toolbar
option
Eclipse
4 outline view
৫ Editor
edit
৬ problem view output error
৭ Project Explorer
Eclipse program
Eclipse program Hello World! This is my first
java Program print eclipse menu bar file click New, new
java project
project
project
source
Name
HelloWorld
option Modifier (public, private etc)
class
Editor Area
“Hello world! This is my first java program”
Prompt
(Error)
Java Development Kit
1: 2: 3:
Physical
JDK Bin
JCreator
(FirstJava.java)
public class FirstJava {
public static void main(String args[])
{
System.out.println("My First Program");
} }
(FirstJava.java)
FirstJava.Java
Command Prompt
C:\)|
FirstJava.Java Enter
FirstJava
My First Program
***
JCreator
JCreator
JCreator
JCreator V1 JCreator
JCreator
New
Files by default
project New Window Java File, HTML File, Text File
Java File book
ok
JCreator
(book.java)
public class book
{
public static void main(String args[])
{
System.out.println("Bookbd Series");
}
}
(book.java)
String S Capital Letter System S Capital Letter
book
Error
Compile
Execute
Execute
Execute book
: Notepad++, Textpad,
JCreator Eclips Netbeans. .java (
book.java
book book
: Compile
JDK
: Java Runtime
(bd.java
public class bd //The name of class is
{
public static void main(String args[])
{
// This is main Method
System.out.println("Dhaka");
// System.out.printLn("Bangladesh");
/* In this program comments do not execute. Its use fast for
developer
help. In this program the output will be dhaka */
}
}
jcreator
(Projectrunning)
(Selected Product)
(Cash memo)
(Temparature Converter)
(Name of Project)
(purpose of this project)
(Feature of this project)
(Input and Output)
(How to create project)
(Source code of this project)
(Name of project)
(GUI)
Temperature converter
Code Run
(Sample input & output)
(Create project)
Netbeans File New Project Catagories Java
Projects Java Applicaion Next Project Name
Temp Finish
NetBeans
NetBeans Projects Temp Source Packages temp
New JFrame Form
GUI
GraphicalUserInterface NetBeans Palette
Swing Containers Panel GraphicalUser Interface NetBeans
Properties Border
Etched Border Ok Design
JPanel1 border
Label Edit Text
Temperature Converter
Label
Properties font-
JLabel1 font
Properties foreground
Properties Background
GUI
Pallete Swing Controls JLabel From
13, 14, 15
JLabel2
Graphical User Interface Swing Controls
Properties Model
Combo Box
Combo Box model-
Text Field
Panel Swing Containers
Panel
Panel Palette Swing Controls Properties Edit Text
Convert Close
Button
icon drag
Convert Button Properties icon font
JButton1 font
Panel Button Clear
Panel Properties
Menu Bar
File
File
icon
icon changing
JMenuItem1 Edit Text Exit
Shortcut Key
Edit Delete
Edit Delete
GraphicalUserInterface.java
Temp.java
(.jar location)
(Project source code)
Temp.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools| Templates
* and open the template in the editor.
*/
package temp;
/**
*
* @author Badal
*/
public class Temp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GraphicalUserInterface().setVisible(true);
}
});
}
GraphicalUserInterface.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools| Templates
* and open the template in the editor.
*/
package temp;
/** *
* @author Badal
*/
public class GraphicalUserInterface extends javax.swing.JFrame {
/**
* Creates new form GraphicalUserInterface
*/
public GraphicalUserInterface() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jTextField2 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 255,
153));Panel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.bord
er.EtchedBorder.RAISED));
jLabel1.setFont(new java.awt.Font("Engravers MT", 3, 25)); // NOI18N
jLabel1.setForeground(new java.awt.Color(153, 153, 0));
jLabel1.setText(" Temperature Converter");
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(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 616,
Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLabel1)
.addContainerGap(23, Short.MAX_VALUE))
);
jPanel2.setBackground(new java.awt.Color(204, 255, 204));
jLabel2.setFont(new java.awt.Font("Batang", 1, 20)); // NOI18N
jLabel2.setForeground(new java.awt.Color(0, 51, 153));
jLabel2.setText("From");
jTextField2.setText("Result");
jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});
(Create Project)
NetBeans File New Project Categories Java Projects
Java Application Next Project Name- Phonebook
Finish
Phonebook, Login Jframe Main class
3 class
(Source Code)
Phonebook class source code:
package phonebook;
//import static com.oracle.util.Checksums.update;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public class Phonebook extends javax.swing.JFrame {
private String search;
public Phonebook() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-
BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
tfaddress = new javax.swing.JTextField();
tfname = new javax.swing.JTextField();
tfnumber = new javax.swing.JTextField();
btnsave = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
tfsearch = new javax.swing.JTextField();
btnedit = new javax.swing.JButton();
btnshow = new javax.swing.JButton();
btndelete = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
btnload = new javax.swing.JButton();
jMenuBar2 = new javax.swing.JMenuBar();
jMenu3 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem4 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(0, 153, 153));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jPanel1.setLayout(null);
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel2.setText("Name:");
jPanel1.add(jLabel2);
jLabel2.setBounds(10, 10, 50, 40);
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel3.setText("Number:");
jPanel1.add(jLabel3);
jLabel3.setBounds(10, 50, 70, 40);
tfaddress.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfaddressActionPerformed(evt);
}
});
jPanel1.add(tfaddress);
tfaddress.setBounds(90, 100, 130, 30);
tfname.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfnameActionPerformed(evt);
}
});
jPanel1.add(tfname);
tfname.setBounds(90, 20, 130, 30);
tfnumber.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfnumberActionPerformed(evt);
}
});
jPanel1.add(tfnumber);
tfnumber.setBounds(90, 60, 130, 30);
btnsave.setBackground(new java.awt.Color(0, 204, 204));
btnsave.setText("Save");
btnsave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsaveActionPerformed(evt);
}
});
jPanel1.add(btnsave);
btnsave.setBounds(150, 150, 73, 30);
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jLabel1.setBackground(new java.awt.Color(153, 153, 255));
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel1.setText("Search:");
tfsearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tfsearchActionPerformed(evt);
}
});
btnedit.setText("Edit");
btnedit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btneditActionPerformed(evt);
}
});
btnshow.setText("Show");
btnshow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnshowActionPerformed(evt);
}
});
btndelete.setText("Delete");
btndelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btndeleteActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(tfsearch, javax.swing.GroupLayout.PREFERRED_SIZE, 173,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
.addComponent(btndelete)
.addGap(28, 28, 28)
.addComponent(btnedit, javax.swing.GroupLayout.PREFERRED_SIZE, 63,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnshow)))
.addContainerGap(27, Short.MAX_VALUE)) );
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfsearch, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnedit, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnshow, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btndelete, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(20, Short.MAX_VALUE)) );
jPanel1.add(jPanel2);
jPanel2.setBounds(260, 20, 290, 120);
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jLabel4.setText("Address:");
jPanel1.add(jLabel4);
jLabel4.setBounds(10, 90, 70, 40);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Name", "Number", "Address"
}
));
jScrollPane1.setViewportView(jTable1);
jPanel1.add(jScrollPane1);
jScrollPane1.setBounds(0, 230, 570, 190);
btnload.setBackground(new java.awt.Color(0, 204, 204));
btnload.setText("Refresh");
btnload.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnloadActionPerformed(evt);
}
});
jPanel1.add(btnload);
btnload.setBounds(473, 183, 80, 30);
jMenu3.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I
, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("App Info");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem1);
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_
A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText("About");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem2);
jMenuBar2.add(jMenu3);
jMenu4.setText("Exit");
jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_
Q, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem4.setText("Exit");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu4.add(jMenuItem4);
jMenuBar2.add(jMenu4);
setJMenuBar(jMenuBar2);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 572,
javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 416,
Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btnsaveActionPerformed
// TODO add your handling code here:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook","root","");
Statement stmt=conn.createStatement();
String d1=tfname.getText();
String d2=tfnumber.getText();
String d3=tfaddress.getText();
String sql = "insert into book SET name='"+d1+"',number='"+d2+"',address='"+d3+"'";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(this,"Insert Data");
stmt.close();
conn.close();
}catch(Exception e){
JOptionPane.showMessageDialog(this," Data Not Insert !!!");
}
tfname.setText("");
tfnumber.setText("");
tfaddress.setText("");
}//GEN-LAST:event_btnsaveActionPerformed
private void btnloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btnloadActionPerformed
// TODO add your handling code here:
DefaultTableModel model;
model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook","root","");
Statement st = conn.createStatement();
String sql = "select * from book";
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
model.addRow(new Object[]{rs.getString("name"), rs.getString("number"),
rs.getString("address")});
}
rs.close();
st.close();
conn.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, " Data Not Insert !!!");
}
}//GEN-LAST:event_btnloadActionPerformed
private void btnshowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btnshowActionPerformed
// TODO add your handling code here:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook","root","");
Statement st = conn.createStatement();
String a=tfsearch.getText();
String sql = "select * from book where name='"+a+"'";
ResultSet rs = st.executeQuery(sql);
rs.next();
tfname.setText(rs.getString("name"));
tfnumber.setText(rs.getString("number"));
tfaddress.setText(rs.getString("address"));
search=rs.getString("id");
rs.close();
st.close();
conn.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, " View Data !!!"); }
}//GEN-LAST:event_btnshowActionPerformed
private void btneditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btneditActionPerformed
// TODO add your handling code here:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook","root","");
Statement stmt=conn.createStatement();
String d4=tfsearch.getText();
String d1=tfname.getText();
String d2=tfnumber.getText();
String d3=tfaddress.getText();
String sql = "Update book set name='"+d1+"', number='"+d2+"',address='"+d3+"' where
name='"+d4+"'";
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(this,"Edit Data");
stmt.close();
conn.close();
}catch(Exception e){
JOptionPane.showMessageDialog(this," Data Not Insert !!!");
}
}//GEN-LAST:event_btneditActionPerformed
private void btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btndeleteActionPerformed
// TODO add your handling code here:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn
=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook","root","");
Statement stmt=conn.createStatement();
String a=tfsearch.getText();
String sql = "delete from book where name='"+a+"'";
int P = JOptionPane.showConfirmDialog(null," Are you sure want to delete
?","Confirmation",JOptionPane.YES_NO_OPTION);
try{
if (P==0){
stmt.executeUpdate(sql);
JOptionPane.showMessageDialog(null, "Record Sucessfully Deleted");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
stmt.close();
conn.close();
}catch(Exception e){
JOptionPane.showMessageDialog(this," Data Not Insert !!!");
}
}//GEN-LAST:event_btndeleteActionPerformed
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jMenuItem1ActionPerformed
appinfo obj = new appinfo();
obj.setVisible(true);
this.setVisible(false);
}//GEN-LAST:event_jMenuItem1ActionPerformed
private void tfnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_tfnameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfnameActionPerformed
private void tfsearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_tfsearchActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfsearchActionPerformed
private void tfnumberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_tfnumberActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfnumberActionPerformed
private void tfaddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_tfaddressActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tfaddressActionPerformed
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jMenuItem4ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jMenuItem4ActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
about obj = new about();
obj.setVisible(true);
this.setVisible(false);
}//GEN-LAST:event_jMenuItem2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Phonebook.class.getName()).log(java.util.logging.Level.SEV
ERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Phonebook.class.getName()).log(java.util.logging.Level.SEV
ERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Phonebook.class.getName()).log(java.util.logging.Level.SEV
ERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Phonebook.class.getName()).log(java.util.logging.Level.SEV
ERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Phonebook().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btndelete;
private javax.swing.JButton btnedit;
private javax.swing.JButton btnload;
private javax.swing.JButton btnsave;
private javax.swing.JButton btnshow;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField tfaddress;
private javax.swing.JTextField tfname;
private javax.swing.JTextField tfnumber;
private javax.swing.JTextField tfsearch;
// End of variables declaration//GEN-END:variables
}
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(40, 40, 40)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(209, Short.MAX_VALUE))) );
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 443,
Short.MAX_VALUE) );
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
if("nuralam".equals(jTextField1.getText()) &&
"nurlyl".equals(jPasswordField1.getText())){
new Phonebook().setVisible(true);
this.setVisible(false);
}else{
JOptionPane.showMessageDialog(this,"Wrong input");
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed
Database Connection:
add
add add
http://dev.mysql.com/downloads/connector/j/5.1.html connector
window mysql connector select
Lirabraryte connector add
Save ( ):
Name Number Address
Nur-alam 01737-867700 Muhammedpur,Dhaka
Show ( ):
Show
www.bookbd.info
www.bookbd.info
www.bookbd.info
infobook7@gmail.com.
ACM)
www.bookbd.info
ক্ষ
infobook7@gmail.com