123
MC0612 – ADVANCE JAVA PROGRAMMING LAB MCA IV-SEMESTER ACADEMIC YEAR: 2012-2013 REG. NO.: 3521130023 Under the Guidance of Mr.Ramesh Kumar Pandey Mr.P.Shivraj (Assistant Professor) (Assistant Professor) 1

Adv. Java Lab File

Embed Size (px)

Citation preview

MC0612 – ADVANCE JAVA PROGRAMMING LAB

MCA IV-SEMESTER

ACADEMIC YEAR: 2012-2013

REG. NO.: 3521130023

Under the Guidance of

Mr.Ramesh Kumar Pandey Mr.P.Shivraj (Assistant Professor) (Assistant Professor)

DEPARTMENT OF COMPUTER APPLICATIONSSRM UNIVERSITY NCR CAMPUS,

MODI NAGAR, GHAZIABAD-201204.

1

Department of Master of Computer Applications

NAME : Nitesh Kumar

REGISTRATION NO : 3521130023

SECTION : A

SUBJECT CODE /TITLE : MC0612/ ADVANCE JAVA PROGRAMMING

SEMESTER : IV

Academic Year 2012 – 2013

SRM UNIVERSITY

MODINAGAR, GHAZIABAD – 201204

2

SRM INSTITUTE OF MANAGEMENT & TECHNOLOGY

(SRM UNIVERSITY)MODINAGAR, GHAZIABAD 201204

Department of Master of Computer Application

Register No: 3521130023

BONAFIDE CERTIFICATE

This is to certify that NITESH KUMAR of IInd year MCA completed the

Advanced Java Programming Lab in the SRM Institute of Management &

Technology, Modinagar during the academic year 2012-13.

LAB INCHARGE HEAD OF THE DEPARTMENT

Submitted for the examination held on ………………… in SRM

Institute of management & technology, Modinagar - 201204

EXAMINER- 1 EXAMINER -2

3

DEPARTMENT OF COMPUTER APPLICATIONS

4

SRM UNIVERSITY NCR CAMPUS,MODI NAGAR, GHAZIABAD-201204.

SUBJECT : ADVANCE JAVA PROGRAMMING LAB SUBJECT CODE : MC0612

SEMESTER : IV CLASS : MCA

HOURS / WEEK : 5 HOURS

ExpNo.

DATE Experiment Title Page No

1 09-01-2012 Tabbed Pane using Java Swing 5

2 09-01-2012 Scroll Pane using Java Swing 8

3 10-01-2012 Table using Java Swing 10

4 10-01-2012 Tree using Java Swing 12

5 17-01-2012 Jbutton using Java Swing 14

6 17-01-2012 Text Field using Java Swing 16

7 23-01-2012 Combobox using Java Swing 18

8 23-01-2012 Client/Server using RMI 20

9 23-01-2012 Server Content using RMI Applet 22

10 22-02-2012 Factorial using JSP 25

11 27-02-2012 Palindrome using JSP 28

12 05-03-2012 Prime Number using JSP 30

13 13-03-2012 Temperature Conversion using JSP 34

14 19-03-2012 Simple Array using JSP 37

15 20-03-2012 Display Week Days using JSP 42

16 21-01-2012 Personal Information using Java Bean 40

17 21-01-2012 Enrollment Form Using Java Bean 52

18 30-01-2012 Calendar using Java Bean 75

19 30-01-2012 Table using Java Bean 77

20 13-02-2012 Date and Time using Servlet 81

21 13-02-2012 Servlet getRequest() method 83

22 14-02-2012 Servlet postRequest() method 86

23 14-02-2012 Insert Student Data using JDBC 88

24 15-02-2012 Retrieve Student Data using JDBC 90

25 21-02-2012 Delete Student Data using JDBC 92

5

TABBED PANE USING JAVA SWING

Aim: To write a program to display a tabbed pane using java swing.

Algorithm:

Step 1: Start

Step 2: Create a JTabbedPane object.

Step 3: Call addTab( ) to add a tab to the pane. (The arguments to this method define

the title of the tab and the component it contains.)

Step 4: Repeat step 2 for each tab.

Step 5: Add the tabbed pane to the content pane of the applet.

Step 6: End

Program:

import javax.swing.*;/*<applet code="JTabbedPaneDemo" width=400 height=100></applet>*/public class JTabbedPaneDemo extends JApplet {public void init() {JTabbedPane jtp = new JTabbedPane();jtp.addTab("Cities", new CitiesPanel());jtp.addTab("Colors", new ColorsPanel());jtp.addTab("Flavors", new FlavorsPanel());getContentPane().add(jtp);}}class CitiesPanel extends JPanel {public CitiesPanel() {JButton b1 = new JButton("New York");add(b1);JButton b2 = new JButton("London");add(b2);JButton b3 = new JButton("Hong Kong");add(b3);JButton b4 = new JButton("Tokyo");add(b4);

6

EXP. NO/DATE 1/09-01-2012

}}class ColorsPanel extends JPanel {public ColorsPanel() {JCheckBox cb1 = new JCheckBox("Red");add(cb1);JCheckBox cb2 = new JCheckBox("Green");add(cb2);JCheckBox cb3 = new JCheckBox("Blue");add(cb3);}}class FlavorsPanel extends JPanel {public FlavorsPanel() {JComboBox jcb = new JComboBox();jcb.addItem("Vanilla");jcb.addItem("Chocolate");jcb.addItem("Strawberry");add(jcb);}}

Result: The program for tabbed pane is successfully executed.

Output:

7

8

SCROLL PANE USING JAVA SWING

Aim: To write a program to display Scroll Pane using java swing.

Algorithm:

Step 1: Start

Step 2: Create a JComponent object.

Step 3: Create a JScrollPane object. (The arguments to the constructor specify the

component and the policies for vertical and horizontal scroll bars.)

Step 4: Add the scroll pane to the content pane of the applet.

Step 5: End

Program:

import java.awt.*;import javax.swing.*;/* <applet code="JScrollPaneDemo" width=300 height=250> </applet> */public class JScrollPaneDemo extends JApplet {public void init() { // Get content paneContainer contentPane = getContentPane();contentPane.setLayout(new BorderLayout());// Add 400 buttons to a panelJPanel jp = new JPanel();jp.setLayout(new GridLayout(20, 20));int b = 0;for(int i = 0; i < 20; i++) {for(int j = 0; j < 20; j++) {jp.add(new JButton("Button " + b));++b;}}// Add panel to a scroll paneint v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;JScrollPane jsp = new JScrollPane(jp, v, h);// Add scroll pane to the content panecontentPane.add(jsp, BorderLayout.CENTER);

9

EXP. NO/DATE 2/09-01-2012

}}Result: The program for the Scroll Pane is successfully executed.

Output:

10

TABLE USING JAVA SWING

Aim: To write a program to print table with 3 column using java swing

Algorithm:

Step 1: Create a JTable object.

Step 2 : Create a JScrollPane object.

Step 3: Add the table to the scroll pane.

Step 4 : Add the scroll pane to the content pane of the applet.

Program:

import java.awt.*;import javax.swing.*;/*<applet code="JTableDemo" width=400 height=200></applet>*/public class JTableDemo extends JApplet {public void init() {// Get content paneContainer contentPane = getContentPane();// Set layout managercontentPane.setLayout(new BorderLayout());// Initialize column headingsfinal String[] colHeads = { "Name", "Phone", "Fax" };// Initialize datafinal Object[][] data = {{ "Gail", "4567", "8675" },{ "Ken", "7566", "5555" },{ "Viviane", "5634", "5887" },{ "Melanie", "7345", "9222" },{ "Anne", "1237", "3333" },{ "John", "5656", "3144" },{ "Matt", "5672", "2176" },{ "Claire", "6741", "4244" },{ "Erwin", "9023", "5159" },{ "Ellen", "1134", "5332" },{ "Jennifer", "5689", "1212" },{ "Ed", "9030", "1313" },

11

EXP. NO/DATE 3/10-02-2012

{ "Helen", "6751", "1415" }};// Create the tableJTable table = new JTable(data, colHeads);// Add table to a scroll paneint v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;JScrollPane jsp = new JScrollPane(table, v, h);// Add scroll pane to the content panecontentPane.add(jsp, BorderLayout.CENTER);}}

Result: The program for the Table using swing is successfully executed.

Output

12

TREE USING JAVA JTREE Demo SWING

Aim: To write a program to display tree using java swing.

Algorithm:

Step 1: Create a JTree object.

Step 2: Create a JScrollPane object.

Step 3: Add the tree to the scroll pane.

Step 4: Add the scroll pane to the content pane of the applet.

Program:

import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.tree.*;/*<applet code="JTreeDemo" width=400 height=200></applet>*/public class JTreeDemo extends JApplet {JTree tree;JTextField jtf;public void init() {

// Get content paneContainer contentPane = getContentPane();// Set layout managercontentPane.setLayout(new BorderLayout());// Create top node of treeDefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");// Create subtree of "A"DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");top.add(a);DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");a.add(a1);DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");a.add(a2);// Create subtree of "B"DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");top.add(b);DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");b.add(b1);

13

EXP. NO/DATE 4/10-01-2012

DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");b.add(b2);DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");b.add(b3);// Create treetree = new JTree(top);// Add tree to a scroll paneint v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;JScrollPane jsp = new JScrollPane(tree, v, h);// Add scroll pane to the content panecontentPane.add(jsp, BorderLayout.CENTER);

// Add text field to appletjtf = new JTextField("", 20);contentPane.add(jtf, BorderLayout.SOUTH);// Anonymous inner class to handle mouse clickstree.addMouseListener(new MouseAdapter() {public void mouseClicked(MouseEvent me) {doMouseClicked(me);}});}void doMouseClicked(MouseEvent me) {TreePath tp = tree.getPathForLocation(me.getX(), me.getY());if(tp != null)jtf.setText(tp.toString());elsejtf.setText("");}}

Result: The program for the Tree using java swing is successfully executed.

Output:

14

JBUTTON USING JAVA SWING

Aim: To write program to display JButton using java swing.

Algorithm:

Step 1: Create a JComponent object.

Step 2: Create a JButton object.

Step 3: Add the ActionListener event to the Jbutton.

Step 4: Add the button to the content pane of the applet.

Program:

import java.awt.*;import java.awt.event.*;import javax.swing.*;

/* <applet code="JButtonDemo" width=570 height=400>

15

EXP. NO/DATE 5/17-01-2012

</applet>

*/public class JButtonDemo extends JApplet implements ActionListener {

JTextField jtf;

public void init() { setSize(300, 300); Container con = getContentPane(); con.setLayout(new FlowLayout());

JButton jb1 = new JButton("Apple", new ImageIcon("Apple.jpg")); jb1.addActionListener(this);

JButton jb2 = new JButton("India", new ImageIcon("India.jpg")); jb2.addActionListener(this);

JButton jb3 = new JButton("Love", new ImageIcon("Love.jpg")); jb3.addActionListener(this);

JButton jb4 = new JButton("VAIO", new ImageIcon("VAIO.jpg")); jb4.addActionListener(this);

con.add(jb1); con.add(jb2); con.add(jb3); con.add(jb4);

jtf = new JTextField(15); jtf.setEditable(false);

con.add(jtf);

}

@Override

public void actionPerformed(ActionEvent e) {

jtf.setText(e.getActionCommand());

}

}

Result: The program for the JButton using java swing is successfully executed.

Output

16

TEXT FIELD USING JAVA SWING

Aim: To write a program to display Text Field using java swing.

Algorithm:

Step 1: Create a JComponent object.

Step 2: Create a JTextField object..

Step 3: Add text field to the content pane of the applet

Program:

import java.awt.*;

17

EXP. NO/DATE 6/17-01-2012

import javax.swing.*;/*<applet code="JTextFieldDemo" width=300 height=50></applet>*/public class JTextFieldDemo extends JApplet {JTextField jtf;public void init() {// Get content paneContainer contentPane = getContentPane();contentPane.setLayout(new FlowLayout());// Add text field to content panejtf = new JTextField(15);contentPane.add(jtf);}}

Result: The program for the TextField using java swing is successfully executed.

Output:

18

COMBOBOX USING JAVA SWING

Aim: To write a program to find the factorial of a given number and display its result.

Algorithm:

Step 1: Create a JComponent object.

Step 2: Create a JComboBox object..

Step 3: Add items to the ComboBox

Step 4: Add ComboBox to the content pane of the applet

Program:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

/*<applet code="JComboBoxDemo" width=300 height=100>

</applet>*/

public class JComboBoxDemo extends JApplet

implements ItemListener {

JLabel jl;

ImageIcon france, germany, italy, japan;

public void init() {

// Get content pane

Container contentPane = getContentPane();

contentPane.setLayout(new FlowLayout());

JComboBox jc = new JComboBox();

jc.addItem("Apple");

jc.addItem("India");

jc.addItem("Love");

jc.addItem("VAIO");

19

EXP. NO/DATE 7/23-01-2012

jc.addItemListener(this);

contentPane.add(jc);

// Create label

jl = new JLabel(new ImageIcon("Apple.jpg"));

contentPane.add(jl);

}

public void itemStateChanged(ItemEvent ie) {

String s = (String) ie.getItem();

jl.setIcon(new ImageIcon(s + ".jpg"));

}

}

Result: The program for the ComboBox using java swing is successfully executed

Output:

20

CLIENT/SERVER USING RMI

Aim: To write a program to display Product information in client/server program in

RMI.

Algorithm:

Step 1: - Start the program

Step 2: - Write a Remote Interface Program

Step 3: - Write a Server Program

Step 4: - Write a Client Program

Step 5: - Compile the server and client program

Step 6: - Run RMIC and create the stub and Skelton files

Step 7: - Run the RMI registry server

Step 8: - Run the server program

Step 9: - Run the Client program

Step 10: - End the program

Program1: AddServerInt.java

import java.rmi.Remote;import java.rmi.RemoteException;public interface AddServerInt extends Remote{

public double add(double d1,double d2) throws RemoteException ;}

Program2: AddServerImpl.javaimport java.rmi.RemoteException;import java.rmi.server.UnicastRemoteObject;public class AddServerImpl extends UnicastRemoteObject implements AddServerInt {

protected AddServerImpl() throws RemoteException {}public double add(double d1, double d2) throws RemoteException {

return d1 + d2;}

}

Program3 : AddServer.java

import java.rmi.Naming;public class AddServer {

21

EXP. NO/DATE 8/23-01-2012

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

AddServerImpl addServerImpl=new AddServerImpl();Naming.rebind("AddServer", addServerImpl);

} catch (Exception e) {System.out.println("Exception"+e);

}}}

Program4: AddClient.java

import java.rmi.Naming;

public class AddClient {

public static void main(String[] args) {

try {

String addserverurl="rmi://"+args[0]+"/AddServer";

AddServerInt addServerInt=(AddServerInt)Naming.lookup(addserverurl);

System.out.println("1st number is: " +args[1]);

double d1= Double.valueOf(args[1]).doubleValue();

System.out.println("2nd number is: " +args[2]);

double d2= Double.valueOf(args[2]).doubleValue();

System.out.println("The sum is : "+addServerInt.add(d1, d2));

} catch (Exception e) {

System.out.println("Exception : "+e);

}

}

}

Result: The program for the Client/Server using RMI is successfully executed

Run:

java AddClient localhost 35 67

Output:

1st number is: 352nd number is: 67The sum is : 102.0

22

SERVER CONTENT USING RMI APPLET

Aim: To write a program to display the content of server by using RMI with Applet.

Algorithm:

Step 1: - Start the program

Step 2: - Write a Remote Interface Program

Step 3: - Write a Server Program

Step 4: - Write a Client Program and create HTML file

Step 5: - Compile the server and client program

Step 6: - Run RMIC and create the stub and Skelton files

Step 7: - Run the RMI registry server

Step 8: - Run the server program

Step 9: - Run the Client program with appletviewer command.

Step 10: - End the program

Program for Server side

Program1: Server.java

import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;import java.rmi.server.UnicastRemoteObject;public class Server implements RemoteInterface{ public String getMessage() { return "Current Date At server : "+new java.util.Date(); } public static void main(String args[]) { try { Registry registry =LocateRegistry.getRegistry(RemoteInterface.REGISTRY_PORT)RemoteInterface remoteReference = (RemoteInterface)UnicastRemoteObject.exportObject(new Server()); registry.rebind(RemoteInterface.REGISTRY_NAME, remoteReference); } catch (Exception e)

23

EXP. NO/DATE 9/23-01-2012

{ throw new RuntimeException(e); } }}

Program2 : RemoteInterface.java

import java.rmi.Remote;import java.rmi.RemoteException;public interface RemoteInterface extends Remote{ String REGISTRY_NAME = "RMI_Example"; int REGISTRY_PORT = 3273; String getMessage() throws RemoteException;}

Program for client side

Program3: ClientApplet.javaimport java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;import javax.swing.JApplet;import javax.swing.JLabel;/*<applet code="ClientApplet" height="50" width="150"></applet>*/public class ClientApplet extends JApplet{ public void init() { try { Registry registry = LocateRegistry.getRegistry(getCodeBase().getHost(), RemoteInterface.REGISTRY_PORT); RemoteInterface remoteReference = (RemoteInterface) registry.lookup(RemoteInterface.REGISTRY_NAME); getContentPane().add(new JLabel(remoteReference.getMessage())); } catch (Exception e) { throw new RuntimeException(e); } }}

24

Html file to run the applet

Program4: applet.html<html> <head> <title>’Current Date' via an Applet using Java RMI</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <h1>'Hello World' via an Applet using Java RMI</h1> <p> If everything works correctly there should be an applet running below that says 'Hello World': </p> <p> <!-- Compatible with all modern browsers --> <applet code="ClientApplet" height="50" width="150"></applet> </p> </body></html>

Result: The program to display the content of server by using RMI with Applet.is

successfully executed

Output:

25

FACTORIAL USING JSP

Aim: To write a program to find the factorial of a given number and display its result.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for factorial inside the JSP directives in the body section.

Step 4: Run the program and enter number in the text field.

Step 5: Click Submit and display output in the web browser.

Program:

<html> <head> <title>Factorial Calculator</title> </head> <body> <form action="factorial.jsp" method="POST"> <table> <tr> <th>Factorial Calculator</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Factorial : </b><% if (request.getParameter("number") == null || request.getParameter("number") == "") { out.println(""); } else { try { int fact = 1; int n = Integer.parseInt(request.getParameter("number")); if (n == 0) { out.println("Facorial of 0=1"); } else { for (int i = n; i > 0; i--) { fact *= i;

26

EXP. NO/DATE 10/22-02-2012

} out.println("Factorial of " + n + "=" + fact); } } catch (Exception e) { out.println("Error" + e); } } %> </td>

</tr>

<tr>

<th><input name="calculate" type="submit" value="Calculate" size="10"></th>

</tr>

</table>

</form>

</body>

</html>

Result: The program for the Factorial using JSP is successfully executed.

Input:

27

Output:

28

PALINDROME USING JSP

Aim: To write a program to find whether a number is palindrome or not.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for factorial inside the JSP directives in the body section.

Step 4: Run the program and enter number in the text field.

Step 5: Click Submit and display output in the web browser.

Program:

<html> <head> <title>Palindrome Number Checker</title> </head> <body> <form action="palindrome.jsp" method="POST"> <table> <tr> <th>Palindrome Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if (request.getParameter("number") == null || request.getParameter("number") == "") { out.println(""); } else { try { int num = Integer.parseInt(request.getParameter("number")); int rev = 0; for (int i = num; i > 0;) { rev *= 10; rev += (i % 10); i /= 10; } if (num == rev) {

29

EXP. NO/DATE 11/27-02-2012

out.println(num + " is a Palindrome Number"); } else { out.println(num + " is Not a Palindrome Number"); }

} catch (Exception e) { out.println("Error : " + e); } } %> </td> </tr> <tr>

<th><input name="check" type="submit" value="Check"></th> </tr> </table> </form> </body></html>

Result: The program for the Palindrome number using JSP is successfully executed.

Input:

30

Output:

PRIME NUMBER USING JSP

Aim: To write a program to find whether a number is prime or not.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for finding prime number inside the JSP directives in the

body section.

Step 4: Run the program and display output in the web browser.

31

EXP. NO/DATE 12/05-02-2012

<html> <head> <title>Prime Number Checker</title> </head> <body> <form action="primenumber.jsp" method="POST"> <table> <tr> <th>Prime Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if (request.getParameter("number") == null || request.getParameter("number") == "") { out.println(""); } else { try { int num = Integer.parseInt(request.getParameter("number"));

if (isPrime(num)) { out.println(num + " is a Prime Number"); } else { out.println(num + " is Not a Prime Number"); }

} catch (Exception e) { out.println("Error : " + e); } } %> <%! boolean isPrime(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return false; } } return true; } %> </td> </tr> <tr>

32

<th><input name="check" type="submit" value="Check"></th> </tr> </table> </form>

</body></html><html> <head> <title>Prime Number Checker</title> </head> <body> <form action="primenumber.jsp" method="POST"> <table> <tr> <th>Prime Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if (request.getParameter("number") == null || request.getParameter("number") == "") { out.println(""); } else { try { int num = Integer.parseInt(request.getParameter("number"));

if (isPrime(num)) { out.println(num + " is a Prime Number"); } else { out.println(num + " is Not a Prime Number"); }

} catch (Exception e) { out.println("Error : " + e); } } %> <%! boolean isPrime(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return false; }

33

} return true; } %> </td> </tr> <tr>

<th><input name="check" type="submit" value="Check"></th> </tr> </table> </form>

</body></html>

Result: The program for the prime number using JSP is successfully executed.

Input:

Output:34

TEMPERATURE CONVERSION USING JSP

Aim: To write a program to convert temperature from Celsius to Fahrenheit.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for temperature conversion inside the JSP directives in the

body section.

Step 4: Run the program and display output in the web browser.

Program:

<html> <head> <title>Temperature Converter</title> </head> <body> <form action="tempcon.jsp" method="POST"> <table> <tr> <th>Temperature Converter</th>

35

EXP. NO/DATE 13/13-03-2012

</tr> <tr> <td>Enter Temperature in Celsius : <input type="text" name="temp" id="temp"> </td> </tr> <tr> <td> <b>Temperature in Fahrenheit : </b> <% if (request.getParameter("temp") == null || request.getParameter("temp") == "") { out.println(""); } else { try { double tempc = Double.parseDouble(request.getParameter("temp")); double tempf =((9*tempc)/5)+32; out.println(tempf); } catch (Exception e) { out.println("Error" + e); } } %> <sup>&deg;</sup>F </td> </tr> <tr>

<th><input name="Convert" type="submit" value="Convert"></th> </tr> </table> </form>

</body></html>Result: The program for the temperature conversion using JSP is successfully executed.

36

Input:

Output:

37

SIMPLE ARRAY USING JSP

Aim: To write a program to print simple array using JSP.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for simple array inside the JSP directives in the body section.

Step 4: Run the program and display output in the web browser.

Program:

<html> <head> <title>Simple Array</title> </head> <body> <h3>Elements of Array</h3>> <ol> <% String[] names = {"Ashish", "Ankur", "Nitesh", "Pandey", "Prabhat", "Nitin", "Sumit"}; for (String s : names) { out.println("<li>" + s + "</li>"); } %> </ol></body></html>

Result: The program for printing the array elements using JSP is successfully executed.

Output:

38

EXP. NO/DATE 14/19-03-2012

DISPLAY WEEK DAYS USING JSP

Aim: To write a program to print week days using JSP.

Algorithm:

Step 1: Write the html code in the JSP file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for week days using array inside the JSP directives in the

body section.

Step 4: Run the program and display output in the web browser.

Program:

<html> <head> <title>Days in Week</title>

39

EXP. NO/DATE 15/20-01-2012

</head> <body> <h3>Days of Week</h3> <ul> <% String[] days = {"Monday", "Tuesday", "Wednesday", "Thirsday", "Friday", "Saturday", "Sunday"}; for (String s : days) { out.println("<li>" + s + "</li>"); } %> </ul> </body></html>

Result: The program for the Factorial using JSP is successfully executed.

Output:

40

PERSONAL INFORMATION USING JAVA BEAN

Aim: To write a program to display personal information form using java bean.

Algorithm:

Step 1: Create new java application using Netbeans,

Step 2: Extends JFrame in the program.

Step 3: Add JLabels, JButtons,JTextFields into the JFrame to enter information.

Step 4: Run the program and display output in the appletviewer.

Program:

import javax.swing.JOptionPane;

/** * * @author Nitesh */public class PerInfo extends javax.swing.JFrame {

/** * Creates new form PerInfo */ public PerInfo() { initComponents(); initMyComponents(); }

private void initMyComponents() {

//Adding Data to Date of Birth Combo Box for (int i = 1; i <= 31; i++) { if (i < 10) { dobddcmb.addItem("0" + i); } else { dobddcmb.addItem("" + i); } } dobmmcmb.addItem("Jan"); dobmmcmb.addItem("Feb"); dobmmcmb.addItem("Mar"); dobmmcmb.addItem("Apr"); dobmmcmb.addItem("May");

41

EXP. NO/DATE 16/21-01-2012

dobmmcmb.addItem("Jun"); dobmmcmb.addItem("Jul"); dobmmcmb.addItem("Aug"); dobmmcmb.addItem("Sep"); dobmmcmb.addItem("Oct"); dobmmcmb.addItem("Nov"); dobmmcmb.addItem("Dec"); for (int i = 2014; i >= 1920; i--) { dobyycmb.addItem("" + i); } setLocationRelativeTo(null); }

private boolean validateFormData() {

if ((nameT.getText()).equals("")) { JOptionPane.showMessageDialog(this, "Enter name first!"); nameT.requestFocus(); return false; } if ((fnameT.getText()).equals("")) { JOptionPane.showMessageDialog(this, "Enter Father Name first!"); fnameT.requestFocus(); return false; } // Date Of Birth if (((String) (dobddcmb.getSelectedItem())).equalsIgnoreCase("Date")) { JOptionPane.showMessageDialog(this, "Select Date of Birth!"); dobddcmb.requestFocus(); return false; } if (((String) (dobmmcmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Month of Birth!"); dobmmcmb.requestFocus(); return false; } if (((String) (dobyycmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Year of Birth!"); dobyycmb.requestFocus(); return false; } //////////////////////////////////////////////////////////////////////// if ((mobileT.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter Mobile Number First!"); mobileT.requestFocus(); return false; } if ((emailT.getText()).equalsIgnoreCase("")) {

42

JOptionPane.showMessageDialog(this, "Enter Email Address First!"); emailT.requestFocus(); return false; } if ((addressT.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Please Enter the Address!"); addressT.requestFocus(); return false; } return true; }

/** * 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() {

RBG = new javax.swing.ButtonGroup(); Label = new javax.swing.JLabel(); nameL = new javax.swing.JLabel(); submitB = new javax.swing.JButton(); clearB = new javax.swing.JButton(); fnameL = new javax.swing.JLabel(); sexL = new javax.swing.JLabel(); dobL = new javax.swing.JLabel(); occL = new javax.swing.JLabel(); mobileL = new javax.swing.JLabel(); emailL = new javax.swing.JLabel(); addressL = new javax.swing.JLabel(); nameT = new javax.swing.JTextField(); fnameT = new javax.swing.JTextField(); occT = new javax.swing.JTextField(); mobileT = new javax.swing.JTextField(); emailT = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); addressT = new javax.swing.JTextArea(); sexMRadio = new javax.swing.JRadioButton(); sexFRadio = new javax.swing.JRadioButton(); dobddcmb = new javax.swing.JComboBox(); dobmmcmb = new javax.swing.JComboBox(); dobyycmb = new javax.swing.JComboBox(); exitB = new javax.swing.JButton();

RBG.add(sexMRadio);

43

RBG.add(sexFRadio);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Personal Information Management");

Label.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N Label.setForeground(new java.awt.Color(0, 153, 153)); Label.setText("Personal Infromation");

nameL.setText("Name");

submitB.setText("Submit"); submitB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { submitBActionPerformed(evt); } });

clearB.setText("Clear"); clearB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearBActionPerformed(evt); } });

fnameL.setText("Father Name");

sexL.setText("Sex");

dobL.setText("DOB");

occL.setText("Occupation");

mobileL.setText("Mobile");

emailL.setText("Email:");

addressL.setText("Address");

mobileT.setColumns(10);

addressT.setColumns(20); addressT.setRows(5); jScrollPane1.setViewportView(addressT);

sexMRadio.setSelected(true); sexMRadio.setText("Male");

44

sexFRadio.setText("Female");

dobddcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Date" }));

dobmmcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Month" }));

dobyycmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Year" }));

exitB.setText("Exit"); exitB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitBActionPerformed(evt); } });

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(70, 70, 70) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(nameL) .addComponent(fnameL) .addComponent(sexL) .addComponent(dobL) .addComponent(occL) .addComponent(mobileL) .addComponent(emailL) .addComponent(addressL)) .addGap(42, 42, 42) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane1) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(nameT, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE) .addComponent(fnameT) .addComponent(occT)

45

.addComponent(mobileT, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(sexMRadio) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(sexFRadio)) .addGroup(layout.createSequentialGroup() .addComponent(dobddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dobmmcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dobyycmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(emailT))) .addGroup(layout.createSequentialGroup() .addGap(90, 90, 90) .addComponent(Label)) .addGroup(layout.createSequentialGroup() .addGap(105, 105, 105) .addComponent(submitB) .addGap(18, 18, 18) .addComponent(clearB) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(exitB))) .addContainerGap(82, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) .addComponent(Label) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(nameL)

46

.addComponent(nameT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(fnameL) .addComponent(fnameT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sexL) .addComponent(sexMRadio) .addComponent(sexFRadio)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(dobL) .addComponent(dobddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dobmmcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dobyycmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(occL) .addComponent(occT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(mobileL) .addComponent(mobileT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

47

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(emailL) .addComponent(emailT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(addressL) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(10, 10, 10) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clearB) .addComponent(exitB) .addComponent(submitB)) .addContainerGap(55, Short.MAX_VALUE)) );

pack(); }// </editor-fold>

private void exitBActionPerformed(java.awt.event.ActionEvent evt) { dispose(); }

private void clearBActionPerformed(java.awt.event.ActionEvent evt) { nameT.setText(""); fnameT.setText(""); sexMRadio.setSelected(true); dobddcmb.setSelectedItem("Date"); dobmmcmb.setSelectedItem("Month"); dobyycmb.setSelectedItem("Year"); occT.setText(""); mobileT.setText(""); emailT.setText(""); addressT.setText(""); nameT.requestFocus(); }

private void submitBActionPerformed(java.awt.event.ActionEvent evt) { if(validateFormData()){ JOptionPane.showMessageDialog(this, "Record Added Successfully!");

48

clearBActionPerformed(evt); } //Use data to save at any particular place }

/** * @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(PerInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PerInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PerInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PerInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold>

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PerInfo().setVisible(true);

49

} }); } // Variables declaration - do not modify private javax.swing.JLabel Label; private javax.swing.ButtonGroup RBG; private javax.swing.JLabel addressL; private javax.swing.JTextArea addressT; private javax.swing.JButton clearB; private javax.swing.JLabel dobL; private javax.swing.JComboBox dobddcmb; private javax.swing.JComboBox dobmmcmb; private javax.swing.JComboBox dobyycmb; private javax.swing.JLabel emailL; private javax.swing.JTextField emailT; private javax.swing.JButton exitB; private javax.swing.JLabel fnameL; private javax.swing.JTextField fnameT; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel mobileL; private javax.swing.JTextField mobileT; private javax.swing.JLabel nameL; private javax.swing.JTextField nameT; private javax.swing.JLabel occL; private javax.swing.JTextField occT; private javax.swing.JRadioButton sexFRadio; private javax.swing.JLabel sexL; private javax.swing.JRadioButton sexMRadio; private javax.swing.JButton submitB; // End of variables declaration }

Result: The program to display personal information form using java bean is successfully executed.

Output:

50

51

52

ENROLLMENT FORM USING JAVA BEAN

Aim: To write a program to design Enrollment form using java bean.

Algorithm:

Step 1: Create new java application using Netbeans,

Step 2: Extends JFrame in the program.

Step 3: Add JLabels, JButtons,JTextFields into the JFrame to enter information.

Step 4: Run the program and display output in the appletviewer.

Program:

package bean;

import javax.swing.*;

public class Registration extends javax.swing.JFrame {

public Registration() {

initComponents();

initMyComponents();

}

private boolean validateFormData() {

if ((treg_no.getText()).equals("")) {

JOptionPane.showMessageDialog(this, "Enter Registration no. first!");

treg_no.requestFocus();

return false;

}

if (((String) (coursecmb.getSelectedItem())).equalsIgnoreCase("Course")) {

JOptionPane.showMessageDialog(this, "Select Course first!");

coursecmb.requestFocus();

53

EXP. NO/DATE 17/21-01-2012

return false;

} if (((String) (semestercmb.getSelectedItem())).equalsIgnoreCase("Semester")) { JOptionPane.showMessageDialog(this, "Select semester first!"); semestercmb.requestFocus(); return false; } // if (((String) (doaddcmb.getSelectedItem())).equalsIgnoreCase("Date")) { JOptionPane.showMessageDialog(this, "Select Date of Admission!"); doaddcmb.requestFocus(); return false; } if (((String) (doammcmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Month of Admission!"); doammcmb.requestFocus(); return false; } if (((String) (doayearcmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Year of Admission!"); doayearcmb.requestFocus(); return false; } ////////////////////////////////////////////////////////////////////////

if ((tfirstname.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter First Name!"); tfirstname.requestFocus(); return false; } if ((tlastname.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter Last Name!"); tlastname.requestFocus(); return false; } if ((tfathername.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter Father Name!"); tfathername.requestFocus(); return false;

} // Date Of Birth

54

if (((String) (dobddcmb.getSelectedItem())).equalsIgnoreCase("Date")) { JOptionPane.showMessageDialog(this, "Select Date of Birth!"); dobddcmb.requestFocus(); return false; } if (((String) (dobmmcmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Month of Birth!"); dobmmcmb.requestFocus(); return false; } if (((String) (dobyearcmb.getSelectedItem())).equalsIgnoreCase("Month")) { JOptionPane.showMessageDialog(this, "Select Year of Birth!"); dobyearcmb.requestFocus(); return false; } //////////////////////////////////////////////////////////////////////// if ((tmobile.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter Mobile Number First!"); tmobile.requestFocus(); return false; } if ((temail.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Enter Email Address First!"); temail.requestFocus(); return false; } if ((taddress.getText()).equalsIgnoreCase("")) { JOptionPane.showMessageDialog(this, "Please Enter the Address!"); temail.requestFocus(); return false; } return true; }

private void initMyComponents() { setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH); //Adding Data to Date of Birth Combo Box for (int i = 1; i <= 30; i++) { if (i < 10) { doaddcmb.addItem("0" + i); } else { doaddcmb.addItem("" + i);

55

} } doammcmb.addItem("Jan"); doammcmb.addItem("Feb"); doammcmb.addItem("Mar"); doammcmb.addItem("Apr"); doammcmb.addItem("May"); doammcmb.addItem("Jun"); doammcmb.addItem("Jul"); doammcmb.addItem("Aug"); doammcmb.addItem("Sep"); doammcmb.addItem("Oct"); doammcmb.addItem("Nov"); doammcmb.addItem("Dec"); for (int i = 2014; i >= 1950; i--) { doayearcmb.addItem("" + i); } //Adding Data to Date of Birth Combo Box for (int i = 1; i <= 30; i++) { if (i < 10) { dobddcmb.addItem("0" + i); } else { dobddcmb.addItem("" + i); } } dobmmcmb.addItem("Jan"); dobmmcmb.addItem("Feb"); dobmmcmb.addItem("Mar"); dobmmcmb.addItem("Apr"); dobmmcmb.addItem("May"); dobmmcmb.addItem("Jun"); dobmmcmb.addItem("Jul"); dobmmcmb.addItem("Aug"); dobmmcmb.addItem("Sep"); dobmmcmb.addItem("Oct"); dobmmcmb.addItem("Nov"); dobmmcmb.addItem("Dec"); for (int i = 2014; i >= 1950; i--) { dobyearcmb.addItem("" + i); } treg_no.requestFocus(); }

56

/** * 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() {

javax.swing.ButtonGroup sexBG = new javax.swing.ButtonGroup(); jPanel1 = new javax.swing.JPanel(); jLabel13 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); treg_no = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); tfirstname = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); tlastname = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); tfathername = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); tmobile = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); temail = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); taddress = new javax.swing.JTextArea(); addB = new javax.swing.JButton(); clearB = new javax.swing.JButton(); cancelB = new javax.swing.JButton(); coursecmb = new javax.swing.JComboBox(); jLabel9 = new javax.swing.JLabel(); dobpan = new javax.swing.JPanel(); dobddcmb = new javax.swing.JComboBox(); dobmmcmb = new javax.swing.JComboBox(); dobyearcmb = new javax.swing.JComboBox(); jLabel10 = new javax.swing.JLabel(); semestercmb = new javax.swing.JComboBox();

57

jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); doapan = new javax.swing.JPanel(); doaddcmb = new javax.swing.JComboBox(); doammcmb = new javax.swing.JComboBox(); doayearcmb = new javax.swing.JComboBox(); exitB = new javax.swing.JButton(); femalerdb = new javax.swing.JRadioButton(); malerdb = new javax.swing.JRadioButton(); jPanel4 = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Student Form");

jPanel1.setPreferredSize(new java.awt.Dimension(605, 205)); jPanel1.addAncestorListener(new javax.swing.event.AncestorListener() { public void ancestorMoved(javax.swing.event.AncestorEvent evt) { jPanel1AncestorMoved(evt); } public void ancestorAdded(javax.swing.event.AncestorEvent evt) { jPanel1AncestorAdded(evt); } public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { } });

jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bean/hstudent.jpg"))); // NOI18N jPanel1.add(jLabel13);

getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

jPanel2.setPreferredSize(new java.awt.Dimension(25, 10));

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 25, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup(

58

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 509, Short.MAX_VALUE) );

getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);

jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(204, 0, 204), new java.awt.Color(0, 255, 153)), "Student Registration")); jPanel3.setToolTipText("Student Registration Form"); jPanel3.setName("Student Registration"); // NOI18N jPanel3.setPreferredSize(new java.awt.Dimension(1000, 400));

jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Registration No.");

treg_no.setHorizontalAlignment(javax.swing.JTextField.CENTER); treg_no.setToolTipText("Enter Registration Number(10-Digits Only)");

jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("First Name");

tfirstname.setHorizontalAlignment(javax.swing.JTextField.CENTER); tfirstname.setToolTipText("Enter First Name");

jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel3.setText("Last Name");

tlastname.setHorizontalAlignment(javax.swing.JTextField.CENTER); tlastname.setToolTipText("Enter Last Name");

jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("Father Name");

tfathername.setHorizontalAlignment(javax.swing.JTextField.CENTER); tfathername.setToolTipText("Enter Father Name");

jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText("Course");

59

jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel6.setText("Mobile");

tmobile.setHorizontalAlignment(javax.swing.JTextField.CENTER); tmobile.setToolTipText("10-Digits Only"); tmobile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { tmobileActionPerformed(evt); } });

jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel7.setText("Email");

temail.setHorizontalAlignment(javax.swing.JTextField.CENTER); temail.setToolTipText("Must Contain Atleast '@'");

jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel8.setText("Address");

taddress.setColumns(20); taddress.setRows(5); taddress.setToolTipText("Enter Current Address"); jScrollPane1.setViewportView(taddress);

addB.setText("ADD"); addB.setName("badd"); // NOI18N addB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addBActionPerformed(evt); } });

clearB.setText("Clear"); clearB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearBActionPerformed(evt); } });

cancelB.setText("Cancel"); cancelB.addActionListener(new java.awt.event.ActionListener() {

60

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

coursecmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Course", "BA", "BEd.", "BBA", "BCA", "BPT", "B.Sc.", "B.Com", "B.Tech.", "MA", "MBA", "MCA", "MPT", "M.Sc.", "M.Com", "M.Tech." })); coursecmb.setToolTipText("Select Course");

jLabel9.setText("Date Of Birth");

dobpan.setBorder(javax.swing.BorderFactory.createCompoundBorder());

dobddcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Date" })); dobddcmb.setToolTipText("Select Date of Birth"); dobddcmb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { dobddcmbActionPerformed(evt); } });

dobmmcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Month" })); dobmmcmb.setToolTipText("Slect Month of Birth");

dobyearcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Year" })); dobyearcmb.setToolTipText("Select Year of Birth"); dobyearcmb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { dobyearcmbActionPerformed(evt); } });

javax.swing.GroupLayout dobpanLayout = new javax.swing.GroupLayout(dobpan); dobpan.setLayout(dobpanLayout); dobpanLayout.setHorizontalGroup( dobpanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(dobpanLayout.createSequentialGroup()

61

.addComponent(dobddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(dobmmcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(dobyearcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); dobpanLayout.setVerticalGroup( dobpanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dobpanLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(dobpanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(dobddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dobmmcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(dobyearcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(37, 37, 37)) );

jLabel10.setText("Semester");

semestercmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Semester", "I", "II", "III", "IV", "V", "VI", "VII", "IIX" }));

62

semestercmb.setToolTipText("Select semester");

jLabel11.setText("Sex");

jLabel12.setText("Date Of Admission");

doapan.setBorder(javax.swing.BorderFactory.createCompoundBorder());

doaddcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Date" })); doaddcmb.setToolTipText("Select Date of Admission"); doaddcmb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { doaddcmbActionPerformed(evt); } });

doammcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Month" })); doammcmb.setToolTipText("Month of Admission");

doayearcmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Year" })); doayearcmb.setToolTipText("Year of Admission"); doayearcmb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { doayearcmbActionPerformed(evt); } });

javax.swing.GroupLayout doapanLayout = new javax.swing.GroupLayout(doapan); doapan.setLayout(doapanLayout); doapanLayout.setHorizontalGroup( doapanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(doapanLayout.createSequentialGroup() .addComponent(doaddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

63

.addComponent(doammcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(doayearcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); doapanLayout.setVerticalGroup( doapanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, doapanLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(doapanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(doaddcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(doammcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(doayearcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) );

exitB.setText("Exit"); exitB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitBActionPerformed(evt); } });

sexBG.add(femalerdb); femalerdb.setText("Female");

64

femalerdb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { femalerdbActionPerformed(evt); } });

sexBG.add(malerdb); malerdb.setSelected(true); malerdb.setText("Male"); malerdb.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { malerdbActionPerformed(evt); } });

javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGap(31, 31, 31) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel10) .addComponent(jLabel5) .addComponent(jLabel12)) .addGap(45, 45, 45) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(treg_no, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(coursecmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

65

.addComponent(semestercmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(doapan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(52, 52, 52) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jLabel3) .addGap(46, 46, 46) .addComponent(tlastname, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel9) .addComponent(jLabel4)) .addComponent(jLabel11) .addComponent(jLabel6) .addComponent(jLabel7) .addComponent(jLabel8)) .addGap(34, 34, 34) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(tfathername, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(temail, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)

66

.addComponent(tmobile, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(malerdb) .addGap(18, 18, 18) .addComponent(femalerdb)) .addComponent(dobpan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jLabel2) .addGap(45, 45, 45) .addComponent(tfirstname, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(jPanel3Layout.createSequentialGroup() .addGap(284, 284, 284) .addComponent(addB, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(33, 33, 33) .addComponent(clearB, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(36, 36, 36) .addComponent(cancelB) .addGap(53, 53, 53) .addComponent(exitB, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(204, Short.MAX_VALUE)) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup()

67

.addGap(3, 3, 3) .addComponent(jLabel2)) .addComponent(tfirstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGap(3, 3, 3) .addComponent(jLabel3)) .addComponent(tlastname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(tfathername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGap(22, 22, 22) .addComponent(jLabel9)) .addGroup(jPanel3Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(doapan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

68

.addComponent(dobpan, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(malerdb) .addComponent(femalerdb) .addComponent(jLabel11)))) .addGap(25, 25, 25) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(tmobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(temail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel8) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGap(3, 3, 3) .addComponent(jLabel1)) .addComponent(treg_no, javax.swing.GroupLayout.PREFERRED_SIZE,

69

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(coursecmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(14, 14, 14) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10) .addComponent(semestercmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jLabel12))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(addB) .addComponent(clearB) .addComponent(cancelB) .addComponent(exitB)) .addGap(57, 57, 57)) );

dobpan.getAccessibleContext().setAccessibleName("");

getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER); jPanel3.getAccessibleContext().setAccessibleName("");

jPanel4.setPreferredSize(new java.awt.Dimension(605, 25));

javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(

70

jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 1025, Short.MAX_VALUE) ); jPanel4Layout.setVerticalGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 25, Short.MAX_VALUE) );

getContentPane().add(jPanel4, java.awt.BorderLayout.PAGE_END);

pack(); }// </editor-fold>

private void jPanel1AncestorAdded(javax.swing.event.AncestorEvent evt) { // TODO add your handling code here: }

private void jPanel1AncestorMoved(javax.swing.event.AncestorEvent evt) { // TODO add your handling code here: }

private void clearBActionPerformed(java.awt.event.ActionEvent evt) { treg_no.setText(""); coursecmb.setSelectedItem("Course"); semestercmb.setSelectedItem("Semester"); doaddcmb.setSelectedItem("Date"); doammcmb.setSelectedItem("Month"); doayearcmb.setSelectedItem("Year"); tfirstname.setText(""); tlastname.setText(""); tfathername.setText(""); dobddcmb.setSelectedItem("Date"); dobmmcmb.setSelectedItem("Month"); dobyearcmb.setSelectedItem("Year"); malerdb.setSelected(true); tmobile.setText(""); temail.setText(""); taddress.setText(""); treg_no.requestFocus(); }

71

private void addBActionPerformed(java.awt.event.ActionEvent evt) { //Validating Form Data if (validateFormData()) { JOptionPane.showMessageDialog(this, "Record Added successfully"); } } private void tmobileActionPerformed(java.awt.event.ActionEvent evt) { }

private void dobddcmbActionPerformed(java.awt.event.ActionEvent evt) { }

private void femalerdbActionPerformed(java.awt.event.ActionEvent evt) { }

private void malerdbActionPerformed(java.awt.event.ActionEvent evt) { }

private void dobyearcmbActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

private void doaddcmbActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

private void doayearcmbActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: }

private void cancelBActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); }

private void exitBActionPerformed(java.awt.event.ActionEvent evt) { this.dispose(); }

/** * @param args the command line arguments */

72

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(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Registration.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold>

/* * Create and display the form

73

*/ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new Registration().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton addB; private javax.swing.JButton cancelB; private javax.swing.JButton clearB; private javax.swing.JComboBox coursecmb; private javax.swing.JComboBox doaddcmb; private javax.swing.JComboBox doammcmb; private javax.swing.JPanel doapan; private javax.swing.JComboBox doayearcmb; private javax.swing.JComboBox dobddcmb; private javax.swing.JComboBox dobmmcmb; private javax.swing.JPanel dobpan; private javax.swing.JComboBox dobyearcmb; private javax.swing.JButton exitB; private javax.swing.JRadioButton femalerdb; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JRadioButton malerdb;

74

private javax.swing.JComboBox semestercmb; private javax.swing.JTextArea taddress; private javax.swing.JTextField temail; private javax.swing.JTextField tfathername; private javax.swing.JTextField tfirstname; private javax.swing.JTextField tlastname; private javax.swing.JTextField tmobile; private javax.swing.JTextField treg_no; // End of variables declaration }Result: The program to design Enrollment form using java bean. is successfully executed.

Output:

CALENDAR USING JAVA BEAN

Aim: To write a program to display calendar using java bean.

Algorithm:

Step 1: Create new java application using Netbeans,

75

EXP. NO/DATE 18/30-01-2012

Step 2: Create Date Chooser object.

Step 3: Add JLabels, JTable, Calender using current date of the system.

Step 4: Run the program and display output.

Program:

import java.util.*;import java.text.*;public class DateChooser {public final static String[] months = {"January" , "February" , "March","April" , "May" , "June","July" , "August" , "September","October" , "November" , "December"};/** days in each month */public final static int dom[] = {31, 28, 31, /* jan, feb, mar */30, 31, 30, /* apr, may, jun */31, 31, 30, /* jul, aug, sep */31, 30, 31 /* oct, nov, dec */};

private void printMonth(int mm, int yy) {int leadSpaces = 0;System.out.println();System.out.println(" " + months[mm] + " " + yy);if (mm < 0 || mm > 11) {throw new IllegalArgumentException("Month " + mm + " bad, must be 0-11");}GregorianCalendar cal = new GregorianCalendar(yy, mm, 1);System.out.println("Su Mo Tu We Th Fr Sa"); // can change to "M T W T F S S"leadSpaces = cal.get(Calendar.DAY_OF_WEEK)-1; // adjust for "M T W T F S S" if desiredint daysInMonth = dom[mm];if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) daysInMonth++;for (int i = 0; i < leadSpaces; i++) {System.out.print(" ");}for (int i = 1; i <= daysInMonth; i++) {if (i<=9) System.out.print(" ");System.out.print(i);if ((leadSpaces + i) % 7 == 0) { // Wrap if EOLSystem.out.println();} else {System.out.print(" ");

76

}}System.out.println();}

public static void main(String[] args) {int month, year;DateChooser mv = new DateChooser();Calendar today = Calendar.getInstance();mv.printMonth( today.get( Calendar.MONTH), today.get( Calendar.YEAR));}}

Result: The program to display calendar using java bean has been successfully executed.

Output:

TABLE USING JAVA BEAN

Aim: To write a program to display Table using Java Bean.

Algorithm:

Step 1: Create new java application using Netbeans,

Step 2: Extends JFrame in the program.

Step 3: Add JLabels, JTable into the JFrame to enter information.

Step 4: Run the program and display output in the appletviewer.

77

EXP. NO/DATE 19/30-01-2012

Program:

public class TableDemo extends javax.swing.JFrame { public TableDemo() { 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() {

jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Table using Bean");

jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Reg no.", "Name", "Course", "Year of Admission" } )); jScrollPane1.setViewportView(jTable1);

jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N jLabel1.setForeground(new java.awt.Color(51, 0, 255)); jLabel1.setText("Table using Bean");

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

78

layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 450, Short.MAX_VALUE) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGap(134, 134, 134) .addComponent(jLabel1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(28, 28, 28) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) );

pack(); }// </editor-fold>

/** * @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 {

79

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(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold>

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new TableDemo().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; // End of variables declaration }Result: The program to display Table using Java Bean.is successfully executed.

Output:

80

DISPLAY DATE AND TIME USING SERVLET

Aim: To write a program to display date and time using Servlet.

Algorithm:

Step 1: Write the html code in the java file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the java code for date and time in the body section.

Step 4: Run the program and display output in the web browser.

Program:

import java.io.IOException;

import java.io.PrintWriter;

81

EXP. NO/DATE 20/13-02-2012

import javax.servlet.GenericServlet;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServlet;

public class ShowDate extends HttpServlet {

@Override

public void service(ServletRequest req, ServletResponse res) throws ServletException,

IOException {

PrintWriter out = res.getWriter();

out.println("<html>");

out.println("<head>");

out.println("<title>Date and Time using Servlet</title>");

out.println("</head>");

out.println("<body bgcolor=\"00FFCC\">");

out.println("<h2>Date and Time on Server using Servlet</h2>");

out.println("<p>"+new java.util.Date()+"</p>");

out.println("</body>");

out.println("</html>");

out.close();

}

}

Result: The program for date and time using Servlet is successfully executed.

Output:

82

SERVLET GETREQUEST() METHOD

Aim: To write a program to display date and time using Servlet.

Algorithm:

Step 1: Write the html code in the html file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the servlet code inside java program.

Step 4: Compile the servlet program/

Step 5: Start Tomcat, if it is not already running.

Step 6: Display the Web page in a browser and Select a color.

Step 7: Submit the Web page.

Program:

showFruit.jsp

<body><center> <form name="Form1" method="get"action="/SRMAdvanceJSP/ShowFruit"> <B>Fruit:</B><select name="fruit" size="1">

83

EXP. NO/DATE 21/13-02-2012

<option value="Apple">Apple</option> <option value="Banana">Banana</option> <option value="Dry Fruit">Dry Fruit</option> <option value="Guava">Guava</option> <option value="Mango">Mango</option> <option value="Orange">Orange</option> <option value="Pineapple">Pineapple</option> </select><br><br> <input type=submit value="Submit"> </form></body></html>

ShowFruit.java

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;

public class ShowFruit extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fruit = request.getParameter("fruit"); response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<B>The selected Fruit is: "); pw.println(fruit); pw.close(); }}Result: The program Servlet get request() method is successfully executed.Input:

84

Output:

85

SERVLET POSTREQUEST() METHOD

Aim: To write a program to display date and time using Servlet.

Algorithm:

Step 1: Write the html code in the html file.

Step 2: Write the title of the program inside the head section of html code.

Step 3: Write the servlet code inside java program.

Step 4: Compile the servlet program/

Step 5: Start Tomcat, if it is not already running.

Step 6: Display the Web page in a browser and Select a color.

Step 7: Submit the Web page.

Program:

showCourse.jsp

<body><center> <form name="Form1" method="post" action="/SRMAdvanceJSP/ShowCourse"> <B>Course:</B><select name="course" size="1"> <option value="BA">BA</option> <option value="BBA">BBA</option> <option value="BCA">BCA</option> <option value="B.Tech">B.Tech</option> <option value="B.Tech(Biotech)">B.Tech(Biotech)</option> <option value="B.Sc.">B.Sc.</option> <option value="MA">MA</option> <option value="MBA">MBA</option> <option value="MCA">MCA</option> <option value="M.Tech">M.Tech</option> <option value="M.Tech(Bioech)">M.Tech(Biotech)</option> <option value="M.Sc.">B.Sc.</option> </select><br><br> <input type=submit value="Submit"> </form></body></html>

ShowCourse.java

//doPost method

import java.io.*;

86

EXP. NO/DATE 22/14-02-2012

import javax.servlet.*;

import javax.servlet.http.*;

public class ShowCourse extends HttpServlet {

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

String fruit = request.getParameter("course");

response.setContentType("text/html");

PrintWriter pw = response.getWriter();

pw.println("<B>The selected Course is: ");

pw.println(fruit);

pw.close();

}

}

Result: The program for date and time using Servlet is successfully executed.

Input:

87

Output:

INSERT STUDENT DATA USING JDBC

Aim: To write a program to insert a student record using JDBC.

Algorithm:

Step 1: Create DSN for the database and load the JDBC Driver using Class.forName().

Step 2: Create Connection using DriverManager.getConnection().

Step 3: Create Statement using Connection name.createStatement().

Step 4: Create Insert query and write execute statement using executeUpdate().

Step 5: Run the program and enter Student information to store into the database.

Program:

import java.sql.*;

/** * @author Yadu */

88

EXP. NO/DATE 23/14-02-2012

public class DataInsertion {

public static void main(String[] args) {

Connection con = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:srm", "swt", "swt"); Statement stmt = con.createStatement(); int n = stmt.executeUpdate("INSERT INTO stu VALUES('3521130001','ashish','MCA','2011')"); if (n > 0) { System.out.println("Record inserted successfully!"); } else { System.out.println("Unable to Insert!"); } con.close();

} catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (Exception e) { e.printStackTrace(); } } } }}Result: The program to insert student information from the database has been

successfully executed.

Output:

Record inserted successfully!

89

RETRIEVE STUDENT DATA USING JDBC

Aim: To write a program to retrieve a student record using JDBC.

Algorithm:

Step 1: Create DSN for the database.

Step 2: Load the JDBC Driver using Class.forName().

Step 3: Create Connection using DriverManager.getConnection().

Step 4: Create Statement using Connection name.createStatement().

Step 5: Create ResultSet and also create retrieve query and write execute statement using

executeQuery().

Step 6: Run the program and enter Student Registration number to retrieve his

information.

Program:

import java.sql.*;

/**

* @author Nitesh

*/

public class DataRetrieval {

public static void main(String[] args) {

Connection con = null;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con = DriverManager.getConnection("jdbc:odbc:srm", "swt", "swt");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM stu");

System.out.println("Reg no. Name Course Year of Admission");

while (rs.next()) {

90

EXP. NO/DATE 24/15-02-2012

System.out.format("%-15s%-20s%-10s%-10s\n", rs.getString(1),

rs.getString(2), rs.getString(3), rs.getString(4));

}

con.close();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (con != null) {

try {

con.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

}

Result: The program to delete student information from the database has been

successfully executed.

Output:

Reg no. Name Course Year of

Admission

3521130004 ashish pandey MCA 2011

3521130008 ankur MCA 2011

3521130011 shubham MCA 2011

3521130023 nitesh MCA 2011

3521130024 prabhat MCA 2011

3521130026 pandey MCA 2011

3521130050 nitin MCA 2011

3521130002 ashish MCA 2011

91

DELETE STUDENT DATA USING JDBC

Aim: To write a program to delete a student record using JDBC.

Algorithm:

Step 1: Create DSN for the database.

Step 2: Load the JDBC Driver using Class.forName().

Step 3: Create Connection using DriverManager.getConnection().

Step 4: Create Statement using Connection name.createStatement().

Step 5: Create Delete query and write execute statement using executeUpdate().

Step 6: Run the program and enter Student Registration number to delete.

Program:

import java.sql.*;

/**

* @author Nitesh

*/

public class DataDeletion {

public static void main(String[] args) {

Connection con = null;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con = DriverManager.getConnection("jdbc:odbc:srm", "swt", "swt");

Statement stmt = con.createStatement();

int n = stmt.executeUpdate("DELETE FROM stu WHERE

regno='3521130001'");

if (n > 0) {

System.out.println(n + " rows DELETED!");

} else {

92

EXP. NO/DATE 25/21-02-2012

System.out.println("Unable to delete");

}

con.close();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (con != null) {

try {

con.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

}

Result: The program to delete student information from the database has been

successfully executed.

Output:

1 rows DELETED!

93