JAVA MANUAL OF GUI
PRACTICAL MANUAL ON JAVA
GUI
1
Page
JAVA MANUAL OF GUI
1. Create an interesting and appealing Swing GUI application and database to
Save and Update the stUdents records in the database. With the following
Fields: Sno, Names, Address and Date.
SQL DATABASE;
create database JAVALB1;
use JAVALB1;
create table JAVA1(
Sno INT,
Names VARCHAR(50),
Address VARCHAR(50),
Date VARCHAR(50),
primary key (Sno));
SELECT * FROM JAVA1;
SAVE BUTTON;
2
Page
JAVA MANUAL OF GUI
String password = "123";
try{
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, userName,
password);
String sql = "INSERT INTO JAVA1"
+"(Sno,Names,Address,Date)"
+"Values(?,?,?,?)";
PreparedStatement PST = conn.prepareStatement(sql);
PST.setString(1, TXT1.getText());
PST.setString(2, TXT2.getText());
PST.setString(3, TXT3.getText());
PST.setString(4, TXT4.getText());
PST.executeUpdate();
JOptionPane.showMessageDialog(null, "SAVED SUCCESSFULLY!");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
} // TODO add your handling code here:
}
UPDATE BUTTON;
3
Page
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
4
Page
JAVA MANUAL OF GUI
catch(HeadlessException | ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
2. Create a an interesting and appealing Swing GUI application and database to
Save and View the EmployEE records in the database. With the following
Fields: EmpNo, Names, Address and Designation.
SQL DATABASE;
SAVE BUTTON;
5
Page
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
6
Page
JAVA MANUAL OF GUI
7
Page
JAVA MANUAL OF GUI
JOptionPane.showMessageDialog(this, message, "EMPLOYEE RECORDS",
JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "No data found for the given EmpNo", "Error",
JOptionPane.ERROR_MESSAGE);
}
} catch (HeadlessException | ClassNotFoundException | SQLException e) {
JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
3. Create a an interesting and appealing Swing GUI application and database
to Save and Delete the Patients records in the database. With the following
Fields: PatientNo, Names, Ward and Department.
8
SQL DATABASE;
Page
create database JAVALB3;
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
USE JAVALB3;
create table JAVA3(
PatientNo INT,
Names VARCHAR(50),
Ward VARCHAR(50),
Department VARCHAR(50),
PRIMARY KEY(PatientNo));
SELECT * FROM JAVA3;
SAVE BUTTON;
9
Page
JAVA MANUAL OF GUI
PST.setString(2, TXT2.getText());
PST.setString(3, TXT3.getText());
PST.setString(4, TXT4.getText());
PST.executeUpdate();
JOptionPane.showMessageDialog(null, "SAVED SUCCESSFULLY!");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
} // TODO add your handling code here:
}
DELETE BUTTON;
10
Page
JAVA MANUAL OF GUI
PST.setString(1, TXT1.getText());
PST.executeUpdate();
JOptionPane.showMessageDialog(null, "delete SUCCESSFULLY!");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
}
// TODO add your handling code here:
}
11
Page
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
4. Create a an interesting and appealing Swing GUI application and database to
Save and Clear the Products records in the database. With the following
Fields: ProductNo, PNames, Type and Price.
SQL DATABASE;
create database JAVALB4;
USE JAVALB4;
create table JAVA4(
ProductNo INT,
PNames VARCHAR(50),
Type VARCHAR(50),
Price VARCHAR(50),
PRIMARY KEY(ProductNo));
SELECT * FROM JAVA4;
SAVE BUTTON;
12
Page
JAVA MANUAL OF GUI
try{
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, userName, password);
String sql = "INSERT INTO JAVA4"
+"(ProductNo,PNames,Type,Price)"
+"Values(?,?,?,?)";
PreparedStatement PST = conn.prepareStatement(sql);
PST.setString(1, TXT1.getText());
PST.setString(2, TXT2.getText());
PST.setString(3, TXT3.getText());
PST.setString(4, TXT4.getText());
PST.executeUpdate();
JOptionPane.showMessageDialog(null, "SAVED SUCCESSFULLY!");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
} // TODO add your handling code here:
}
CLEAR BUTTON;
13
Page
JAVA MANUAL OF GUI
// TODO add your handling code here:
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String
url="jdbc:sqlserver://localhost:1433;databaseName=JAVALB4;encrypt=true;trustServerCertificate=true";
String userName = "enock";
String password = "123";
try{
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, userName, password);
String sql = "delete from JAVA4 where ProductNo=?";
PreparedStatement PST = conn.prepareStatement(sql);
PST.setString(1, TXT1.getText());
PST.executeUpdate();
JOptionPane.showMessageDialog(null, "delete SUCCESSFULLY!");
}
catch(Exception e){
JOptionPane.showMessageDialog(this, e.getMessage());
}
// TODO add your handling code here:
}
14
Page
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
5. With the following Fields: ProductNo, PNames, Type and Price. 5 Create an
interesting and appealing Swing GUI application and database to Save and
Exit the Bank Deposit records in the database. With the following Fields:
DepositNo, Names, amount and Date.
SQL DATABASE;
create database JAVALB5;
USE JAVALB5;
create table JAVA5(
DepositNo INT,
Names VARCHAR(50),
amount VARCHAR(50),
Date VARCHAR(50),
PRIMARY KEY(DepositNo));
SELECT * FROM JAVA5;
Save button;
15
Page
ANOCK ENOCK GEORGE
JAVA MANUAL OF GUI
16
Page
JAVA MANUAL OF GUI
EXIT BUTTON;
The exit button escapes from the GUI.
CODE FOR THE EXIT BUTTON;
private void btnEXITActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);// TODO add your handling code here:
}
END.
17
Page
ANOCK ENOCK GEORGE